Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change kernel i/o buffer size

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.

like image 316
jitihsk Avatar asked Aug 12 '11 18:08

jitihsk


2 Answers

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 using fsync, sync_file_range, posix_fadvise, and posix_madvise. (O_DIRECT and sync_file_range are 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.

like image 140
Nemo Avatar answered Nov 16 '22 14:11

Nemo


I think you mean the disk IO queues. For example:

$ cat /sys/block/sda/queue/nr_requests
128

How this queue is used depends on the IO scheduler that is in use.

$ cat /sys/block/sda/queue/scheduler
noop anticipatory deadline [cfq]

cfq is the most common choice, although on systems with advanced disk controllers and in virtual guest systems noop is also a very good choice.

There is no config file for this information that I am aware of. On systems that I need to change the queue settings on I put the changes into /etc/rc.local although you could use a full-up init script instead and place it into an RPM or DEB for mass distribution to a lot of systems.

like image 36
Zan Lynx Avatar answered Nov 16 '22 15:11

Zan Lynx