I am running some experiments with I/O intensive applications and am trying to understand the effects of varying the kernel i/o buffer size, different elevator algorithms, and so on.
How can I know the current size of the i/o buffer in the kernel? Does the kernel use more than one buffer as need arises? How can I change the size of this buffer? Is there a config file somewhere that stores this info?
(To be clear, I am not talking about processor or disk caches, I am talking about the buffer used by the kernel internally that buffers reads/writes before flushing them out to disk from time to time).
Thanks in advance.
The kernel does not buffer reads and writes the way you think… It maintains a “page cache” that holds pages from the disk. You do not get to manipulate its size (well, not directly, anyway); the kernel will always use all available free memory for the page cache.
You need to explain what you are really trying to do. If you want some control over how much data the kernel pre-fetches from disk, try a search for “linux readahead”. (Hint:
blockdev --setra XXX)If you want some control over how long the kernel will hold dirty pages before flushing them to disk, try a search for “linux dirty_ratio”.
A specific application can also bypass the page cache completely by using
O_DIRECT, and it can exercise some control over it usingfsync,sync_file_range,posix_fadvise, andposix_madvise. (O_DIRECTandsync_file_rangeare Linux-specific; the rest are POSIX.)You will be able to ask a better question if you first educate yourself about the Linux VM subsystem, especially the page cache.