biosnoop/biotop always return BYTES 0
Hi, I'm trying on running biosnoop.py on my desktop machine, but I'm always getting 0 for BYTES as shown below. (same for biotop.py)

This is the result while my desktop is on idle state, and also getting 0 for BYTES when I'm writing actual data to a file.
Any idea why I'm not getting the right value for the BYTES?
Hey
What kernel are you using? do you get the appropriate output using Brendans ftrace scripts?
Al
On Wed, 16 Sep 2020 at 13:58, YJYJLee [email protected] wrote:
Hi, I'm trying on running biosnoop.py on my desktop machine, but I'm always getting 0 for BYTES as shown below. (same for biotop.py)
[image: image] https://user-images.githubusercontent.com/28900943/93340094-559e9e80-f867-11ea-9c5e-ffc905bbca77.png
This is the result while my desktop is on idle state, and also getting 0 for BYTES when I'm writing actual data to a file.
Any idea why I'm not getting the right value for the BYTES?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/iovisor/bcc/issues/3099, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ5WVH6PMUGYWMOHZFGK3TSGCY5XANCNFSM4ROZLCVA .
I'm using Ubuntu 18.04, 5.3.0-62-generic kernel.
It turns out that biosnoop.py gets its request length once I/O is done (when blk_account_io_done is called). At this point request's length is zero.
I changed the code to retrieve the length of request at the start of I/O (attached kprobe to blk_account_io_start) and I think I'm getting the right result now.

I have the same issue on Fedora 33, kernel 5.8.1-300.fc33.x86_64, using BCC 0.16.0
Running /usr/share/bcc/tools/biotop in one terminal and while true; do dd if=/dev/zero of=tmp bs=10M oflag=direct; done in another, I see
PID COMM D MAJ MIN DISK I/O Kbytes AVGms
3324 dd W 252 0 vda 63 0.0 15.95
Also with other programs (e.g. running dnf update), Kbytes is always zero.
It turns out that biosnoop.py gets its request length once I/O is done (when blk_account_io_done is called). At this point request's length is zero.
Sounds like an explanation. Commit 95c9229ea9f029a1b9e8dcbe86fc67f037c0dfa2 changed the kprobe from blk_account_io_completion to blk_account_io_done.
I checked biotop on Fedora 31, Kernel 5.7 and BCC 0.15.0, works fine there. Updating the BCC script to use blk_account_io_done, the Kbytes column stays zero. So this kprobe is definitely the culprit here.
I changed the code to retrieve the length of request at the start of I/O (attached kprobe to blk_account_io_start) and I think I'm getting the right result now.
Is this really the correct way? This kprobe is already attached in trace_pid_start, but I'm not sure if this actually catches all I/O requests. Can someone confirm this?
@YJYJLee: can you please reopen this issue? It should be fixed in this repository, manual patching shouldn't be required for end users.
Reopend. My solution is temporary, I agree. It definitely depends on kernel versions, thus the fixed version needs to support various kernel versions.
Right. We need to fix this properly in the tool. Maybe req->__data_len keeps decreasing every time when a sub-request gets processed? Geting the value from start at least gives us the correct answer?
Is this really the correct way? This kprobe is already attached in trace_pid_start, but I'm not sure if this actually catches all I/O requests. Can someone confirm this?
If I remember correctly, blk_start_request is not able to capture all start request, so requests may be from fsync, or something like that. Not sure about blk_account_io_start, need to check.
@YJYJLee @andreasgerstmayr Even if blk_start_request is not able to capture all start request, but it still should capture most requests, I think. We need some experiments to prove that though. How about the following to make it work for both old way of attachment and new attachment as I did not find an easy condition to pick one vs. another. Using kernel version is not a good idea as it won't work for backported kernels. How about the following approach:
- record the data_len during
trace_req_start - during
trace_req_completion, if req->__data_len is not 0, use that __data_len, otherwise, using the one recorded during trace_req_start. - add comments to explain why we did this way. Does this sound a reasonable approach? Could you submit a pull request? Thanks!
It could be trace_req_completion already has req->__data_len = 0 since __data_len is decremented until the end. So it makes sense just using the one recorded during trace_req_start?
It could be
trace_req_completionalready has req->__data_len = 0 since __data_len is decremented until the end. So it makes sense just using the one recorded duringtrace_req_start?
Yep, I guess so. However, doing a quick grep for __data_len shows that it can also be incremented if multiple IOs get coalesced (merged) afaics.
I also noticed a /* the following two fields are internal, NEVER access directly */ comment on top of the __data_len field :|
Anyway, current solution would be to create another BPF map (with struct request *req as key) and store the __data_len field in trace_req_start? There are quite a few instructions required to calculate the key for the counts map, so I'd just create another map.
@andreasgerstmayr sounds good. thanks. For
Yep, I guess so. However, doing a quick grep for __data_len shows that it can also be incremented if multiple IOs get coalesced (merged) afaics. Do you know where this happens? This should be before
trace_req_start? Right?