From: Caleb Sander Mateos <csander@purestorage.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] io_uring/rsrc: skip atomic refcount for uncloned buffers
Date: Wed, 2 Jul 2025 17:11:42 -0400 [thread overview]
Message-ID: <CADUfDZo5O1zONAdyLnp+Nm2ackD5K5hMtQsO_q4fqfxF2wTcPA@mail.gmail.com> (raw)
In-Reply-To: <20250619143435.3474028-1-csander@purestorage.com>
Hi Jens,
Any concerns with this one? I thought it was a fairly straightforward
optimization in the ublk zero-copy I/O path.
Thanks,
Caleb
On Thu, Jun 19, 2025 at 10:34 AM Caleb Sander Mateos
<csander@purestorage.com> wrote:
>
> io_buffer_unmap() performs an atomic decrement of the io_mapped_ubuf's
> reference count in case it has been cloned into another io_ring_ctx's
> registered buffer table. This is an expensive operation and unnecessary
> in the common case that the io_mapped_ubuf is only registered once.
> Load the reference count first and check whether it's 1. In that case,
> skip the atomic decrement and immediately free the io_mapped_ubuf.
>
> Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
> ---
> io_uring/rsrc.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
> index 94a9db030e0e..9a1f24a43035 100644
> --- a/io_uring/rsrc.c
> +++ b/io_uring/rsrc.c
> @@ -133,12 +133,14 @@ static void io_free_imu(struct io_ring_ctx *ctx, struct io_mapped_ubuf *imu)
> kvfree(imu);
> }
>
> static void io_buffer_unmap(struct io_ring_ctx *ctx, struct io_mapped_ubuf *imu)
> {
> - if (!refcount_dec_and_test(&imu->refs))
> - return;
> + if (unlikely(refcount_read(&imu->refs) > 1)) {
> + if (!refcount_dec_and_test(&imu->refs))
> + return;
> + }
>
> if (imu->acct_pages)
> io_unaccount_mem(ctx, imu->acct_pages);
> imu->release(imu->priv);
> io_free_imu(ctx, imu);
> --
> 2.45.2
>
next prev parent reply other threads:[~2025-07-02 21:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-19 14:34 [PATCH] io_uring/rsrc: skip atomic refcount for uncloned buffers Caleb Sander Mateos
2025-07-02 21:11 ` Caleb Sander Mateos [this message]
2025-07-02 23:10 ` Jens Axboe
2025-07-03 1:23 ` Caleb Sander Mateos
2025-07-02 23:19 ` 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=CADUfDZo5O1zONAdyLnp+Nm2ackD5K5hMtQsO_q4fqfxF2wTcPA@mail.gmail.com \
--to=csander@purestorage.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=linux-kernel@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