I want provide some insight on the implementation.
balance_dirty_pages() (Linux kernel 6.10) is the function that is called by a process to check whether any of the thresholds have been crossed or not.
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.
(Ref: Snippet from accepted answer)
From above explanation, we may think that a possible implementation can be as following:
balance_dirty_pages()
{
d = amount of dirty pages in available memory
if(d > vm.dirty_ratio)
{
start synchronous write
}
else if (d > vm.dirty_background_ratio)
{
trigger background writeback thread to run
}
return
}
However, implementation is sort of like this (at an algorithmic level):
balance_dirty_pages()
{
while(1)
{
d = amount of dirty pages in available memory
if(d > vm.dirty_ratio)
{
trigger background writeback thread to run
sleep(some time)
}
other stuff
}
return
}
i.e. the point I want to highlight is that writeback is performed by the background writeback thread irrespective of the threshold crossed.
In case of vm.dirty_background_ratio, process returns immediately after triggering background thread.
In case of vm.dirty_ratio, process sleeps for some time after triggering the writeback thread. After it wakes up, it again loops.
PS: This is my understanding of the code. More experienced people can pitch in and suggest corrections.