mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hang Zhengyang <hang.zhengyang1010@gmail.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Tao Cui <cui.tao@linux.dev>,
	io-uring@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] io_uring: charge request async data to memcg
Date: Sun,  6 Dec 2026 10:04:48 +0000	[thread overview]
Message-ID: <20261206100449.2060856-2-hang.zhengyang1010@gmail.com> (raw)
In-Reply-To: <20261206100449.2060856-1-hang.zhengyang1010@gmail.com>

The io_kiocb of a request is charged to memcg, but its async data is
usually allocated with plain GFP_KERNEL. A request that waits, such as a
read on an empty pipe, holds its async data until it completes. 50000
such reads took 29MiB of unreclaimable slab, of which 13MiB was charged.

Use GFP_KERNEL_ACCOUNT, as commit 6e0d71c288fd ("io_uring/futex: use
GFP_KERNEL_ACCOUNT for futex data allocation") did for futexv. Both
async data allocations could already sleep, so at memory.max the charge
reclaims like any other.

Found, fixed and tested by Claude Code, I handled the review process.

Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com>
---
 io_uring/io_uring.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index ef30ddf4cbf7..d5a9534a4bb0 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -343,7 +343,7 @@ static inline bool
 io_uring_alloc_cached_async_data(struct io_alloc_cache *cache,
 				 struct io_kiocb *req)
 {
-	if (!io_cache_alloc(cache, GFP_KERNEL, &req->async_data))
+	if (!io_cache_alloc(cache, GFP_KERNEL_ACCOUNT, &req->async_data))
 		return false;
 
 	io_req_set_flags(req, REQ_F_ASYNC_DATA);
@@ -355,7 +355,7 @@ static inline void *io_uring_alloc_async_data(struct io_kiocb *req)
 	const struct io_issue_def *def = &io_issue_defs[req->opcode];
 
 	WARN_ON_ONCE(!def->async_size);
-	req->async_data = kmalloc(def->async_size, GFP_KERNEL);
+	req->async_data = kmalloc(def->async_size, GFP_KERNEL_ACCOUNT);
 	if (req->async_data)
 		io_req_set_flags(req, REQ_F_ASYNC_DATA);
 	return req->async_data;
-- 
2.53.0


  reply	other threads:[~2026-12-06 10:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06 10:04 [PATCH 0/2] io_uring: charge request async data and iovec arrays " Hang Zhengyang
2026-12-06 10:04 ` Hang Zhengyang [this message]
2026-12-06 10:04 ` [PATCH 2/2] io_uring: charge imported " Hang Zhengyang

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=20261206100449.2060856-2-hang.zhengyang1010@gmail.com \
    --to=hang.zhengyang1010@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=cui.tao@linux.dev \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®