public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Joanne Koong <joannelkoong@gmail.com>
Cc: axboe@kernel.dk, io-uring@vger.kernel.org,
	csander@purestorage.com, krisman@suse.de, bernd@bsbernd.com,
	hch@infradead.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v1 03/11] io_uring/kbuf: add support for kernel-managed buffer rings
Date: Fri, 13 Feb 2026 15:26:50 +0000	[thread overview]
Message-ID: <43f34edf-6a34-4afb-b0a3-0d81ec037a96@gmail.com> (raw)
In-Reply-To: <CAJnrk1YXmxqUnT561-J7seaicxFRJTyJ=F3_MX1rmtAROC6Ybg@mail.gmail.com>

On 2/11/26 22:06, Joanne Koong wrote:
> On Wed, Feb 11, 2026 at 4:01 AM Pavel Begunkov <asml.silence@gmail.com> wrote:
>> On 2/10/26 19:39, Joanne Koong wrote:
>>> On Tue, Feb 10, 2026 at 8:34 AM Pavel Begunkov <asml.silence@gmail.com> wrote:
...
>>> checking) and different allocation calls (eg
>>> io_region_allocate_pages() vs io_region_allocate_pages_multi_buf()).
>>
>> I saw that and saying that all memmap.c changes can get dropped.
>> You're using it as one big virtually contig kernel memory range then
>> chunked into buffers, and that's pretty much what you're getting with
>> normal io_create_region(). I get that you only need it to be
>> contiguous within a single buffer, but that's not what you're doing,
>> and it'll be only worse than default io_create_region() e.g.
>> effectively disabling any usefulness of io_mem_alloc_compound(),
>> and ultimately you don't need to care.
> 
> When I originally implemented it, I had it use
> io_region_allocate_pages() but this fails because it's allocating way
> too much memory at once. For fuse's use case, each buffer is usually
> at least 1 MB if not more. Allocating the memory one buffer a time in
> io_region_allocate_pages_multi_buf() bypasses the allocation errors I
> was seeing. That's the main reason I don't think this can just use
> io_create_region().

Let's fix that then. For now, just work it around by wrapping
into a loop.

Btw, I thought you're going to use it for metadata like some
fuse headers and payloads would be zero copied by installing
it as registered buffers.

...
>>>> Provided buffer rings with kernel addresses could be an interesting
>>>> abstraction, but why is it also responsible for allocating buffers?
>>>
>>> Conceptually, I think it makes the interface and lifecycle management
>>> simpler/cleaner. With registering it from userspace, imo there's
>>> additional complications with no tangible benefits, eg it's not
>>> guaranteed that the memory regions registered for the buffers are the
>>> same size, with allocating it from the kernel-side we can guarantee
>>> that the pages are allocated physically contiguously, userspace setup
>>> with user-allocated buffers is less straightforward, etc. In general,
>>> I'm just not really seeing what advantages there are in allocating the
>>> buffers from userspace. Could you elaborate on that part more?
>>
>> I don't think I follow. I'm saying that it might be interesting
>> to separate rings from how and with what they're populated on the
>> kernel API level, but the fuse kernel module can do the population
> 
> Oh okay, from your first message I (and I think christoph too) thought
> what you were saying is that the user should be responsible for
> allocating the buffers with complete ownership over them, and then
> just pass those allocated to the kernel to use. But what you're saying
> is that just use a different way for getting the kernel to allocate
> the buffers (eg through the IORING_REGISTER_MEM_REGION interface). Am
> I reading this correctly?

The main point is disentangling memory allocation from ring
creation in the io_uring uapi, and moving ring population
into fuse instead of doing it at creation. And it'll still be
populated by the kernel (fuse), user space doesn't have access
to the ring. IORING_REGISTER_MEM_REGION is just the easiest way
to achieve that without any extra uapi.

...
>> Pinning can be gated on that flag as well. Pretty likely uapi
>> and internals will be a bit cleaner, but that's not a huge deal,
>> just don't see why would you roll out a separate set of uapi
>> ([un]register, offsets, etc.) when essentially it can be treated
>> as the same thing.
> 
> imo, it looked cleaner as a separate api because it has different
> expectations and behaviors and squashing kmbuf into the pbuf api makes
> the pbuf api needlessly more complex. Though I guess from the

It appeared to me that they're different because of special
region path and embedded buffer allocations, and otherwise
differences would be minimal. But if you think it's still
better to be made as a separate opcode, I'm not opposing it,
go for it.

> userspace pov, liburing could have a wrapper that takes care of
> setting up the pbuf details for kernel-managed pbufs. But in my head,
> having pbufs vs. kmbufs makes it clearer what each one does vs regular
> pbufs vs. pbufs that are kernel-managed.
> 
> Especially with now having kmbufs go through the ioring mem region
> interface, it makes things more confusing imo if they're combined, eg
> pbufs that are kernel-managed are created empty and then populated
> from the kernel side by whatever subsystem is using them. Right now
> there's only one mem region supported per ring, but in the future if
> there's the possibility that multiple mem regions can be registered

That shouldn't be a problem

> (eg if userspace doesn't know upfront what mem region length they'll
> need), then we should also probably add in a region id param for the
> registration arg, which if kmbuf rings go through the pbuf ring
> registration api, is not possible to do.

Not having patches using the functionality is inconvenient. How
fuse looks up the buffer ring from io_uring? I could imagine you
have some control path io-uring command:

case FUSE_CMD_BIND_BUFFER_RING:
	return bind_queue(params);

Then you can pass all necessary parameters to it, pseudo code:

struct fuse_bind_kmbuf_ring_params {
	region_id;
	buf_ring_id;
	...
};

