From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: dw@davidwei.uk, hengyul@cs.unc.edu, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 1/2] Revert "io_uring/memmap: account the pages a compound region really uses"
Date: Wed, 7 Oct 2026 15:38:56 -0600 [thread overview]
Message-ID: <20261007213903.445430-2-axboe@kernel.dk> (raw)
In-Reply-To: <20261007213903.445430-1-axboe@kernel.dk>
This reverts commit f12f0234cc14886bcfd53ffb7c8df4216dad51f1.
The next patch stops charging kernel allocated regions to RLIMIT_MEMLOCK
altogether, which leaves nothing for this to account. Revert it first so
that fix applies cleanly to the stable trees that need it, none of which
have this commit.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/memmap.c | 37 +++++++------------------------------
1 file changed, 7 insertions(+), 30 deletions(-)
diff --git a/io_uring/memmap.c b/io_uring/memmap.c
index 48c0eb012412..23e8a85111bc 100644
--- a/io_uring/memmap.c
+++ b/io_uring/memmap.c
@@ -16,10 +16,8 @@
#include "zcrx.h"
static bool io_mem_alloc_compound(struct page **pages, int nr_pages,
- size_t size, gfp_t gfp,
- struct user_struct *user)
+ size_t size, gfp_t gfp)
{
- unsigned long nr_compound, extra;
struct page *page;
int i, order;
@@ -29,22 +27,9 @@ static bool io_mem_alloc_compound(struct page **pages, int nr_pages,
else if (order)
gfp |= __GFP_COMP;
- /*
- * get_order() rounds a non power of two size up, so the allocation
- * can hold more pages than the region exposes. Account those too,
- * and leave the compound allocation alone if they do not fit.
- */
- nr_compound = 1UL << order;
- extra = nr_compound - nr_pages;
- if (extra && user && __io_account_mem(user, extra))
- return false;
-
page = alloc_pages(gfp, order);
- if (!page) {
- if (extra && user)
- __io_unaccount_mem(user, extra);
+ if (!page)
return false;
- }
for (i = 0; i < nr_pages; i++)
pages[i] = page + i;
@@ -120,15 +105,8 @@ void io_free_region(struct user_struct *user, struct io_mapped_region *mr)
}
if ((mr->flags & IO_REGION_F_VMAP) && mr->ptr)
vunmap(mr->ptr);
- if (mr->nr_pages && user) {
- unsigned long nr_accounted = mr->nr_pages;
-
- /* a compound region was accounted for the whole allocation */
- if (mr->flags & IO_REGION_F_SINGLE_REF)
- nr_accounted = 1UL << get_order(io_region_size(mr));
-
- __io_unaccount_mem(user, nr_accounted);
- }
+ if (mr->nr_pages && user)
+ __io_unaccount_mem(user, mr->nr_pages);
memset(mr, 0, sizeof(*mr));
}
@@ -173,8 +151,7 @@ static int io_region_pin_pages(struct io_mapped_region *mr,
static int io_region_allocate_pages(struct io_mapped_region *mr,
struct io_uring_region_desc *reg,
- unsigned long mmap_offset,
- struct user_struct *user)
+ unsigned long mmap_offset)
{
gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_NOWARN;
size_t size = io_region_size(mr);
@@ -185,7 +162,7 @@ static int io_region_allocate_pages(struct io_mapped_region *mr,
if (!pages)
return -ENOMEM;
- if (io_mem_alloc_compound(pages, mr->nr_pages, size, gfp, user)) {
+ if (io_mem_alloc_compound(pages, mr->nr_pages, size, gfp)) {
mr->flags |= IO_REGION_F_SINGLE_REF;
goto done;
}
@@ -240,7 +217,7 @@ int io_create_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr,
if (reg->flags & IORING_MEM_REGION_TYPE_USER)
ret = io_region_pin_pages(mr, reg);
else
- ret = io_region_allocate_pages(mr, reg, mmap_offset, ctx->user);
+ ret = io_region_allocate_pages(mr, reg, mmap_offset);
if (ret)
goto out_free;
--
2.55.0
next prev parent reply other threads:[~2026-10-07 21:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 21:38 [PATCHSET 0/2] Fix memlock account for kernel backed memory Jens Axboe
2026-10-07 21:38 ` Jens Axboe [this message]
2026-10-07 21:38 ` [PATCH 2/2] io_uring/memmap: only charge pinned user memory to RLIMIT_MEMLOCK Jens Axboe
2026-10-08 4:57 ` Hengyu Liang
2026-10-08 14:54 ` Jens Axboe
2026-10-08 17:06 ` [PATCH] io_uring: do not charge user provided SQ/CQ rings " Hengyu Liang
2026-10-08 19:11 ` 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=20261007213903.445430-2-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=dw@davidwei.uk \
--cc=hengyul@cs.unc.edu \
--cc=io-uring@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.