#!/usr/bin/env bash # Do not use in production, or on hard drives. This is only for consumer SSDs in a home lab. # I recommend running these commands one-by-one once you understand what they do. Do not run a command you don't understand or you may experience catastrophic data loss. # These changes are recommended for reducing writes on consumer SSDs: https://serverfault.com/questions/950794/how-to-limit-zfs-writes-on-nvme-ssd-in-raid1-to-avoid-rapid-disk-wear/950896#950896 # This may cause data loss and increase other resource usage (like CPU, etc). # This script assumes your zfs pool is rpool, you may need to change that name when running these commands. echo "Enabling a variety of settings to reduce writes on SSDs. This may cause data loss and increase the usage of other resources like CPU. DO NOT run this on a hard drive. Hit Ctrl + C to cancel." sleep 10 echo "starting changes" echo 'options zfs zfs_txg_timeout=30' > /etc/modprobe.d/zfs.conf # Set txg_timeout to 30 seconds. This introduces a higher risk of data loss because it syncs to disk every 30 seconds instead of 5 seconds. zfs set atime=off rpool # Turn off atime (updates to file time data that aren't as important) zfs set logbias=throughput rpool # Change logbias to throughput. Don't do this if you have a custom log device for your pool. If you later decide to do so, you'll need to change this setting back to latency zfs set compression=lz4 rpool # Set compression to lz4 instead of the older LZJB. zfs set recordsize=16K rpool # This works better with lots of little writes, and seems to be recommended for VMs on SSDs unless your workload is many large writes. If you do a lot of large writes, do not run this command, leave the recordsize as default. # ZFS seems to recommend smaller recordsizes for the VM ZFS pool if you're running on SSDs in general depending on the workload: # https://openzfs.github.io/openzfs-docs/Performance%20and%20Tuning/Workload%20Tuning.html#virtual-machines # https://openzfs.github.io/openzfs-docs/Performance%20and%20Tuning/Workload%20Tuning.html#zvol-volblocksize # 16K: https://serverfault.com/a/1120640 echo "This is the ashift value for your ZFS pools, this should be 12:" zpool get all | grep ashift echo "And this should tell you whether trim is enabled, it should be:" systemctl status fstrim.timer