bind_queue(cmd, struct fuse_bind_kmbuf_ring_params *p)
{
	region = io_uring_get_region(cmd, p->region_id);
	// get exclusive access:
	buf_ring = io_uring_get_buf_ring(cmd, p->buf_ring_id);

	if (!validate_buf_ring(buf_ring))
		return NOTSUPPORTED;

	io_uring_pin(buf_ring);
	fuse_populate_buf_ring(buf_ring, region, ...);
}

Does that match expectations? I don't think you even need
the ring part exposed as an io_uring uapi, tbh, as it
stays completely in fuse and doesn't meaningfully interact
with the rest of io_uring.

...
>>>> 3. Require the user to register a memory region of appropriate size,
>>>>       see IORING_REGISTER_MEM_REGION, ctx->param_region. Make fuse
>>>>       populating the buffer ring using the memory region.
>>
>> To explain why, I don't think that creating many small regions
>> is a good direction going forward. In case of kernel allocation,
>> it's extra mmap()s, extra user space management, and wasted space.
> 
> To clarify, is this in reply to why the individual buffers shouldn't
> be allocated separately by the kernel?

That was about an argument for using IORING_REGISTER_MEM_REGION
instead a separate region. And it's separate from whether
buffers should be bound to the ring.

> I added a comment about this above in the discussion about
> io_region_allocate_pages_multi_buf(), and if the memory allocation
> issue I was seeing is bypassable and the region can be allocated all
> at once, I'm happy to make that change. With having the allocation be
> separate buffers though, I'm not sure I agree that there are extra
> mmaps / userspace management. All the pages across the buffers are
> vmapped together and the userspace just needs to do 1 mmap call for
> them. On the userspace side, I don't think there's more management
> since the mmapped address represents the range across all the buffers.
> I'm not seeing how there's wasted space either since the only

I shouldn't affect you much since you have such large buffers,
but imagine the total allocation size is not being pow2, and
the kernel allocating it as a single folio. E.g. 3 buffers,
0.5 MB each, total = 1.5MB, and the kernel allocates a 2MB
huge page.

-- 
Pavel Begunkov


  parent reply	other threads:[~2026-02-13 15:26 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-10  0:28 [PATCH v1 00/11] io_uring: add kernel-managed buffer rings Joanne Koong
2026-02-10  0:28 ` [PATCH v1 01/11] io_uring/kbuf: refactor io_register_pbuf_ring() logic into generic helpers Joanne Koong
2026-02-10  0:28 ` [PATCH v1 02/11] io_uring/kbuf: rename io_unregister_pbuf_ring() to io_unregister_buf_ring() Joanne Koong
2026-02-10  0:28 ` [PATCH v1 03/11] io_uring/kbuf: add support for kernel-managed buffer rings Joanne Koong
2026-02-10 16:34   ` Pavel Begunkov
2026-02-10 19:39     ` Joanne Koong
2026-02-11 12:01       ` Pavel Begunkov
2026-02-11 22:06         ` Joanne Koong
2026-02-12 10:07           ` Christoph Hellwig
2026-02-12 10:52             ` Pavel Begunkov
2026-02-12 17:29               ` Joanne Koong
2026-02-13  7:27                 ` Christoph Hellwig
2026-02-13 15:31                   ` Pavel Begunkov
2026-02-13 15:48                     ` Pavel Begunkov
2026-02-13 16:27                 ` Pavel Begunkov
2026-02-13  7:21               ` Christoph Hellwig
2026-02-13 13:18                 ` Pavel Begunkov
2026-02-13 15:26           ` Pavel Begunkov [this message]
2026-02-11 15:45     ` Christoph Hellwig
2026-02-12 10:44       ` Pavel Begunkov
2026-02-13  7:18         ` Christoph Hellwig
2026-02-13 12:41           ` Pavel Begunkov
2026-02-10  0:28 ` [PATCH v1 04/11] io_uring/kbuf: add mmap " Joanne Koong
2026-02-10  1:02   ` Jens Axboe
2026-02-10  0:28 ` [PATCH v1 05/11] io_uring/kbuf: support kernel-managed buffer rings in buffer selection Joanne Koong
2026-02-10  0:28 ` [PATCH v1 06/11] io_uring/kbuf: add buffer ring pinning/unpinning Joanne Koong
2026-02-10  1:07   ` Jens Axboe
2026-02-10 17:57     ` Caleb Sander Mateos
2026-02-10 18:00       ` Jens Axboe
2026-02-10  0:28 ` [PATCH v1 07/11] io_uring/kbuf: add recycling for kernel managed buffer rings Joanne Koong
2026-02-10  0:52   ` Jens Axboe
2026-02-10  0:28 ` [PATCH v1 08/11] io_uring/kbuf: add io_uring_is_kmbuf_ring() Joanne Koong
2026-02-10  0:28 ` [PATCH v1 09/11] io_uring/kbuf: export io_ring_buffer_select() Joanne Koong
2026-02-10  0:28 ` [PATCH v1 10/11] io_uring/kbuf: return buffer id in buffer selection Joanne Koong
2026-02-10  0:53   ` Jens Axboe
2026-02-10 22:36     ` Joanne Koong
2026-02-10  0:28 ` [PATCH v1 11/11] io_uring/cmd: set selected buffer index in __io_uring_cmd_done() Joanne Koong
2026-02-10  0:55 ` [PATCH v1 00/11] io_uring: add kernel-managed buffer rings Jens Axboe
2026-02-10 22:45   ` Joanne Koong

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=43f34edf-6a34-4afb-b0a3-0d81ec037a96@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=bernd@bsbernd.com \
    --cc=csander@purestorage.com \
    --cc=hch@infradead.org \
    --cc=io-uring@vger.kernel.org \
    --cc=joannelkoong@gmail.com \
    --cc=krisman@suse.de \
    --cc=linux-fsdevel@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