Linux – How to improve IO when there is a lot of random read and write

iolinux

My scripts uses tons of read and writes. Most of them are small and random. I want Linux to wait 10 seconds before writing any data to the disk.

How would this be achieved?

I think Linux can already do this automatically. I want to do it in a more extreme way. It's like supercache in Windows.

Note: This is related to question Does linux have something like supercache? . I already know that by default linux use "supercache" like system. However the supercache-like setting for linux must be low. I want more share of memory is for supercache. I also want lazy writes every 10 seconds.

Best Answer

There are 5 tunables in the /proc file system to change linux' writeback behavior:

dirty_async_ratio
dirty_background_ratio
dirty_sync_ratio
dirty_expire_centisecs
dirty_writeback_centisecs

The configuration is quite complicated and documentation can be found at kernel.org. However, as jordanm already said, "Any userspace application can tell the kernel to write its dirty buffers to disk via the sync() system call." which means that any other process might render your configuration useless.

Also keep your Filesystem settings in mind: Mount options like noatime, data=writeback and nobarrier can dramatically improve your throughput but will also put your data at risk, if your disk controllers are not battery backed.

Related Question