SSDs (solid-state drives) and SD cards have finite write cycles, influencing their lifespan. This article provides updated methods to optimize their performance and extend their durability. This is an updated version of an article from seven years ago.
TRIM Optimization
The most effective method to maintain SSD performance is through TRIM, which allows the operating system to inform the SSD which data blocks are no longer in use.
Step 1: Check if your SSD or SD card supports TRIM.
sudo hdparm -I /dev/sdx | grep "TRIM supported"
Step 2: Verify TRIM is enabled.
sudo systemctl status fstrim.timer
Step 3: Enable TRIM using systemctl
if it’s not already enabled.
sudo systemctl enable fstrim.timer
sudo systemctl start fstrim.timer
Using iotop
to Monitor and Minimize Reads/Writes
Use iotop
to identify processes causing excessive disk I/O. This helps in pinpointing areas for optimization.
Step 1: Install iotop
using your distribution’s package manager.
Step 2: Run iotop
with the following options to monitor disk I/O usage.
iotop -oPa
Step 3: Analyze the output to identify processes with high disk I/O.
You should look for processes that unnecessarily consume disk I/O. The following tips help to minimize disk overhead.
noatime
Mount Flag
Utilize the noatime
mount option to prevent logging of file access times, reducing unnecessary writes.
Step 1: Edit /etc/fstab
file.
Step 2: Add the noatime
flag to your mount options.
/dev/sdx / ext4 noatime,errors=remount-ro 0 1
Mount Temporary Directories as tmpfs
Mounting temporary directories as tmpfs
stores them in RAM, reducing writes to the SSD.
Step 1: Edit /etc/fstab
.
Step 2: Add the following lines to mount /tmp
and /var/tmp
as tmpfs
.
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
Note: Modern Linux distributions often mount /tmp
as tmpfs
by default.
Avoid Heavy Use of Swap Space
Limiting swap usage minimizes writes to the SSD or SD card.
Step 1: Edit /etc/sysctl.conf
(or equivalent configuration file).
Step 2: Add or modify the vm.swappiness
value.
To reduce swap usage:
vm.swappiness=1
To disable swap (use with caution):
vm.swappiness=0
Note: Consider using zram or zswap for memory-based swap.
Reduce Logging Writes
Reducing logging activity can decrease unnecessary writes.
Step 1: Disable or reduce the verbosity of access logs for services like Apache and Nginx.
Step 2: Adjust system log levels from info
to warn
or error
.
Step 3: Move logs to tmpfs
by editing /etc/fstab
.
tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0
Step 4: Configure journalctl
settings in /etc/systemd/journald.conf
.
Storage=
SystemMaxUse=
SystemKeepFree=
SystemMaxFileSize=
RuntimeMaxUse=
RuntimeKeepFree=
RuntimeMaxFileSize=
MaxLevelStore=
Refer to the descriptions and size format for configuration.
Mount Additional Directories with Heavy I/O to tmpfs
Identify directories with frequent I/O operations and mount them as tmpfs
.
Step 1: Identify the directory.
Step 2: Add an entry to /etc/fstab
.
tmpfs /full/path/to/busy/io/dir/ tmpfs defaults, size=1G 0 0
I/O Scheduler
Modern kernels automatically manage I/O scheduling, making manual adjustments unnecessary in most cases.
To check the currently active I/O scheduler:
cat /sys/block/sdX/queue/scheduler
Older systems may benefit from switching to noop
or deadline
schedulers via kernel parameters.
FAT32/ExFAT for SD Cards
SD cards typically use FAT32 or ExFAT, which do not support TRIM or journaling. Consider using cards with higher endurance or using a Linux-compatible filesystem like ext4 if possible.
Filesystems
Modern filesystems like Btrfs and ext4 are suitable for SSDs. Consider features like compression and snapshots in Btrfs, but understand their impact on write activity.
NVMe Drives
Ensure your system leverages NVMe SSDs by verifying correct setup and enabling fstrim.timer
.
Further Increasing Performance/Life of SSDs & SD Cards
- Use larger SD cards, as writes are distributed across the storage.
- Invest in quality SSDs and SD cards for better performance and longevity.
To check for issues and lifespan:
sudo smartctl -a /dev/sdxx
For NVMe drives:
sudo nvme smart-log /dev/nvmeX
By implementing these strategies, you can effectively enhance the performance and extend the lifespan of your SSDs and SD cards.