Linux Disk Caching & Performance – with vm.dirty_ratio & vm.dirty_background_ratio

root@rpi-iot-jsho-2FA-02:~# sysctl -a | grep dirty
vm.dirty_background_bytes = 0
vm.dirty_background_ratio = 10
vm.dirty_bytes = 0
vm.dirty_expire_centisecs = 3000
vm.dirty_ratio = 20
vm.dirty_writeback_centisecs = 500
vm.dirtytime_expire_seconds = 43200
root@rpi-iot-jsho-2FA-02:~# sysctl vm.dirty_ratio=50

vm.dirty_background_ratio – is the percentage of system memory that can be filled with “dirty” pages — memory pages that still need to be written to disk — before the pdflush/flush/kdmflush background processes kick in to write it to disk. My example is 10%, so if my virtual server has 32 GB of memory that’s 3.2 GB of data that can be sitting in RAM before something is done

vm.dirty_ratio – is the absolute maximum amount of system memory that can be filled with dirty pages before everything must get committed to disk. When the system gets to this point all new I/O blocks until dirty pages have been written to disk. This is often the source of long I/O pauses, but is a safeguard against too much data being cached unsafely in memory

vm.dirty_expire_centisecs – is how long something can be in cache before it needs to be written. In this case it’s 30 seconds. When the pdflush/flush/kdmflush processes kick in they will check to see how old a dirty page is, and if it’s older than this value it’ll be written asynchronously to disk. Since holding a dirty page in memory is unsafe this is also a safeguard against data loss

vm.dirty_writeback_centisecs – is how often the pdflush/flush/kdmflush processes wake up and check to see if work needs to be done

Leave a Reply

You must be logged in to post a comment.