From: Jens Axboe <axboe@kernel.dk>
To: stable@vger.kernel.org
Subject: [PATCH 6.18.y 05/11] io_uring/rsrc: charge buffer arrays and nodes to memcg
Date: Wed, 4 Nov 2026 11:44:06 -0700 [thread overview]
Message-ID: <20261104184412.516558-6-axboe@kernel.dk> (raw)
In-Reply-To: <20261104184412.516558-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.18 uses kvmalloc() + struct_size_t() rather than
kvmalloc_flex()]
---
io_uring/rsrc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 8d28c6bfebb1..41e5755bd9aa 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -110,9 +110,9 @@ static struct io_mapped_ubuf *io_alloc_imu(struct io_ring_ctx *ctx,
int nr_bvecs)
{
if (nr_bvecs <= IO_CACHED_BVECS_SEGS)
- return io_cache_alloc(&ctx->imu_cache, GFP_KERNEL);
+ return io_cache_alloc(&ctx->imu_cache, GFP_KERNEL_ACCOUNT);
return kvmalloc(struct_size_t(struct io_mapped_ubuf, bvec, nr_bvecs),
- GFP_KERNEL);
+ GFP_KERNEL_ACCOUNT);
}
static void io_free_imu(struct io_ring_ctx *ctx, struct io_mapped_ubuf *imu)
@@ -140,7 +140,7 @@ struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx, int type)
{
struct io_rsrc_node *node;
- node = io_cache_alloc(&ctx->node_cache, GFP_KERNEL);
+ node = io_cache_alloc(&ctx->node_cache, GFP_KERNEL_ACCOUNT);
if (node) {
node->type = type;
node->refs = 1;
--
2.56.0
next prev parent reply other threads:[~2026-11-04 18:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 18:44 [PATCH 6.18.y 00/11] io_uring fixes for 6.18-stable Jens Axboe
2026-11-04 18:44 ` [PATCH 6.18.y 01/11] io_uring/kbuf: advance head when a pickup empties the buffer ring Jens Axboe
2026-11-04 18:44 ` [PATCH 6.18.y 02/11] io_uring/net: keep recvmsg buffer select length within MAX_RW_COUNT Jens Axboe
2026-11-04 18:44 ` [PATCH 6.18.y 03/11] io_uring/net: don't retry a non-blocking connect() that fails with -EAGAIN Jens Axboe
2026-11-04 18:44 ` [PATCH 6.18.y 04/11] io_uring/io-wq: no new workers once the exit has begun Jens Axboe
2026-11-04 18:44 ` Jens Axboe [this message]
2026-11-04 18:44 ` [PATCH 6.18.y 06/11] io_uring: charge tctx nodes and personalities Jens Axboe
2026-11-04 18:44 ` [PATCH 6.18.y 07/11] io_uring: free XArray nodes left by a failed store Jens Axboe
2026-11-04 18:44 ` [PATCH 6.18.y 08/11] io_uring/sqpoll: don't wait for the thread to exit Jens Axboe
2026-11-04 18:44 ` [PATCH 6.18.y 09/11] io_uring: defer foreign io-wq enqueues to task_work Jens Axboe
2026-11-04 18:44 ` [PATCH 6.18.y 10/11] io_uring/timeout: count cancelled timeouts in cq_timeouts Jens Axboe
2026-11-04 18:44 ` [PATCH 6.18.y 11/11] io_uring/net: fix multishot recv length limit accounting 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=20261104184412.516558-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;
as well as URLs for NNTP newsgroup(s).