众所周知SSD的读写速度远比hdd磁盘要快,理解ssd的工作原理使我们开发处高效储存方案。
linux 相关指令
fstrim --fstab --verbose ## 回收(discard)文件系统上对应磁盘未使用的块
blkdiscard /dev/nvme1n1 ## 回收并擦除(discard)整个SSD块设备
wipefs -a /dev/nvme1n1 ## 擦除(erase)文件系统的签名
fstrim
fstrim命令实际可以视为手动对SSD磁盘下发TRIM指令。使用-v参数可以直接查看TRIM回收擦除空间的大小。fstrim是针对已挂载的文件系统的SSD分区
root@xxxx:~# fstrim --help
Usage:
fstrim [options] <mount point>
Discard unused blocks on a mounted filesystem.
Options:
-a, --all trim all supported mounted filesystems
-A, --fstab trim all supported mounted filesystems from /etc/fstab
-o, --offset <num> the offset in bytes to start discarding from
-l, --length <num> the number of bytes to discard
-m, --minimum <num> the minimum extent length to discard
-v, --verbose print number of discarded bytes
-n, --dry-run does everything, but trim
-h, --help display this help
-V, --version display version
For more details see fstrim(8).
以下是执行后返回的结果,以NVMe 为列
/home: 32.5 GiB (313011310592 bytes) trimmed on /dev/mapper/gat204--vg-root
/boot/efi: 102.2 MiB (607301632 bytes) trimmed on /dev/nvme1n1p1
/boot: 732.5 MiB (825778176 bytes) trimmed on /dev/nvme1n1p2
/: 60.7 GiB (65154805760 bytes) trimmed on /dev/mapper/gat204--vg-swap_1
ubuntu与debian的systemd 服务可以定时执行fstrim,省去手写crontab脚本工作。
systemctl status fstrim.timer ##查询服务状态
systemctl enable fstrim.timer ##开启定时TRIM功能
blkdiscard
blkdiscard用于擦除(discard)SSD设备扇区,和fstrim不同这条命令直接用在块设备上,默认擦除整个块设备的所有扇区。
root@xxxx:~# blkdiscard -help
Usage:
blkdiscard [options] <device>
Discard the content of sectors on a device.
Options:
-o, --offset <