I know that the Block I/O layer in Linux I/O stack manages and schedules I/O requests. but I do not know where this code is. indeed, I want to see the section of code in kernel which corresponds to this layer.


The scheduling of IO starts at the call of the blk_finish_plug function, that itself will call the elevator_add_req_fn method of the IO scheduler.

This is an example of a writeback tread calling this function to add new IOs:

#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

You can have a look at the files mentioned in the stack trace, especially the blk_finish_plug method of the blk-core.c file. You can find more details on how plugging works at https://lwn.net/Articles/438256/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.