io_uring/kbuf: recycle freed mapped buffer ring entries
authorJens Axboe <axboe@kernel.dk>
Tue, 28 Nov 2023 18:17:25 +0000 (11:17 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Dec 2023 07:52:21 +0000 (08:52 +0100)
commit9e1152a6c2b5488b688f50f81a6af029b2537258
treee1c3537573e31796f34f0e53f75fe6e87e4f1f6b
parent7138ebbe65caf65f52b923d4ef819c77d04ea671
io_uring/kbuf: recycle freed mapped buffer ring entries

commit b10b73c102a2eab91e1cd62a03d6446f1dfecc64 upstream.

Right now we stash any potentially mmap'ed provided ring buffer range
for freeing at release time, regardless of when they get unregistered.
Since we're keeping track of these ranges anyway, keep track of their
registration state as well, and use that to recycle ranges when
appropriate rather than always allocate new ones.

The lookup is a basic scan of entries, checking for the best matching
free entry.

Fixes: c392cbecd8ec ("io_uring/kbuf: defer release of mapped buffer rings")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
io_uring/kbuf.c