History

io_uring: add support for registering ring file descriptors

Lots of workloads use multiple threads, in which case the file table is shared between them. This makes getting and putting the ring file descriptor for each io_uring_enter(2) system call more expensive, as it involves an atomic get and put for each call. Similarly to how we allow registering normal file descriptors to avoid this overhead, add support for an io_uring_register(2) API that allows to register the ring fds themselves: 1) IORING_REGISTER_RING_FDS - takes an array of io_uring_rsrc_update structs, and registers them with the task. 2) IORING_UNREGISTER_RING_FDS - takes an array of io_uring_src_update structs, and unregisters them. When a ring fd is registered, it is internally represented by an offset. This offset is returned to the application, and the application then uses this offset and sets IORING_ENTER_REGISTERED_RING for the io_uring_enter(2) system call. This works just like using a registered file descriptor, rather than a real one, in an SQE, where IOSQE_FIXED_FILE gets set to tell io_uring that we're using an internal offset/descriptor rather than a real file descriptor. In initial testing, this provides a nice bump in performance for threaded applications in real world cases where the batch count (eg number of requests submitted per io_uring_enter(2) invocation) is low. In a microbenchmark, submitting NOP requests, we see the following increases in performance: Requests per syscall Baseline Registered Increase ---------------------------------------------------------------- 1 ~7030K ~8080K +15% 2 ~13120K ~14800K +13% 4 ~22740K ~25300K +11%

Jens Axboe committed 4 years ago

Commit e7a6c001 parent 63c36543 files · +190 −10Browse files

Showing the changes to include/uapi (1 of 3 files). Show all

Unified · Split

include/uapi/linux/io_uring.h+9−4
@@ -257,10 +257,11 @@ struct io_cqring_offsets { · 256 unmodified lines
257257 /*
258258 * io_uring_enter(2) flags
259259 */
260−#define IORING_ENTER_GETEVENTS (1U << 0)
261−#define IORING_ENTER_SQ_WAKEUP (1U << 1)
262−#define IORING_ENTER_SQ_WAIT (1U << 2)
263−#define IORING_ENTER_EXT_ARG (1U << 3)
260+#define IORING_ENTER_GETEVENTS (1U << 0)
261+#define IORING_ENTER_SQ_WAKEUP (1U << 1)
262+#define IORING_ENTER_SQ_WAIT (1U << 2)
263+#define IORING_ENTER_EXT_ARG (1U << 3)
264+#define IORING_ENTER_REGISTERED_RING (1U << 4)
264265
265266 /*
266267 * Passed in for io_uring_setup(2). Copied back with updated info on success
@@ -325,6 +326,10 @@ enum { · 58 unmodified lines
325326 /* set/get max number of io-wq workers */
326327 IORING_REGISTER_IOWQ_MAX_WORKERS = 19,
327328
329+ /* register/unregister io_uring fd with the ring */
330+ IORING_REGISTER_RING_FDS = 20,
331+ IORING_UNREGISTER_RING_FDS = 21,
332+
328333 /* this goes last */
329334 IORING_REGISTER_LAST
330335 };