AIO(4)
π aio(4) β asynchronous I/O π
hiii bestie!! welcome to the Kernel Interfaces Manual page for aio(4), aka the async I/O situation. lowkey iconic, highkey kernel-coded. letβs get into it π«Άβ¨
β¨ NAME β¨
aio β asynchronous I/O
π DESCRIPTION π
okay so the aio facility is literally the whole system-call crew for asynchronous I/O. π« Asynchronous I/O operations are not completed synchronously by the calling thread. Instead, the calling thread invokes one system call to request an asynchronous I/O operation, and the status of a completed request gets retrieved later via a separate system call. no cap, thatβs the whole vibe.
Some file descriptor types are giving βhandle with cautionβ energy: asynchronous I/O operations on some file descriptor types may block an AIO daemon indefinitely, which can result in process and/or system hangs. π Operations on these file descriptor types are considered βunsafeβ and are disabled by default. They can be enabled by setting the vfs.aio.enable_unsafe sysctl node to a non-zero value.
π¨ bestie warning: βunsafeβ here is not a cute aesthetic. those operations can block an AIO daemon indefinitely and cause process and/or system hangs.
But not everything is scary: asynchronous I/O operations on sockets, raw disk devices, and regular files on local filesystems do not block indefinitely and are always enabled. slay. π
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. π§
𧦠the socket pool: soaiod<N>
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.
π§ the other pool: aiod<N>
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.
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. π οΈ
π the limit sysctls
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.
π completion notifications
Asynchronous I/O control buffers should be zeroed before initializing individual fields. This ensures all fields are initialized. β¨
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.
For SIGEV_KEVENT notifications, the sigevent's sigev_notify_kqueue field should contain the descriptor of the kqueue that the event should be attached to, its sigev_notify_kevent_flags field may contain EV_ONESHOT, EV_CLEAR, and/or EV_DISPATCH, and its sigev_notify field should be set to SIGEV_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_readv(2)aio_return(2)aio_suspend(2)aio_waitcomplete(2)aio_write(2)aio_writev(2)lio_listio(2)sigevent(3)sysctl(8)
πΈ HISTORY πΈ
- The
aiofacility appeared as a kernel option in FreeBSD 3.0. π - The
aiokernel module appeared in FreeBSD 5.0. - The
aiofacility was integrated into all kernels in FreeBSD 11.0. π
β Debian π January 2, 2021 π AIO(4)
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2002 Dag-Erling SmΓΈrgrav
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms