From: David Wei <dw@davidwei.uk>
To: Jens Axboe <axboe@kernel.dk>,
hengyul@cs.unc.edu, Pavel Begunkov <asml.silence@gmail.com>,
io-uring@vger.kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] io_uring: do not charge the SQ/CQ rings to RLIMIT_MEMLOCK
Date: Wed, 7 Oct 2026 21:17:45 +0100 [thread overview]
Message-ID: <33f685a9-1140-4b4d-a40d-8250ab93e500@davidwei.uk> (raw)
In-Reply-To: <01d75013-9eae-4ec6-93b5-cc1b2b83b791@kernel.dk>
On 2026-10-06 16:59, Jens Axboe wrote:
> On 10/6/26 6:57 AM, hengyul@cs.unc.edu wrote:
>> From: Hengyu Liang <hengyul@cs.unc.edu>
>>
>> Commit 8078486e1d53 ("io_uring: use region api for SQ") and commit
>> 81a4058e0cd0 ("io_uring: use region api for CQ") made io_uring_setup()
>> allocate the rings with io_create_region().
>>
>> However, io_create_region() charges the memory to RLIMIT_MEMLOCK, and
>> the rings had been exempt from that limit since commit 26bfa89e25f4
>> ("io_uring: place ring SQ/CQ arrays under memcg memory limits"). As of
>> now, a user without CAP_IPC_LOCK gets ENOMEM from io_uring_setup() when
>> their rings exceed the limit, which is 8 MiB by default. PostgreSQL
>> developers have already hit this in their io_uring tests [1].
>>
>> The issue can be reproduced with a simple liburing program, run as an
>> unprivileged user:
>>
>> #include <liburing.h>
>> #include <stdio.h>
>>
>> int main(void)
>> {
>> static struct io_uring ring[64];
>> int i;
>>
>> for (i = 0; i < 64; i++)
>> if (io_uring_queue_init(4096, &ring[i], 0) < 0)
>> break;
>> printf("%d rings\n", i);
>> return 0;
>> }
>>
>> Before those commits (v6.13), it prints "64 rings". After those commits
>> (v6.14), it prints "21 rings".
>>
>> This patch makes io_create_region() take the user to charge, and passes
>> no user for the SQ/CQ rings.
>
> Agree that this is a bug, stricter accounting may break use cases.
> However, I think we can solve this simpler, and actually kill more code.
> How about something like the below instead? Only apply accounting to
> user backed memory, which is how it used to work too. Would be great if
> you could take a look and also run your test case against it.
Tested in a VM and confirmed that with the patch below the reproducer
correctly allocates all 64 w/ a 8 MB RLIMIT_MEMLOCK.
This change is really helpful for me as well, thank you for addressing
this Hengyu.
next prev parent reply other threads:[~2026-10-07 20:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 12:57 [PATCH] io_uring: do not charge the SQ/CQ rings to RLIMIT_MEMLOCK hengyul
2026-10-06 14:59 ` Jens Axboe
2026-10-07 20:17 ` David Wei [this message]
2026-10-07 21:33 ` 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=33f685a9-1140-4b4d-a40d-8250ab93e500@davidwei.uk \
--to=dw@davidwei.uk \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=hengyul@cs.unc.edu \
--cc=io-uring@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--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