From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379690; b=CCq+IV8fFOsVvSozh4ncMoB3vsuRFDMpDLm/xXUPzEDKG8psdsywgfD+6fo/xse4UupO 4q1/dfCbAv0bCnY3e8w9hgw0ypfWieOF8JeGjCnFP3l8g3ObXTz8Y/ba21XkLDVSqc3TU JhSS7csrpNuWIkcJIdJO2IZbosOoq9g1z9CVAoezUBgM6IOP3LcJ0ka+SPtaJmTir6WVj J9FUYtEYtw70cZFmfBZEcXsQshp9yhAODVMukJZM7Jv9wlDNuKYbiQtQ/r0t5haB08LBN gP61lHUd4gww1hFFG4bTyLT4UyYls8rzL0IOH8brvlHRdynDeqriQqMf+8Q/wtshpUA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379690; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=wiFzYZWGugXLzsFy+q1Tpjk4cScW+56bgl0BlCbJQN0=; b=gWOhqlD/7Or8U8stXP7b67vFYbeICmuEWNBHt9QJcKnkhGh9J9hwRMAZJJzNfEyEzSJb mAIHgTRSZR99WPanUTUz2YNyfpHaB6XuBtbrfqE73pEk7W0Z62cHdhYL7iv83uKcqMZ+g bg0mR9yOH4aaM8u89s3R0Wc9OidXhi/osXQgDkIsollakzvbjvzXSWh+FWIIbw47rRgoa T+p+9Bz9cVroUtHbm/ztsOt3bt0G8slFrZgbmjM5zEp6s56ezATeXOhL8UHmnIBvWtPhE 6MgEhjdp3twP1r/WfnTEblnDC1wIJQwtmuSPceW6+8FTosiF0rJssQAXXDBGmZNNoCg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=L6tWtUTs; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F54E606A322; Fri, 4 Dec 2026 10:21:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=L6tWtUTs Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA38C1F000C2; Fri, 4 Dec 2026 10:21:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379690; bh=wiFzYZWGugXLzsFy+q1Tpjk4cScW+56bgl0BlCbJQN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=L6tWtUTsEm3nbdV5LVAoS8E0IPQvsF7MJg/0Bo5YbErMrnz5pXDASP9TJJvIbJebc OAKnDLax/GgfkhFh52elZ/ZziYU110adzp/1/GnJxXhf4IJr68BBaJSw66/puVoEg4 R0QoYFlKn+UBXCUeNKAfvFesOmR3rhCOkn8+dDHU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shakeel Butt , Jens Axboe , Sasha Levin Subject: [PATCH 6.6 0034/1167] io_uring/sqpoll: do the return-to-userspace work in the SQPOLL thread Date: Fri, 4 Dec 2026 18:51:01 +0900 Message-ID: <20261204100702.933551245@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shakeel Butt Commit f013b695506491c5202a412a6568313549c81f50 upstream. 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 commit b5d3ae202fbf ("io_uring: handle TIF_NOTIFY_RESUME when checking for task_work"). Commit af5d68f8892f ("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: af5d68f8892f ("io_uring/sqpoll: manage task_work privately") Cc: stable@vger.kernel.org Signed-off-by: Shakeel Butt Link: https://patch.msgid.link/20261101022146.309201-1-shakeel.butt@linux.dev Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- io_uring/sqpoll.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c index 3d0fbae80938a..263da37d45ee0 100644 --- a/io_uring/sqpoll.c +++ b/io_uring/sqpoll.c @@ -318,6 +318,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 = __io_sq_thread(ctx, cap_entries); -- 2.53.0