在本人的系统软件中调用io_submit提交IO请求,长时间运行后会返回不为1,并且还伴随着 Bad File descripotr 错误。检查了提交先后文件描述符的值,都是对的;检查了文件是否存在,文件打开先后都是存在的。那到底什么缘由呢?less
首先的找到问题的直接缘由,这就须要理解io submit 的错误码。ide
经过 man io_submit 很容易看到:测试
io_submit returns the number of iocbs submitted and 0 if nr is zero. ERRORS EINVAL The aio_context specified by ctx_id is invalid. nr is less than 0. The iocb at *iocbpp[0] is not properly initialized, or the operation specified is invalid for the file descriptor in the iocb. EFAULT One of the data structures points to invalid data. EBADF The file descriptor specified in the first iocb is invalid. EAGAIN Insufficient resources are available to queue any iocbs.
针对io submit 返回的EBADF, 常见的错误包括:code
为此,笔者进行了下面的工做来检查是不是上面的错误:ip
基于上面的分析,把上述 cache 容量上限调整到所在磁盘的文件数量的上限,进行了一样的测试,长时间运行仍然稳定。所以,能够认为根因就是提交请求的文件描述符被fd cache中途关掉了。ci
经过分析上面的问题能够看到,针对通常的错误,咱们首先须要知道直接缘由,好比io submit 错误,须要知道错误码的含义、可能致使的缘由;而后据此结合时间系统上下文进行分析排查,才能完全定位、解决问题。it