AIO(4)
β¨ AIO(4) β the aio manual, bestie edition β¨
okay so this is the aio page from the Kernel Interfaces Manual β aka the tea on asynchronous I/O π grab a snack, we're going in
πΈ NAME πΈ
aio β asynchronous I/O π¦
π DESCRIPTION π
The aio facility hands you system calls for asynchronous I/O. And here's the whole vibe: asynchronous I/O operations are not completed synchronously by the calling thread. Not even a little. Instead, the calling thread makes one system call to request an asynchronous I/O operation, and then later β separately, whenever β the status of that completed request gets retrieved via a separate system call. Request now, check later. It's giving β¨delegationβ¨.
π¨ okay real talk bestie, this part matters: asynchronous I/O operations on some file descriptor types may block an AIO daemon indefinitely, which results in process and/or system hangs. Those file descriptor types are considered βunsafeβ and they are disabled by default. You can turn them on by setting the vfs.aio.enable_unsafe sysctl node to a non-zero value. lowkey dangerous, highkey your call π
Asynchronous I/O operations on sockets, raw disk devices, and regular files on local filesystems do not block indefinitely, and those are always enabled. no vibes check needed, they're fine π«Ά
The aio facility uses kernel processes (also known as AIO daemons) to service most asynchronous I/O requests. These processes are grouped into pools containing a variable number of processes. Each pool will add or remove processes to the pool based on load. Pools can be configured by sysctl nodes that define the minimum and maximum number of processes, as well as the amount of time an idle process will wait before exiting. it's giving adaptive staffing, honestly iconic π
π the socket pool π
One pool of AIO daemons is used to service asynchronous I/O requests for sockets. These processes are named βsoaiod<N>β. The following sysctl nodes are used with this pool:
kern.ipc.aio.num_procsβ The current number of processes in the pool. β¨kern.ipc.aio.target_procsβ The minimum number of processes that should be present in the pool.kern.ipc.aio.max_procsβ The maximum number of processes permitted in the pool.kern.ipc.aio.lifetimeβ The amount of time a process is permitted to idle in clock ticks. If a process is idle for this amount of time and there are more processes in the pool than the target minimum, the process will exit. bye bestie π
π the everything-else pool π
A second pool of AIO daemons is used to service all other asynchronous I/O requests except for I/O requests to raw disks. These processes are named βaiod<N>β. The following sysctl nodes are used with this pool:
vfs.aio.num_aio_procsβ The current number of processes in the pool.vfs.aio.target_aio_procsβ The minimum number of processes that should be present in the pool.vfs.aio.max_aio_procsβ The maximum number of processes permitted in the pool.vfs.aio.aiod_lifetimeβ The amount of time a process is permitted to idle in clock ticks. If a process is idle for this amount of time and there are more processes in the pool than the target minimum, the process will exit.
π¦ raw disks do their own thing π¦
Asynchronous I/O requests for raw disks are queued directly to the disk device layer, after temporarily wiring the user pages associated with the request. These requests are not serviced by any of the AIO daemon pools. they simply do not participate in the group chat π
π the limits (aka the boundaries, we love those) π
Several limits on the number of asynchronous I/O requests are imposed both system-wide and per-process. These limits are configured via the following sysctls:
vfs.aio.max_buf_aioβ The maximum number of queued asynchronous I/O requests for raw disks permitted for a single process. Asynchronous I/O requests that have completed but whose status has not been retrieved viaaio_return(2)oraio_waitcomplete(2)are not counted against this limit.vfs.aio.num_buf_aioβ The number of queued asynchronous I/O requests for raw disks system-wide.vfs.aio.max_aio_queue_per_procβ The maximum number of asynchronous I/O requests for a single process serviced concurrently by the default AIO daemon pool.vfs.aio.max_aio_per_procβ The maximum number of outstanding asynchronous I/O requests permitted for a single process. This includes requests that have not been serviced, requests currently being serviced, and requests that have completed but whose status has not been retrieved viaaio_return(2)oraio_waitcomplete(2).vfs.aio.num_queue_countβ The number of outstanding asynchronous I/O requests system-wide.vfs.aio.max_aio_queueβ The maximum number of outstanding asynchronous I/O requests permitted system-wide.
π control buffers & notifications π
Asynchronous I/O control buffers should be zeroed before initializing individual fields. This ensures all fields are initialized. fr fr, do it, it's not optional energy π
All asynchronous I/O control buffers contain a sigevent structure in the aio_sigevent field, which can be used to request notification when an operation completes. it's giving "text me when you're done" β¨
For SIGEV_KEVENT notifications:
- the
sigeventβssigev_notify_kqueuefield should contain the descriptor of the kqueue that the event should be attached to - its
sigev_notify_kevent_flagsfield may containEV_ONESHOT,EV_CLEAR, and/orEV_DISPATCH - its
sigev_notifyfield should be set toSIGEV_KEVENT
The posted kevent will contain:
identβ asynchronous I/O control buffer pointerfilterβEVFILT_AIOflagsβEV_EOFudataβ value stored inaio_sigevent.sigev_value
For SIGEV_SIGNO and SIGEV_THREAD_ID notifications, the information for the queued signal will include SI_ASYNCIO in the si_code field, and the value stored in sigevent.sigev_value in the si_value field.
For SIGEV_THREAD notifications, the value stored in aio_sigevent.sigev_value is passed to the aio_sigevent.sigev_notify_function as described in sigevent(3). π§
π₯ SEE ALSO π₯
aio_cancel(2)aio_error(2)aio_read(2)aio_return(2)aio_suspend(2)aio_waitcomplete(2)aio_write(2)lio_listio(2)sigevent(3)sysctl(8)
go read them, i'm obsessed with you learning things π
β HISTORY β
The aio facility appeared as a kernel option in FreeBSD 3.0. The aio kernel module appeared in FreeBSD 5.0. The aio facility was integrated into all kernels in FreeBSD 11.0. glow-up of the century honestly π
and that's the page bestie!! π this one came from Debian, dated June 22, 2017, and it's the AIO(4) page β mwah, thanks for reading, ily, go zero your control buffers π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2002 Dag-Erling CoΓ―dan SmΓΈrgrav
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms