mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
io_uring/sqpoll: do the return-to-userspace work in the SQPOLL thread
The SQPOLL thread never returns to userspace. io_sq_tw() runs its task_work, but the rest of resume_user_mode_work(), like memory.high reclaim and block cgroup throttling, only runs when the thread exits. So memory.high reclaim only happens inside a charge, with sqd->lock and ctx->uring_lock held, and not at all if the charges can't block. This used to work. The loop called io_run_task_work(), which does this work since commitb5d3ae202f("io_uring: handle TIF_NOTIFY_RESUME when checking for task_work"). Commitaf5d68f889("io_uring/sqpoll: manage task_work privately") replaced that call with io_sq_tw(). Call resume_user_mode_work() at the top of the loop when TIF_NOTIFY_RESUME is set, with sqd->lock dropped. It runs once per pass, so a pass that charges two or more batches still reclaims inside the charge, as before. Tested in a VM with memory.high=64M and swap on zram. An SQPOLL ring reads 256M from /dev/zero into untouched memory, 64K at a time. Before, the thread made 337 calls to __mem_cgroup_handle_over_high(), all from inside the charge. After, it makes 704, all from the top of the loop. memory.peak stays at 64M. With 1M reads, 296 of its 385 calls still come from inside the charge. Both runs take about 50% longer, and the extra time is in the handler, which now runs more often. Without memory.high pressure, the test never calls resume_user_mode_work() and the times do not change. Lockdep showed no warnings, also with io_uring_register() racing for sqd->lock. Fixes:af5d68f889("io_uring/sqpoll: manage task_work privately") Cc: [email protected] Signed-off-by: Shakeel Butt <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jens Axboe <[email protected]>
This commit is contained in:
@@ -349,6 +349,18 @@ static int io_sq_thread(void *data)
|
||||
timeout = jiffies + sqd->sq_thread_idle;
|
||||
}
|
||||
|
||||
/*
|
||||
* The SQPOLL thread never returns to userspace, so do the
|
||||
* return-to-userspace work, like memory.high reclaim, here.
|
||||
* It can sleep for a long time, so drop sqd->lock.
|
||||
*/
|
||||
if (test_thread_flag(TIF_NOTIFY_RESUME)) {
|
||||
mutex_unlock(&sqd->lock);
|
||||
resume_user_mode_work(NULL);
|
||||
mutex_lock(&sqd->lock);
|
||||
sqd->sq_cpu = raw_smp_processor_id();
|
||||
}
|
||||
|
||||
cap_entries = !list_is_singular(&sqd->ctx_list);
|
||||
list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
|
||||
int ret;
|
||||
|
||||
Reference in New Issue
Block a user