I have following code for opening all files:
int ret= open(zFile, flags, mode);
posix_fadvise (ret, 0, 0, POSIX_FADV_RANDOM);
and posix_fadvise return 0 means success.
But it is not working correctly.
OS: Ubuntu 12.04
Strace is showing that the read done by the program is
29088 bytes.
I used following command to calculate read from strace log
cat fadvise3.log | grep read | awk '{SUM+=$NF} END {print SUM}'
But iotop is showing that program has read about 2.5 MB.
- Is there a way I can know why it is reading that much ?
- Why iotop O/p is not matching with strace?
- Why posix_fadvise (ret, 0, 0, POSIX_FADV_RANDOM); is not working?
- How can I disable read ahead for a process?
More details about read:
I am using sqlite library. and modified their function posixOpen to open a database. Read is done by sqlite.
Disk read are done in disk block, this is a hardware limit,
POSIX_FADV_RANDOMcan’t change that. If you read less then a block, you still have to pay the cost of that block.Even so,
posix_fadvise, as its name suggest, is just an advise to the kernel. A hint. Not a strict rule.