Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/rsrc: skip atomic refcount for uncloned buffers

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>
Link: https://lore.kernel.org/r/20250619143435.3474028-1-csander@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Caleb Sander Mateos and committed by
Jens Axboe
daa01d95 e448d578

+4 -2
+4 -2
io_uring/rsrc.c
··· 135 135 136 136 static void io_buffer_unmap(struct io_ring_ctx *ctx, struct io_mapped_ubuf *imu) 137 137 { 138 - if (!refcount_dec_and_test(&imu->refs)) 139 - return; 138 + if (unlikely(refcount_read(&imu->refs) > 1)) { 139 + if (!refcount_dec_and_test(&imu->refs)) 140 + return; 141 + } 140 142 141 143 if (imu->acct_pages) 142 144 io_unaccount_mem(ctx, imu->acct_pages);