dirty 参数查看
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
参数详解
vm.dirty_backgroud_ratio = 10
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.
假定 server 有 32G 物理内存,在不做任何处理的情况下,有 3.2G 的数据可以在内存。超过这个值后,要 flush 到磁盘(write back)。
vm.dirty_ratio = 20
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.
假定 server 有 32G 物理内存,那么最多有 32 * 20% = 6.4G 物理内存作为 dirty page。 注意:当磁盘缓存达到了这个比例,将会阻塞所有新的 I/O 操作,直到 dirty page 写入了磁盘。面试常问的 redis 命令执行慢,这也是可能的原因之一。
_bytes 类参数
vm.dirty_background_bytes and vm.dirty_bytes are another way to specify these parameters. If you set the _bytes version the _ratio version will become 0, and vice-versa.
和 _ratio 类参数是互斥的。
vm.dirty_expire_centisecs = 3000
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.
centisecs 厘秒(百分之一秒)。dirty page 能在内存里待的时间,超出这个时间,必须写入到磁盘。因为 dirty page 一直在内存中是有丢失风险的。可以将这个时间调小,来降低数据丢失的风险。
vm.dirty_writeback_centisecs = 500
vm.dirty_writeback_centisecs is how often the pdflush/flush/kdmflush processes wake up and check to see if work needs to be done.
内核有将内存数据刷入磁盘的 flusher 线程。那么刷新频率是多少呢?用这个参数来控制。也就是多长时间来刷一次盘。默认 5s。