io_uring_queue_init(3)
β¨ io_uring_queue_init(3) β¨
okay bestie, sit down, hydrate, and let me tell you about io_uring_queue_init π this is a page from the liburing Manual and it's literally the moment your app and the kernel become besties. setting up the io_uring submission and completion queues? yeah. that's the whole vibe. π
πΈ SYNOPSIS πΈ
#include <liburing.h>
int io_uring_queue_init(unsigned entries,
struct io_uring *ring,
unsigned flags);
int io_uring_queue_init_params(unsigned entries,
struct io_uring *ring,
struct io_uring_params *params);
int io_uring_queue_init_mem(unsigned entries,
struct io_uring *ring,
struct io_uring_params *params,
void *buf, size_t buf_size);
three whole flavors, all iconic, pick your fighter π«Ά
π DESCRIPTION π
so what does io_uring_queue_init(3) actually do, bestie? it runs the io_uring_setup(2) system call to initialize the submission and completion queues in the kernel with at least entries entries in the submission queue, and then it maps the resulting file descriptor to memory that's shared between your application and the kernel. like. shared custody but make it syscalls. π
by default, the CQ ring will have twice the number of entries as specified by entries for the SQ ring. this is adequate for regular file or storage workloads, but ngl it may be too small for networked workloads. and listen β the SQ ring entries do not impose a limit on the number of in-flight requests that the ring can support, it merely limits the number that can be submitted to the kernel in one go (batch). that's such an important distinction, no cap. β¨
if the CQ ring overflows β like, more entries are generated than fit in the ring before the application can reap them β then if the kernel supportsIORING_FEAT_NODROP, the ring enters a CQ ring overflow state. otherwise it drops the CQEs and incrementscq.koverflowinstruct io_uringwith the number of CQEs dropped. π
the overflow state is indicated by IORING_SQ_CQ_OVERFLOW being set in the SQ ring flags. unless the kernel runs out of available memory, entries are not dropped, but it is a much slower completion path and will slow down request processing. for that reason it should be avoided and the CQ ring sized appropriately for the workload. like, don't do that to yourself. π
setting cq_entries in struct io_uring_params will tell the kernel to allocate this many entries for the CQ ring, independent of the SQ ring size given in entries. and if the value isn't a power of 2, it will be rounded up to the nearest power of 2. math ate, honestly. π
on success, io_uring_queue_init(3) returns 0 and ring will point to the shared memory containing the io_uring queues. on failure, -errno is returned.
flags will be passed through to the io_uring_setup syscall (see io_uring_setup(2)).
the io_uring_queue_init_params(3) and io_uring_queue_init_mem(3) variants will pass the parameters indicated by params straight through to the io_uring_setup(2) system call. no filter, no editing, straight through. π
π¦ the io_uring_queue_init_mem(3) variant π¦
this one uses the provided buf with associated size buf_size as the memory for the ring, using the IORING_SETUP_NO_MMAP flag to io_uring_setup(2).
the buffer passed to io_uring_queue_init_mem(3) must be page size aligned on the host, and must already be zeroed. not optional, bestie, that's a hard requirement. π
typically, the caller should allocate a huge page and pass that in to io_uring_queue_init_mem(3). pages allocated by mmap are already zeroed, so that's your easy path. π
io_uring_queue_init_mem(3) returns the number of bytes used from the provided buffer, so that the app can reuse the buffer with the returned offset to put more rings in the same huge page. it's giving efficiency. it's giving main character energy. π₯
π on success, the resources held byringshould be released via a corresponding call toio_uring_queue_exit(3). please. don't leave it hanging. π«Ά
β RETURN VALUE β
io_uring_queue_init(3)andio_uring_queue_init_params(3)return0on success and-errnoon failure.io_uring_queue_init_mem(3)returns the number of bytes used from the provided buffer on success, and-errnoon failure.
π SEE ALSO π
and that's the tea, bestie π this was liburing-0.7, dated July 10, 2020 β go forth and initialize your queues responsibly, mwah π β¨πΈ
π¦ where this page comes from
- alpine 3.23: liburing-doc 2.12-r0 Β· LGPL-2.1-or-later OR MIT
- alpine 3.24: liburing-doc 2.14-r0 Β· LGPL-2.1-or-later OR MIT
- centos-stream 10: liburing-devel 2.12-1.el10 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- centos-stream 9: liburing-devel 2.12-1.el9 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- centos-stream 9: liburing-devel 2.12-1.el9 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- nixpkgs unstable: liburing 2.14
- ubuntu questing: liburing-dev 2.11-1
- ubuntu resolute: liburing-dev 2.14-1
- π the page's license: LGPL-2.0-or-later
- Copyright (C) 2020 Jens Axboe <axboe@kernel.dk>
- Copyright (C) 2020 Red Hat, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms