Skip to content

ublk: honor rq_affinity on request completion

Yoav Cohen linux-block 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 2 repliesIn review
  2. v32 patches 1 replySuperseded
  3. v22 patches 4 repliesSuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2ublk: honor rq_affinity on request completiondrivers/block/ublk_drv.c include/uapi/linux/ublk_cmd.h+64 -121 reply
2/2selftests: ublk: add rq_affinity testtools/testing/selftests/ublk/Makefile tools/testing/selftests/ublk/kublk.c tools/testing/selftests/ublk/test_generic_19.sh+55 -11 reply

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchMing Lei
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/2] ublk: honor rq_affinity on request completion

ublk ends successfully completed requests inline on the server thread, so rq_affinity never redirects completion work back to the submitting CPU the way it does for NVMe, SCSI, virtio-blk, loop, nbd and rnbd. Patch 1 fixes that and adds a feature flag so servers can detect support. Patch 2 adds a selftest for it.

With an SPDK-style polling user-space block server at queue depth 96, rq_affinity=2 gives 7-8% higher IOPS than today's always-inline completion by offloading a saturated server CPU; rq_affinity=0 keeps the old behavior for anyone who wants to opt out.

v4, addressing Ming Lei's review of v3:
- The selftest didn't reach the remote completion path, as kublk pins the queue 0 thread to the first CPU of its hctx mask, which is where I/O was submitted. Use a single queue and submit from the last CPU in the hctx's cpu_list, so rq_affinity=2 always takes the remote path.
- No change to the driver patch.

v3, addressing Caleb Sander Mateos's and Ming Lei's review of v2:
- Pass whether the device opted in to __ublk_complete_rq() from the ublk_device its callers already have, instead of reading it through req->mq_hctx->driver_data and ubq->flags, which are likely cache misses on a server thread servicing many queues.
- ublk_end_rq() may run on a remote CPU, so it no longer touches ublk_io or ublk_queue; it only ends the request. Only a request that completed in full (io->res == blk_rq_bytes()) is redirected. Short completion, errors and copy-back failures stay in __ublk_complete_rq() as before.
- Drop the re-derivation of the completion path in ublk_end_rq(), and with it ublk_rq_need_unmap() and ublk_update_and_requeue().

v2, addressing Ming Lei's review of v1:
- v1 only redirected the classic-copy-mode successful-read completion; every write, flush/discard, error, and zero-copy/user-copy/ auto-buf-reg/shmem-zc I/O still completed inline as before, so rq_affinity had no effect for most traffic. v2 redirects every completion outcome.
- v1 ran the new completion path unconditionally on any patched kernel. v2 adds UBLK_F_SUPPORT_RQ_AFFINITY, which a server must request at ADD_DEV time; without it, behavior is unchanged.

Yoav Cohen (2):
ublk: honor rq_affinity on request completion
selftests: ublk: add rq_affinity test

 drivers/block/ublk_drv.c                      | 68 +++++++++++++++----
 include/uapi/linux/ublk_cmd.h                 |  8 +++
 tools/testing/selftests/ublk/Makefile         |  1 +
 tools/testing/selftests/ublk/kublk.c          |  6 +-
 .../testing/selftests/ublk/test_generic_19.sh | 51 ++++++++++++++
 5 files changed, 121 insertions(+), 13 deletions(-)
 create mode 100755 tools/testing/selftests/ublk/test_generic_19.sh
Signature · 1 line
2.50.1 (Apple Git-155)