Filesystem optimisations for SSDs (Btrfs)

12th November 2012 (12 years ago)

Btrfs is a great filesystem for SSDs as it can increase read/write speeds and save space with compression. These are the mount options I use with Btrfs:

  • sdd - Built in optimisations for SSDs
  • discard - Enables discard/TRIM on freed blocks
  • compress=lzo - Fastest compression and improves performance
  • noatime - Not specific to Btrfs but stops writing accress times to files

I use this for the / (root) and /home partitions so my /etc/fstab looks a bit like this:

UUID=00000000-0000-0000-0000-000000000000  /  btrfs  defaults,ssd,discard,compress=lzo,noatime,subvol=@  0  1
UUID=00000000-0000-0000-0000-000000000001 /boot  ext2  defaults  0  2
UUID=00000000-0000-0000-0000-000000000002 /home  btrfs  defaults,ssd,discard,compress=lzo,noatime,subvol=@home  0  2

When you've enabled this, you'll want to compress the files that already exist on the filesystem. The defragment and rebalace commands apparently will do this but I am unsure whether this is correct as these oparations complete instantly.

btrfs fi defragment /
btrfs fi balance /

It's also good to have the /tmp directory mounted as tmpfs. This will mean the temporary files will be kept in RAM rather than being written to disk. Add this line to /etc/fstab

tmpfs  /tmp  tmpfs  defaults  0  0

Read more about Btrfs mount options on the Btrfs Wiki and their benchmarks on Phoronix.