I'm working on creating a tool to display system stats on Linux. I'm using the /sys and /proc APIs for this to learn how they work.

Currently, I'm reading /sys/block/<dev>/stat to get block device statistics (docs). This works great for seeing how much reading and writing is happening on disk, but I'm wondering if it is possible to see the total block device I/O from an application's perspective.

Here's an example to demonstrate what I mean:

> cat somebigfile > /dev/zero # Takes some time, triggers device I/O
> cat somebigfile > /dev/zero # Runs quickly a second time, no device I/O

I believe the difference between the two runs is due to the kernel going to the buffer cache rather than the disk for the second read. I have confirmed this by flushing the cache using /proc/sys/vm/drop_caches causing the command to execute like the first time again.

What is the easiest way to see the total bytes read from block devices, including bytes served from the buffer cache, over some time period?

I have also considering summing the values in /proc/<pid>/io, but this includes all I/O and isn't split out by device or type.

I am aware that I could do this using something like System Tap, but I'm wondering if there is a simpler way.

1 Answer 1


I wrote 'stat collector' service several years ago - rwdisk_stat.

I used values in /sys/block/<dev>/stat and then converted their in bytes.

From application perspective, cgroups is useful. It's possible to put distinguish application in some group 'blkio' and read 'blkio.io_service_bytes' counter.

  • 1
    Thanks for that. That sounds like what I am doing currently. In your case, you were measuring bytes actually read/written to disk. I'd like to do this but also include bytes that applications read/write to "disk", but that were actually served by the buffer cache.
    – jncraton
    Commented Mar 7, 2018 at 1:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .