I've been diving into the Linux kernel. and would like to trace an io request and find out exactly which process sent the current io request?
There is a structure named current which the kernel documentation says that represents currrent process.
However analysing the printk function in block/blk-core.c in function submit_bio it seems this is not the current process.
My printk is this:
printk(" Ata: in block/blk-core.c in submit_bio current task: %s pid:(%d): %s block %Lu on device %s (%u sectors)\n",
current->comm, task_pid_nr(current),
(rw & WRITE) ? "WRITE" : "READ",
(unsigned long long)bio->bi_iter.bi_sector,
bdevname(bio->bi_bdev, b),
count);
However the output of it is not what I was expecting:
[Thu Dec 31 15:18:49 2015] Ata: in block/blk-core.c in submit_bio current task: jbd2/sda1-8 pid:(494): WRITE block 54798672 on device sda1 (8 sectors)
the output says that current process is jbd2. According to this answer jbd2 is a function run by filesystem. In contrast with this my process was dd with pid : 2479.
How can I find exactly which process sent the current io request? something like iotop is doing.