我知道Block I/O层Linux I/O 堆栈管理和调度 I/O 请求。但我不知道这段代码在哪里。确实,我想查看内核中与该层对应的代码部分。
答案1
IO的调度从blk_finish_plug函数的调用开始,该函数本身将调用IO调度程序的elevator_add_req_fn方法。
这是调用此函数来添加新 IO 的写回步骤的示例:
#0 deadline_add_request at block/deadline-iosched.c:102
#1 __elv_add_request at block/elevator.c:717
#2 blk_flush_plug_list at block/blk-core.c:2746
#3 blk_finish_plug at block/blk-core.c:2762
#4 generic_writepages at mm/page-writeback.c:1052
#5 do_writepages at mm/page-writeback.c:1065
#6 writeback_single_inode at fs/fs-writeback.c:388
#7 writeback_sb_inodes at fs/fs-writeback.c:549
#8 writeback_inodes_wb at fs/fs-writeback.c:592
#9 wb_writeback at fs/fs-writeback.c:724
#10 wb_check_background at fs/fs-writeback.c:804
#11 wb_do_writeback at fs/fs-writeback.c:879
#12 bdi_writeback_thread at fs/fs-writeback.c:913
#13 kthread at kernel/kthread.c:96
您可以查看堆栈跟踪中提到的文件,尤其是 blk-core.c 文件的 blk_finish_plug 方法。您可以在以下位置找到有关堵塞工作原理的更多详细信息:https://lwn.net/Articles/438256/