07年写的一篇文章,呵呵,贴上来以防哪天找不见了。当时用的应该是 FreeBSD 6.2,有空再整理下,把参数更新到 8.0 的。
AIO 一篇比较不错的介绍:
http://www.ibm.com/developerworks/cn/linux/l-async/-------------------------------
AIO系统参数含义:
sysctl param Default Comments
vfs.aio.max_aio_procs 32 Maximum number of kernel threads to use for handling async IO
vfs.aio.num_aio_procs - Number of presently active kernel threads for async IO
vfs.aio.target_aio_procs 4 Preferred number of ready kernel threads for async IO
对于 AIO,FreeBSD 中会开启一些 kernel thread 来处理这些逻辑,名字叫 aiodXX。target_aio_procs 是空闲的 aiod 数量,num_aio_procs 是当前系统中 aiod 的数量。在空闲的时候(没什么AIO任务),num_aio_procs == target_aio_procs,仅当 aio queue 有很多任务,而现有的 aiod 不够用时,才自动创建(aio_write/aio_read/lio_listio 会引发 aiod 的增多)。
max_aio_procs 是整个系统最大允许的 aiod 个数。
个人感觉,target_aio_procs 只是保证 AIO 空闲的时候,不会占用太多内存;而 target_aio_procs 设置得比较大的话,可以减少每次创建 aiod 的开销。如果同一时刻时 add to queue 的任务个数比较大(> target_aio_procs),则每次 aio_write/aio_read/lio_listio 都会迫使系统创建新的 aiod,等 I/O 结束后,系统又释放多余的 aiod,如此一来,还不如直接把 target_aio_procs 设置大一些。
vfs.aio.max_aio_queue 1024 Maximum number of aio requests to queue, globally
vfs.aio.num_queue_count - Number of queued aio requests
vfs.aio.num_buf_aio - Number of aio requests presently handled by the buf subsystem
num_queue_count 当前 AIO 请求量。max_aio_queue 是整个系统所允许的 AIO 请求上限,当 num_queue_count > max_aio_queue,则 aio_write/aio_read/lio_listio 返回 EAGAIN (系统资源不足)。
对于一些设备(device),可以不需要 aio queue,而直接写数据即可。num_buf_aio 表示系统当前有多少 AIO 请求,是此类情况的。
vfs.aio.max_aio_per_proc 32 Maximum active aio requests per process (stored in the process)
vfs.aio.max_aio_queue_per_proc 256 Maximum queued aio requests per process (stored in the process)
vfs.aio.max_buf_aio 16 Maximum buf aio requests per process (stored in the process)
除了上面那些系统级的限制,对于每个进程,max_aio_queue_per_proc 限制了一个进程允许占用的 aio queue slot 数量;而 max_aio_per_proc 限制一个进程,允许多少 aiod 为其效劳;max_buf_aio 限制一个进程所允许的 buf aio request 的量。
这三个参数,只在一个进程调用任意 aio_xxx 函数之前有效,一旦一个进程的 aio 操作启动(状态初始化了),则再调整这些参数不会影响该进程。
vfs.aio.aiod_timeout 10 sec Timeout value for synchronous aio operations
vfs.aio.aiod_lifetime 30 sec Maximum lifetime for idle aiod
对于一些 aio operation,需要将当前进程挂起(暂时sleep)一会,则 aiod_timeout 限制了最大的挂起时间。当一个 aiod 完成任务后,如果此时没有新的任务,且 num_aio_procs > target_aio_procs,则系统释放这个空闲的 aiod。
vfs.aio.unloadable 0 Allow unload of aio (not recommended)
在 FreeBSD,aio module 这类 kernel module 允许动态加载/卸载。如果 unloadable = 1,则在卸载 aio module 时,即使 queue 中还有任务,也不理会,直接丢弃。
-------------------------------
目前只是大概理解了系统参数的意思,更深入内容还需要继续学习。。
posix aio 在各个系统中还属于比较新的内容(似乎只有FreeBSD/Linux有实现),网络上的资料非常少。而且从网上一些帖子来看,aio 还不是非常稳定,lighttpd 的近期修改里面,还包含很多关于 posix aio 的内容(具体的还没细读)。
评论