Search code examples
randomsystem-callshard-drivelibcsequential

write system call C - HDD Sequential or Random Access ?


I am looking for a solution to detect how's the write function access to the disk. I want to know if it is a sequential or random access. I thought about open the write system call on the libC and try to edit it and count if it is a random or seq access.. is it possible? how?

If there's another solution I would be thankful to know it!


Solution

  • Your question probably has no sense today, because on today's disk even the hardware is handling disk sectors logically: two "consecutive" disk sectors are not physically near, because the hard disk controller is remapping them. Read also about SATA. Some controllers are even able to re-order pending disk requests.

    BTW, an SSD does not have any physical geometry (for sectors), but does give the appearance of sector numbering.

    In addition, the operating system kernel (notably Linux) is managing the page cache so a write usually won't write directly the disk. See e.g. the sync(2) syscall.

    At last, write(2) is (on Linux and most Unixes) a syscall, and happens inside the kernel. So you won't be able to change its behavior in your libc.

    Read also about SMART.