Saturday, December 22, 2012

SSD optimisation part 2: Large commit interval (Ext4)

"Ext4 can be told to sync all its data and metadata every 'nrsec' seconds. The default value is 5 seconds. This means that if you lose your power, you will lose as much as the latest 5 seconds of work (your filesystem will not be damaged though, thanks to the journaling).  This default value (or any low value) will hurt performance, but it's good for data-safety. Setting it to 0 will have the same effect as leaving it at the default (5 seconds). Setting it to very large values will improve performance."
- Ext4 documentation
Let's look at a simplified example:

A file at 2MB in size is created, used in one minute and then deleted (a photo in an online photo editor put in the browser cache perhaps?). In the one minute it is changed two times. That would be a maximum of 6MB written to the SSD, if for simplicity's sake we assume the whole file is changed. With the default commit interval at 5 seconds all 6MB would be written to disk with 3 writes @ 2MB. With an interval at, for example 2 minutes, nothing will be written at all as everything stays in cache. That is 3 writes / 6MB Vs. 0 writes / 0MB. Of course this imply that the file is not implicitly saved by the application or some other operation that calls fsync, but I did write "simplified example"..

If your system crashes with a commit at 600 (I.E. 10 minutes) you might loose all the changes you have made in the last 10 minutes. Most of the time this wont happen though as software can still call fsync() and get its data written to disk, overriding the commit setting. You could look at it as "write everything to disk at least this often".

Less commits to disk equals less writes and better performance.

My recommendation
The default (5) is a good all around value. If you never have crashes or power-outs, you could go as high as you feel like (years even, but you better not use software that does not call fsync then). If you really want me to throw a number out there, how about 200 seconds, like so:

This post was written for the Linux Mint forum. Please ask any questions there (: