public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] loop: inherit the ioprio in loop woker thread
@ 2024-05-22  7:48 Yunlong Xing
  2024-05-22 17:38 ` Bart Van Assche
  0 siblings, 1 reply; 11+ messages in thread
From: Yunlong Xing @ 2024-05-22  7:48 UTC (permalink / raw)
  To: axboe, yunlongxing23, niuzhiguo84, Hao_hao.Wang; +Cc: linux-block, linux-kernel

The loop worker thread only inherit the blkcg of original request,
but does not inherit it's ioprio. So, when a task with the high
ioprio but in root blkcg accesses the loop device, the worker
thread handle this cmd with a normal ioprio. This results in the
request of high ioprio task doesn't be prioritized.

Signed-off-by: Yunlong Xing <yunlong.xing@unisoc.com>
---
 drivers/block/loop.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 28a95fd366fe..404ac113c71b 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -442,7 +442,6 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 	cmd->iocb.ki_filp = file;
 	cmd->iocb.ki_complete = lo_rw_aio_complete;
 	cmd->iocb.ki_flags = IOCB_DIRECT;
-	cmd->iocb.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
 
 	if (rw == ITER_SOURCE)
 		ret = call_write_iter(file, &cmd->iocb, &iter);
@@ -1856,6 +1855,9 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
 		break;
 	}
 
+	/* get request's ioprio */
+	cmd->iocb.ki_ioprio = rq->ioprio;
+
 	/* always use the first bio's css */
 	cmd->blkcg_css = NULL;
 	cmd->memcg_css = NULL;
@@ -1886,12 +1888,18 @@ static void loop_handle_cmd(struct loop_cmd *cmd)
 	int ret = 0;
 	struct mem_cgroup *old_memcg = NULL;
 	const bool use_aio = cmd->use_aio;
+	int ori_ioprio = 0;
+	int cmd_ioprio = cmd->iocb.ki_ioprio;
 
 	if (write && (lo->lo_flags & LO_FLAGS_READ_ONLY)) {
 		ret = -EIO;
 		goto failed;
 	}
 
+	ori_ioprio = get_current_ioprio();
+	if (ori_ioprio != cmd_ioprio)
+		set_task_ioprio(current, cmd_ioprio);
+
 	if (cmd_blkcg_css)
 		kthread_associate_blkcg(cmd_blkcg_css);
 	if (cmd_memcg_css)
@@ -1913,6 +1921,10 @@ static void loop_handle_cmd(struct loop_cmd *cmd)
 		set_active_memcg(old_memcg);
 		css_put(cmd_memcg_css);
 	}
+
+	if (ori_ioprio != cmd_ioprio)
+		set_task_ioprio(current, ori_ioprio);
+
  failed:
 	/* complete non-aio request */
 	if (!use_aio || ret) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-05-24  5:26 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-22  7:48 [PATCH] loop: inherit the ioprio in loop woker thread Yunlong Xing
2024-05-22 17:38 ` Bart Van Assche
2024-05-22 17:57   ` Jens Axboe
2024-05-22 18:12     ` Bart Van Assche
2024-05-22 18:13       ` Jens Axboe
2024-05-23  2:15         ` yunlong xing
2024-05-23  6:04       ` yunlong xing
2024-05-23 13:04         ` Jens Axboe
2024-05-23 14:52           ` yunlong xing
2024-05-23 14:58             ` Jens Axboe
2024-05-24  5:26               ` yunlong xing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox