I am running a random write benchmark directly on some disks (HDD & SDD) and I am getting some weird output data on the iostat monitor. Besides the usual write rate, there is a read rate that I can't understand why it's there.

This is the write benchmark program I did on C for the test (the core code for the question only):

fd=open("/dev/sda", O_WRONLY|O_CREAT|O_TRUNC, 0666); 
for (;;) {
    offset2=DLIMIT * (double)random() / RAND_MAX;
    retval = lseek64(fd, offset2, SEEK_SET);
    handle("lseek64", retval == (off64_t) -1);
    retval = write(fd, buffer, BLOCKSIZE);
    handle("write", retval < 0);

For example, during a 60 secs benchmark, iostat shows these average results:

54467,27(rkB/s) | 38147,37(wkB/s)

I did strace on the running program and it shows only write's and lseek's..

Another good info, If I run this program on a file (mounted filesystem from SDA), it doesn't show any read rate... just on this "/dev/sda" situation.

Any idea or explanation for this ghost read rate?

  • /dev/sda is a block device and not a character device, correct? – Mark Plotnick Mar 21 '16 at 13:50
  • yes, it is. I tested it with a HDD and with a SSD. Both had this problem. – Gustavo Portela Mar 21 '16 at 14:09
  • 1
    This answer may help: why dd reads from output device. When you write to non-block-aligned areas, the system will need to read in one or more blocks, modify the data, and write the blocks back. When writing to a file on a mounted filesystem, no reads may be necessary if the file has been cached in memory. – Mark Plotnick Mar 21 '16 at 14:23
  • Thank you, I believe that's the answer I was looking for! – Gustavo Portela Mar 21 '16 at 14:38

Your Answer

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

Browse other questions tagged or ask your own question.