Skip to content

Instantly share code, notes, and snippets.

@rayhassan
Created November 14, 2017 11:05
Show Gist options
  • Save rayhassan/1794ea472050a4bcf1ef2d8803d0d3d8 to your computer and use it in GitHub Desktop.
Save rayhassan/1794ea472050a4bcf1ef2d8803d0d3d8 to your computer and use it in GitHub Desktop.
TRIM/fstrim notes
The TRIM command enables an operating system to notify the SSD of pages which no longer contain valid data. For a file deletion operation, the operating system will mark the files sectors as free for new data, then send a TRIM command to the SSD. After trimming, the SSD will not preserve any contents of the block when writing new data to a page of flash memory, resulting in less write amplification (fewer writes), higher write throughput (no need for a read-erase-modify sequence), thus increasing drive life.
Different SSDs implement the command somewhat differently, so performance can vary.[3][8]
Trim tells the SSD to mark a LBA region as invalid and subsequent reads on the region will not return any meaningful data. However, the data could still reside on the flash internally.
are my disks TRIM enabled
lsblk -o MOUNTPOINT,DISC-MAX,FSTYPE
MOUNTPOINT DISC-MAX FSTYPE
16M
/boot 16M xfs
16M LVM2_member
/ 16M xfs
[SWAP] 16M swap
/disks/sdb 16M ext4
/disks/sdc 16M ext4
/disks/sdd 16M ext4
/disks/sde 16M ext4
/disks/sdf 16M ext4
/disks/sdg 16M ext4
/disks/sdh 16M ext4
/disks/sdi 16M ext4
/disks/sdj 16M ext4
/disks/sdk 16M ext4
/disks/sdl 16M ext4
/disks/sdm 16M ext4
[root@dn10 system]# for i in [a-z] ; do lsblk -D /dev/sd$i; done
NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda 0 512B 16M 0
+-sda1 0 512B 16M 0
+-sda2 0 512B 16M 0
+-cl-root 0 512B 16M 0
+-cl-swap 0 512B 16M 0
sdb 0 512B 16M 0
sdc 0 512B 16M 0
sdd 0 512B 16M 0
sde 0 512B 16M 0
sdf 0 512B 16M 0
sdg 0 512B 16M 0
sdh 0 512B 16M 0
sdi 0 512B 16M 0
sdj 0 512B 16M 0
sdk 0 512B 16M 0
sdl 0 512B 16M 0
sdm 0 512B 16M 0
check the values of DISC-GRAN and DISC-MAX columns. Non-zero values indicate TRIM support.
enabling on centos7 via systemd
[root@dn10 system]# more fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true
[Install]
WantedBy=multi-user.target
[root@dn10 system]# more fstrim.service
[Unit]
Description=Discard unused blocks
[Service]
Type=oneshot
ExecStart=/usr/sbin/fstrim -a
systemctl enable fstrim.timer
systemctl start fstrim.timer
by hand on the cli
[root@dn10 system]# /usr/sbin/fstrim -av
/boot: 861.4 MiB (903200768 bytes) trimmed
/disks/sdk: 84.3 GiB (90486259712 bytes) trimmed
/disks/sdi: 82.9 GiB (88970567680 bytes) trimmed
/disks/sdm: 85.3 GiB (91569057792 bytes) trimmed
/disks/sdf: 83.5 GiB (89609076736 bytes) trimmed
/disks/sdl: 84.9 GiB (91091161088 bytes) trimmed
/disks/sde: 25.1 GiB (26988478464 bytes) trimmed
/disks/sdc: 25.3 GiB (27198820352 bytes) trimmed
/disks/sdh: 83.1 GiB (89224007680 bytes) trimmed
/disks/sdj: 84.7 GiB (90879746048 bytes) trimmed
/disks/sdg: 85.9 GiB (92172173312 bytes) trimmed
/disks/sdd: 25.5 GiB (27388055552 bytes) trimmed
/disks/sdb: 25.5 GiB (27326164992 bytes) trimmed
/: 29.3 GiB (31431467008 bytes) trimmed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment