I am emptying out a hard drive on some Linux 4.x OS using this command:
sudo sh -c 'pv -pterb /dev/zero > /dev/sda'
And I opened another tty and started sudo htop
and noticed this:
PID USER PRI NI CPU% RES SHR IO_RBYTES IO_WBYTES S TIME+ Command
4598 root 20 0 15.5 1820 1596 4096 17223823 D 1:14.11 pv -pterb /dev/zero
The value for IO_WBYTES
seems quite normal, but IO_RBYTES
remains at 4 KiB and never changes.
I ran a few other programs, for example
dd if=/dev/zero of=/dev/zero
cat /dev/zero > /dev/zero
and was surprised to see none of them generates a lot of IO_RBYTES
or IO_WBYTES
.
I think this is not specific to any program, but why don't reads from /dev/zero
and writes to /dev/{zero,null}
count as I/O bytes?
Best Answer
They do count as I/O, but not of the type measured by the fields you’re looking at.
In
htop
,IO_RBYTES
andIO_WBYTES
show theread_bytes
andwrite_bytes
fields from/proc/<pid>/io
, and those fields measure bytes which go through the block layer./dev/zero
doesn’t involve the block layer, so reads from it don’t show up there.To see I/O from
/dev/zero
, you need to look at therchar
andwchar
fields in/proc/<pid>/io
, which show up inhtop
asRCHAR
andWCHAR
:See
man 5 proc
andman 1 htop
for details.