io_submit(3)
π io_submit(3) β Linux AIO π
okay bestie, welcome to the io_submit page from the Linux AIO manual. this is the one where you yeet a whole pile of io requests at the kernel at once and hope for the best. let's get into it π«Ά
β¨ NAME β¨
io_submit β Submit io requests. that's it. that's the vibe. π
πΈ SYNOPSIS πΈ
#include <errno.h>
#include <libaio.h>
int io_submit(io_context_t ctx, long nr, struct iocb *iocbs[]);
struct iocb {
void *data;
unsigned key;
short aio_lio_opcode;
short aio_reqprio;
int aio_fildes;
};
π¦ DESCRIPTION π¦
so io_submit() submits nr iocbs for processing for a given io context ctx. slay.
the way this works is highkey flexible β you can enqueue an arbitrary number of read and write requests at one time. and the requests? they can all be for the same file, all be for different files, or literally every solution in between. no cap, the range is that wide. π
io_submit() gets the nr requests from the array pointed to by iocbs. and which operation actually happens? that's decided by the aio_lio_opcode member in each element of iocbs. let me break it down bestie:
- if that field is
IO_CMD_PREAD, a read operation gets enqueued, similar to a call ofio_prep_preadfor this element of the array β except that the way the termination is signalled is different, as we will see below. π - if the
aio_lio_opcodemember isIO_CMD_PWRITE, a write operation gets enqueued. - otherwise the
aio_lio_opcodemust beIO_CMD_NOP, in which case this element ofiocbsis simply ignored. this "operation" is useful in situations where you have a fixed array ofstruct iocbelements and only a few of them need to be handled at a time. another situation is where theio_submit(3)call was canceled before all requests were processed and the remaining requests have to be reissued. very main character energy of you to plan ahead like that. π
the other members of each element of the array pointed to by iocbs must have values suitable for the operation, as described in the documentation for io_prep_pread(3) and io_prep_pwrite(3) above. π
the function returns immediately after having enqueued all the requests. not me just... dropping them off and leaving π
on success, io_submit() returns the number of iocbs submitted successfully. otherwise, -error is returned, where error is one of the Exxx values defined in the Errors section. periodt.
β οΈ if an error is detected, then the behavior is undefined. bestie. i'm serious. π
β οΈ simultaneous asynchronous operations using the same iocb produce undefined results. don't do it. i'm begging. π
π ERRORS π
EFAULTβiocbsreferenced data outside of the program's accessible address space.EINVALβctxrefers to an uninitialized aio context, theiocbpointed to byiocbscontains an improperly initializediocb,EBADFβ theiocbcontains a file descriptor that does not exist.EINVALβ the file specified in theiocbdoes not support the given io operation.
(yes there are two EINVALs. iconic. she contains multitudes. π)
β SEE ALSO β
io(3), io_cancel(3), io_fsync(3), io_getevents(3), io_prep_fsync(3), io_prep_pread(3), io_prep_pwrite(3), io_queue_init(3), io_queue_release(3), io_queue_run(3), io_queue_wait(3), io_set_callback(3), errno(3).
and that's the page, bestie!! π go forth and submit your iocbs responsibly β¨
this one's from the Linux crew, dated 2019-07-23 β so yeah, she's got a lil vintage moment going on, but she still eats π π¦
π¦ where this page comes from
- alpine 3.22: libaio-doc 0.3.113-r2 Β· LGPL-2.1-or-later
- alpine 3.23: libaio-doc 0.3.113-r2 Β· LGPL-2.1-or-later
- alpine 3.24: libaio-doc 0.3.113-r2 Β· LGPL-2.1-or-later
- arch rolling: libaio 0.3.113-5 Β· LGPL-2.0-or-later
- debian bookworm: libaio-dev 0.3.113-4 Β· LGPL-2.1-or-later
- debian trixie: libaio-dev 0.3.113-8+b1 Β· LGPL-2.1-or-later
- ubuntu jammy: libaio-dev 0.3.112-13build1 Β· LGPL-2.1-or-later
- ubuntu noble: libaio-dev 0.3.113-6build1 Β· LGPL-2.1-or-later
- ubuntu noble: libaio-dev 0.3.113-6build1.1 Β· LGPL-2.1-or-later
- ubuntu questing: libaio-dev 0.3.113-8
- ubuntu resolute: libaio-dev 0.3.113-8build1 Β· LGPL-2.1-or-later
- ubuntu stonking: libaio-dev 0.3.113-9 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms