I am using powertop
to check that my machine is setup in a way that will give me good battery life. After installing laptop-mode-tools
all of the "Tunables" section shows "Good" except VM writeback timeout. On the powertop
page, it seems to suggest that 1500 (i.e. 15 seconds) is a good value. Checking cat /proc/sys/vm/dirty_writeback_centisecs
shows that my current value is 60000 (i.e. 600 seconds or 10 minutes). I believe a larger value means to wait longer between writes (which means spinning up the drive less frequently). Do I really need to set the timeout longer than ten minutes?
4 Answers
The larger the dirty writeback setting the longer dirty pages sit in memory before being flushed out to disk. The downside is that this increases the window of opportunity for losing data if you lose power since there will be probably more dirty pages sitting in memory and not flushed out.
Actually you don't need to set dirty_writeback timeout to more than 6000 centisec, but rather to less. At least for Powertop to smile: It seems Powertop checks for vm.dirty_writeback = an *exact* value of 1500 csec (15 sec)
. You can check by setting it to this value and look back at the powertop screen.
Other than that, @Colin Ian King said it clear on the data loss widening window with higher timeouts.
-
Thank you @Catskul for being more specific than I had it. It's appreciated :)– tuk0zJan 1, 2019 at 10:03
I believe a larger value means to wait longer between writes (which means spinning up the drive less frequently)
No, you're just delaying write operations to the disk by 10 minutes. This doesn't buy you anything in terms of battery life or reducing SSD writes.
The way to think about this value is: "What's the longest ever possible time (times 2, even) that I would ever want a batch of disk operations to last."
If you have an application that actually takes 10 minutes (an absurdly high value for normal users) of disk writes that would benefit of being delayed in I/O, eg. multiple writes to the same file get made into one write, then you would set the timeout to a very high value.
tldr; For 99.9% of users, the powertop suggested default is more than enough.
If you actually want to reduce writes to SSD, think about putting parts of your filesystem on tmpfs. But that's a whole other subject.
I just want to add something to this in case anyone happens upon it. Even though this is a bit older we should never really have to touch this setting regardless of what powertop says. The kernel automatically makes adjustments for best performance on this since kernel version 3.5 with a feature called Dynamic Writeback Throttling. It allows the kernel to automatically adjust the vm.dirty_writeback_centisecs setting based on the system's available memory and the type of storage device in use. With this feature enabled, the kernel will try to maintain a balance between minimizing the amount of dirty data in memory and minimizing the number of writes to the storage device.
/etc/laptop-mode/laptop-mode.conf
(LM_BATT_MAX_LOST_WORK_SECONDS
). Personally i think 10 minutes is too much (i use 20 seconds).vm.dirty_writeback_centisecs=1500
in/etc/sysctl.d/99-vm-writeback.conf
and reboot or dosudo service procps start