目录
0.前言
内核版本:4.19
文档目的: 主要以null_dev为例来研究多队列的工作机制。本文主要以ext4文件系统为例,介绍null block dev读流程。注意本文所述流程是在开启blk-mq调度器的情况下进行的,开启方法为null blk驱动
中g_no_sched设为0。
1.通过文件系统读取nullb上的文件
new_sync_read
vfs_read
|--rw_verify_area(READ, file, pos, count)
\--__vfs_read(file, buf, count, pos)
\--if (file->f_op->read)
file->f_op->read(file, buf, count, pos)
else if (file->f_op->read_iter)
new_sync_read(file, buf, count, pos)
|--init_sync_kiocb(&kiocb, filp)
|--iov_iter_init(&iter, READ, &iov, 1, len)
\--call_read_iter(filp, &kiocb, &iter)
\--ext4_file_read_iter(kio, iter)
如上调用流程同 nullb driver分析2-读文件过程(禁用调度器)
ext4_file_read_iter
ext4_file_read_iter(kio, iter)
\--generic_file_read_iter(iocb, to)
\--if (iocb->ki_flags & IOCB_DIRECT)
对DIRECT IO的处理(TODO)
else
generic_file_buffered_read(iocb, iter, retval)
如上调用流程同 nullb driver分析2-读文件过程(禁用调度器)
generic_file_buffered_read
generic_file_buffered_read
|--if (PageReadahead(page))
| page_cache_async_readahead//异步读
|--wait_on_page_locked_killable(page)//如果页面锁定则说明正在读,block等待end bio唤醒即可
|--if (!trylock_page(page)) //如果页面没有被锁定,则跳转到page_not_up_to_date,锁定页面
| goto page_not_up_to_date
|--page_not_up_to_date:lock_page_kill

本文详细解析了在内核4.19版本中,当nullblockdev启用blk-mq调度器时,文件读取的复杂流程,涉及new_sync_read、vfs_read到调度队列的合并与执行。重点讲解了page_cache_async_readahead、blk_mq_flush_plug_list等关键环节。
最低0.47元/天 解锁文章
1049

被折叠的 条评论
为什么被折叠?



