linuxperformancelinux-kernel

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


Solution

  • 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.