io_uring: speedup provided buffer handling
authorJens Axboe <axboe@kernel.dk>
Wed, 9 Mar 2022 00:46:52 +0000 (17:46 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 10 Mar 2022 13:33:14 +0000 (06:33 -0700)
commitcc3cec8367cba76a8ae4c271eba8450f3efc1ba3
tree23a60579ae1cc6438208a64d7be4867f5240de9f
parente7a6c00dc77aedf27a601738ea509f1caea6d673
io_uring: speedup provided buffer handling

In testing high frequency workloads with provided buffers, we spend a
lot of time in allocating and freeing the buffer units themselves.
Rather than repeatedly free and alloc them, add a recycling cache
instead. There are two caches:

- ctx->io_buffers_cache. This is the one we grab from in the submission
  path, and it's protected by ctx->uring_lock. For inline completions,
  we can recycle straight back to this cache and not need any extra
  locking.

- ctx->io_buffers_comp. If we're not under uring_lock, then we use this
  list to recycle buffers. It's protected by the completion_lock.

On adding a new buffer, check io_buffers_cache. If it's empty, check if
we can splice entries from the io_buffers_comp_cache.

This reduces about 5-10% of overhead from provided buffers, bringing it
pretty close to the non-provided path.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c