Stage 3 · Build
Storage Reliability & Performance
Discard, TRIM & Wear
fstrim timers, discard mount options, SSD endurance, and write amplification.
TRIM/Discard Overview
TRIM (SATA) and Deallocate (NVMe) tell the SSD which blocks are no longer in use. SSDs cannot overwrite directly — they must erase before writing. TRIM allows the SSD to erase blocks in the background, maintaining write performance over time.
# Check if TRIM is supported
sudo hdparm -I /dev/sda | grep TRIM
# * Data Set Management TRIM supported
# Check if discard is enabled on mount
mount | grep " / "
# /dev/sda1 on / type ext4 (rw,relatime,discard)
# Check NVMe TRIM support
sudo nvme id-ctrl /dev/nvme0 | grep dsm
# vwc : 0 (dataset management supported)
# Manual TRIM
sudo fstrim -v /
# /: 123456789123 bytes trimmedTRIM is essential for SSD performance. Without it, SSDs slow down as they run out of pre-erased blocks.
Discard Mount Options
| Option | Behavior | Best For |
|---|---|---|
| discard | TRIM on every delete | Low-write workloads |
| nodiscard | No automatic TRIM | High-write workloads, HDD |
| batch_discard | Batch TRIM operations | General purpose |
# Enable discard in fstab
# /dev/sda1 / ext4 defaults,discard 0 1
# /dev/nvme0n1p1 / ext4 defaults,discard 0 1
# Apply without reboot
sudo mount -o remount,discard /
# For XFS
# /dev/sda1 /data xfs defaults,discard 0 2
# Remove discard if causing latency
sudo mount -o remount,nodiscard /The discard mount option TRIMs blocks on file deletion. This adds latency to delete operations but keeps the SSD healthy.
fstrim Scheduler
# Manual TRIM
sudo fstrim -v /
# /: 456789012345 bytes trimmed in 2.34 seconds
# Trim all mounted filesystems
sudo fstrim -av
# Enable fstrim timer (weekly by default)
sudo systemctl enable --now fstrim.timer
sudo systemctl status fstrim.timer
# Active: active (waiting) since ...
# Check timer schedule
systemctl cat fstrim.timer
# [Timer]
# OnCalendar=weekly
# Persistent=true
# Check last run
sudo journalctl -u fstrimfstrim weekly is the recommended approach for most systems. It batches TRIM operations for efficiency without per-delete overhead.
SSD Endurance
SSDs have a limited number of write cycles (measured in TBW — Terabytes Written). Endurance depends on the NAND type: SLC > MLC > TLC > QLC. Workloads with heavy writes consume SSD lifespan faster.
# SMART wear indicator
sudo smartctl -a /dev/sda | grep -E "Wear|Written|Percentage"
# 233 Wear_Leveling_Count 0x0033 067 067 000 Old_age Always
# Percentage Used: 33%
# Total_LBAs_Written: 123456789012
# NVMe SMART
sudo nvme smart-log /dev/nvme0
# Percentage Used: 15%
# Data Units Written: 98765432123
# Calculate TBW
# Total_LBAs_Written * 512 / (1024^4) = TB writtenWhen Percentage Used reaches 100%, the warranty expires. Monitor this regularly and plan replacement before failure.
Write Amplification
Write amplification occurs when the SSD writes more data than the host requested. This happens due to garbage collection, wear leveling, and partial block updates. Lower write amplification means longer SSD life.
# Enable TRIM to reduce garbage collection overhead
sudo fstrim -v /
# Use over-provisioning (leave 10-20% free space)
# Don't fill SSDs beyond 80% capacity
# Check free space
df -h /dev/sda1
# Filesystem Size Used Avail Use% Mounted on
# /dev/sda1 477G 350G 103G 78% /
# For write-heavy workloads, consider SLC or MLC SSDs
# TLC and QLC have higher write amplificationWrite amplification of 2x means the SSD writes 2 bytes for every 1 byte the host requested. TRIM and over-provisioning reduce write amplification.
Monitoring SSD Health
# Full SMART report
sudo smartctl -a /dev/sda
# Quick health check
sudo smartctl -H /dev/sda
# SMART overall-health self-assessment test result: PASSED
# NVMe health
sudo nvme smart-log /dev/nvme0
# temperature, spare, percentage used, data units read/written
# Automated monitoring
sudo smartctl -a /dev/sda | grep -E "Percentage|Wear|Error"Monitor SSD health monthly. Watch for increasing error counts, temperature spikes, and wear level approaching 100%.
The fstrim.timer provides weekly TRIM without per-delete overhead. Enable it on all SSD-backed systems with sudo systemctl enable fstrim.timer.
The discard mount option adds latency to file deletions. For latency-sensitive workloads, use fstrim instead of the discard mount option.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.