nix-community / impermanence

Modules to help you handle persistent state on systems with ephemeral root storage [maintainer=@talyz]
MIT License
1.14k stars 85 forks source link

nixos: Prevent redundant fstrim #141

Closed alois31 closed 1 year ago

alois31 commented 1 year ago

The fstrim service, when enabled, by default trims all mounts listed in fstab (as long as the underlying device supports discard), including bind mounts. With impermanence, this can lead to a significant number of redundant trim operations, since the persistent volume is trimmed once for itself and then again once per persistent directory each. On my system, this leads to fstrim.service taking about 10 minutes, during which the system usability is somewhat degraded. In addition, it may be desired to disable trim for a certain filesystem entirely, for example when using btrfs with discard=async.

Mark our bind mounts with the X-fstrim.notrim option, which is ignored by mount, but instructs fstrim to skip the mount point in question. The persistent filesystem is still trimmed properly, since it has to be listed in fstab itself as well.