-1

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!

2 Answers2

3

I am looking for a solution to detect how's the write function access to the disk.

Since your question mentions libc, we could assume that you are running under some operating system, and not on a "bare metal" system, in which case the answer is that write function doesn't access disk at all. It merely asks the OS to (eventually) write the data to disk.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
0

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.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Thank you for your answer. Well, I already read about sync and I use it on some disk benchmarks at the moment. I did a LD_PRELOAD wrapper to filter the write/lseek functions.. maybe that's a good start for tracking random and sequential accesses. no? – Gustavo Portela Nov 17 '15 at 13:12