To minimize the disk access using fsync

781 Views Asked by At

There is a situation that whenever a write occurs, fsync is used with that write. Then, how to minimise the disk access? How the kernel does this?

fsync() transfers ("flushes") all modified in-core data of (i.e., modified buffer cache pages for) the file referred to by the file descriptor fd to the disk device (or other permanent storage device).

I think Kernel can transfer the data of all the modified buffers to the hard disk periodically after some time. So that it can minimise the disk access.

Please give some suggestions/hints.

1

There are 1 best solutions below

0
On

In general, try to avoid overthinking it. Don't call fsync, just let the kernel decide when to do the physical write.

Here are kernel options for ext4, which you can use to tune the kernel's behavior to your needs - but this would be a server tuning exercise rather than something you could implement from your application: http://kernel.org/doc/Documentation/filesystems/ext4.txt

This might be an interesting one: " max_batch_time=usec Maximum amount of time ext4 should wait for additional filesystem operations to be batch together with a synchronous write operation. "