I'm currently experimenting with the kernel parameters found in /proc/sys/vm
, especially dirty_ratio
and dirty_background_ratio
.
The kernel doc has the following explanations for both:
dirty_background_ratio
Contains, as a percentage of total available memory that contains free pages and reclaimable pages, the number of pages at which the background kernel flusher threads will start writing out dirty data.
and
dirty_ratio
Contains, as a percentage of total available memory that contains free pages and reclaimable pages, the number of pages at which a process which is generating disk writes will itself start writing out dirty data.
On my linux system dirty_background_ratio
is 10 and dirty_ratio
is 20. I understand that the difference is, who the dirty data writes. So if my used memory reaches 10% the kernel starts writing back and 20% should never be reached.
My question now is: Has the higher value of dirty_background_ratio
and dirty_ratio
any meaning or is it just a matter of "what is the lower value and who has it"?
Dirty means that the data is stored in the Page Cache, but needs to be written to the underlying storage device first. The content of these dirty pages is periodically transferred (as well as with the system calls sync or fsync) to the underlying storage device.
dirty_writeback_centisecs: the sleep interval of the pdflush daemon, expressed in 100'ths of a second. The default is 500.
This file contains the documentation for the sysctl files in /proc/sys/vm and is valid for Linux kernel version 2.6. 29. The files in this directory can be used to tune the operation of the virtual memory (VM) subsystem of the Linux kernel and the writeout of dirty data to disk.
Has the higher value of dirty_background_ratio and dirty_ratio any meaning or is it just a matter of "what is the lower value and who has it"?
In simpler words:
vm.dirty_background_ratio is the percentage of system memory which when dirty, causes the system to start writing data to the disk.
vm.dirty_ratio is the percentage of system memory which when dirty, causes the process doing writes to block and write out dirty pages to the disk.
These tunable depend on what your system is running; if you run a large database it's recommended to keep these values low, to avoid I/O bottlenecks when the system load increases.
e.g.:
vm.dirty_background_ratio=10 vm.dirty_ratio=15
In this example, when the dirty pages exceed vm.dirty_background_ratio=10
I/O starts, i.e they start getting flushed / written to the disk. When the total number of dirty pages exceed vm.dirty_ratio=15
all writes get blocked until some of the dirty pages get written to disk. You can think of the vm.dirty_ratio=15
as the upper limit.
I have been intrigued by this very question and so experimented a bit on my Debian 7.10 system running Linux 3.2.0-4-amd64 using sysbench 0.4.12, modifying:
These settings are a way to delay writing to disk. They are useful as long as you have applications that write infrequently or in small chunks (e.g. web browser). If there is only one application on the system that is just generating data at a rate greater than the maximum supported by the disk then no settings matter. The writing will take as much time as it has to.
Dirty Ratio (DR) results in the process that caused the number of dirty pages to cross the threshold to block. Dirty Background Ratio (DBR) controls writing dirty pages in the background. So, if you have a low DBR, higher DR and all of your processes write in small chunks never in total crossing the supported write speed of the disk (e.g. 50 MB/s) then you will find a system that is pretty responsive. This is impressive when we bear in mind the fact that writing to RAM is usually 100 times faster (5 GB/s)! This is the importance of DBR.
Configuration parameters are useful when you are bothered about applications that write infrequently. You don't want a process writing a byte or reading a few KB to stall for 20 seconds because there is too much dirty data. This is the importance of not having a too high DR. It also ensures that some memory is available to cache recently used data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With