happyMOOyear happyMOOyear - 5 months ago 69
Linux Question

Difference between vm.dirty_ratio and vm.dirty_background_ratio?

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"?

Answer

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 more simpler words:

vm.dirty_background_ratio is the percentage of system memory which when dirty then system can start writing data to the disks.

vm.dirty_ratio is percentage of system memory which when dirty, the process doing writes would block and write out dirty pages to the disks.

This tunable depends on what your system running, if you run large database its recommend to keep these values low to avoid I/O bottle-necks and when the system load increases.

ex:

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 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=10 as the upper limit.

Comments