14

I have done many obscure system optimizations in the past, but I got rid of most of them after powertop told me I should set my USB ports to autosuspend, which forced them to an eternal sleep, and also after I realized the benefits of a higher swappiness.

But today, while looking at /etc/fstab, I noticed I had set the option commit=60 for / and /home. I remember that this was an optimization for laptops, to reduce the amount of writes to the disk, thus saving battery. But then I became concerned that this might cause data loss (sometimes my battery gets disconnected, and then on boot fsck tells me about a couple of orphan inodes).

While searching for an explanation for this option, I came to the following explanations (the second seems to contradict my previous understanding):

$ man mount | awk '/commit=/,/^$/'
commit=nrsec
    Sync all data and metadata every nrsec seconds. The default value is 5 seconds.
    Zero means default.

https://forums.gentoo.org/viewtopic-p-4088752.html

commit=60 stops the "immediate" (default of 5 seconds) prioritization of writes of over reads, caching the writes for a few more seconds later. This is good in the situation of heavy reads and writes mixed together, where the user wants the reads to take priority, so that the processor can be kept busy rather than pause while waiting for the writes to finish before it can continue reading.

A real-world example I have seen is waiting several seconds for the Gnome pull-down menu to appear, for seemingly no reason. The reason was that the disk was busy writing, so the CPU had to wait for the writing to finish before it could get all the data from the disk to be able to show the menu.

What does commit really do? Are there really advantages of increasing it (like responsiveness and power savings)? May it actually cause data loss?

11
+50

What does commit really do?

I think one of the best explanations was given here by allquixotic.

Are there really advantages of increasing it (like responsiveness and power savings)? May it actually cause data loss?

As per the ext4 official documentation:

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.

Increasing commit value means you might lose as much as the latest N seconds of work (where N = commit interval) though most of the time this won't happen 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".1
On the other hand, it means less writes (which makes it quite popular among ssd users) and better performance (multiple writes are combined into one single larger write, updates to previous writes within the commit time frame are cancelled out).
As to the power savings, according to this page, it turns out that nowadays increasing commit value does not save power.

  • 1
    I think some power save happens due to that the extents + delayed allocation can much better optimize the HDD seeks. But it is probably not significant. – peterh Mar 4 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.