Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: stable@vger.kernel.org
Subject: [PATCH 6.12.y 5/9] io_uring/rsrc: charge buffer arrays and nodes to memcg
Date: Wed,  4 Nov 2026 11:43:49 -0700	[thread overview]
Message-ID: <20261104184353.516403-6-axboe@kernel.dk> (raw)
In-Reply-To: <20261104184353.516403-1-axboe@kernel.dk>

From: Chris Mason <mason@kernel.org>

Commit 075d5837bafc317e796548f721b8fbf7add6821d upstream.

The io_mapped_ubuf of a registered buffer has one bio_vec per page,
unless the pages coalesce into huge pages. Huge pages only count against
RLIMIT_MEMLOCK once per ring, so a buffer that maps the same 2MB folio
over and over in a way that defeats coalescing gets a full bvec array
per registration while only the one folio counts as locked. 1GB of that
registered in 100 slots took several times a 64MB memory.max, with 2.6MB
charged.

Allocate the io_mapped_ubuf and the io_rsrc_node with
GFP_KERNEL_ACCOUNT. An object reused from the ring caches stays charged
to whoever allocated it first, same as the io_kiocb cache.

Fixes: de2939388be5 ("io_uring: improve registered buffer accounting for huge pages")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.12 predates the rsrc node rework, charge the imu kvmalloc()
and the node kzalloc() instead]
---
 io_uring/rsrc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 1687e35e21c9..ad7ad35545d6 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -183,7 +183,7 @@ struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx)
 
 	ref_node = io_alloc_cache_get(&ctx->rsrc_node_cache);
 	if (!ref_node) {
-		ref_node = kzalloc(sizeof(*ref_node), GFP_KERNEL);
+		ref_node = kzalloc(sizeof(*ref_node), GFP_KERNEL_ACCOUNT);
 		if (!ref_node)
 			return NULL;
 	}
@@ -982,7 +982,7 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
 	/* If it's huge page(s), try to coalesce them into fewer bvec entries */
 	coalesced = io_try_coalesce_buffer(&pages, &nr_pages, &data);
 
-	imu = kvmalloc(struct_size(imu, bvec, nr_pages), GFP_KERNEL);
+	imu = kvmalloc(struct_size(imu, bvec, nr_pages), GFP_KERNEL_ACCOUNT);
 	if (!imu)
 		goto done;
 
-- 
2.56.0


  parent reply	other threads:[~2026-11-04 18:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 18:43 [PATCH 6.12.y 0/9] io_uring fixes for 6.12-stable Jens Axboe
2026-11-04 18:43 ` [PATCH 6.12.y 1/9] io_uring/kbuf: advance head when a pickup empties the buffer ring Jens Axboe
2026-11-04 18:43 ` [PATCH 6.12.y 2/9] io_uring/net: keep recvmsg buffer select length within MAX_RW_COUNT Jens Axboe
2026-11-04 18:43 ` [PATCH 6.12.y 3/9] io_uring/net: don't retry a non-blocking connect() that fails with -EAGAIN Jens Axboe
2026-11-04 18:43 ` [PATCH 6.12.y 4/9] io_uring/io-wq: no new workers once the exit has begun Jens Axboe
2026-11-04 18:43 ` Jens Axboe [this message]
2026-11-04 18:43 ` [PATCH 6.12.y 6/9] io_uring: charge tctx nodes and personalities Jens Axboe
2026-11-04 18:43 ` [PATCH 6.12.y 7/9] io_uring: free XArray nodes left by a failed store Jens Axboe
2026-11-04 18:43 ` [PATCH 6.12.y 8/9] io_uring/sqpoll: don't wait for the thread to exit Jens Axboe
2026-11-04 18:43 ` [PATCH 6.12.y 9/9] io_uring/timeout: count cancelled timeouts in cq_timeouts Jens Axboe

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=20261104184353.516403-6-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=stable@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