From: "zhaoyang.huang" <zhaoyang.huang@unisoc.com>
To: Jens Axboe <axboe@kernel.dk>, Ming Lei <ming.lei@redhat.com>,
<linux-mm@kvack.org>, <linux-block@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
Zhaoyang Huang <huangzhaoyang@gmail.com>, <steve.kang@unisoc.com>
Subject: [RFC PATCH] driver: loop: introduce synchronized read for loop driver
Date: Mon, 22 Sep 2025 11:29:15 +0800 [thread overview]
Message-ID: <20250922032915.3924368-1-zhaoyang.huang@unisoc.com> (raw)
From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
For now, my android system with per pid memcgv2 setup are suffering
high block_rq_issue to block_rq_complete latency which is actually
introduced by schedule latency of too many kworker threads. By further
investigation, we found that the EAS scheduler which will pack small
load tasks into one CPU core will make this scenario worse. This commit
would like to introduce a way of synchronized read to be helpful on
this scenario. The I2C of loop device's request reduced from 14ms to
2.1ms under fio test.
Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
drivers/block/Kconfig | 10 ++++++++++
drivers/block/loop.c | 22 +++++++++++++++++++++-
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index df38fb364904..a30d6c5f466e 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -383,4 +383,14 @@ config BLK_DEV_ZONED_LOOP
If unsure, say N.
+config LOOP_SYNC_READ
+ bool "enable synchronized read for loop device"
+ default n
+ help
+ provide a way of synchronized read for loop device which could be
+ helpful when you are concerned with the schedule latency affection
+ over the requests of loop device especially when plenty of blkcgs
+ setup within the system. The loop device should be configured as
+ LO_FLAGS_DIRECT_IO when applying this config.
+
endif # BLK_DEV
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 053a086d547e..1e18abe48d2b 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1884,7 +1884,27 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
#endif
}
#endif
- loop_queue_work(lo, cmd);
+#ifdef CONFIG_LOOP_SYNC_READ
+ if (req_op(rq) == REQ_OP_READ && cmd->use_aio && current->plug) {
+ struct blk_plug *plug = current->plug;
+
+ current->plug = NULL;
+ /* iterate through the plug->mq_list and launch the requests to real device */
+ while (rq) {
+ loff_t pos;
+
+ cmd = blk_mq_rq_to_pdu(rq);
+ pos = ((loff_t) blk_rq_pos(rq) << 9) + lo->lo_offset;
+ lo_rw_aio(lo, cmd, pos, ITER_DEST);
+ rq = rq_list_pop(&plug->mq_list);
+ }
+ plug->rq_count = 0;
+ current->plug = plug;
+ } else
+ loop_queue_work(lo, cmd);
+#else
+ loop_queue_work(lo, cmd);
+#endif
return BLK_STS_OK;
}
--
2.25.1
next reply other threads:[~2025-09-22 3:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-22 3:29 zhaoyang.huang [this message]
2025-09-22 18:09 ` Christoph Hellwig
2025-09-23 3:50 ` Zhaoyang Huang
2025-09-23 16:30 ` Bart Van Assche
2025-09-24 9:13 ` Zhaoyang Huang
2025-09-24 10:04 ` Ming Lei
2025-09-25 1:14 ` Zhaoyang Huang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250922032915.3924368-1-zhaoyang.huang@unisoc.com \
--to=zhaoyang.huang@unisoc.com \
--cc=axboe@kernel.dk \
--cc=huangzhaoyang@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ming.lei@redhat.com \
--cc=steve.kang@unisoc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox