最後更新: 2022-02-21
目錄
- 找出系上的 SSD
- 為 SSD 設定 IO Scheduler
- TRIM Command
- 定期 trim (fstrim)
- FS: btrfs, ext4 的 trim (Continuous TRIM)
- Speed Test on Sata Port
- Window 's tuning
- M.2 NVMe PCIe SSD
- Window 7 install on SSD
- Linux Check SSD SMART Script
- Low-level Format
- Hardware
- Notes
找出系上的 SSD
# To check if the kernel knows about SSDs try:
grep . /sys/block/sd?/queue/rotational
/sys/block/sda/queue/rotational:1
/sys/block/sdb/queue/rotational:0
/sys/block/sdc/queue/rotational:1
為 SSD 設定 IO scheduler
查看 scheduler 設定
grep . /sys/block/sd?/queue/scheduler
/sys/block/sda/queue/scheduler:noop [deadline] cfq /sys/block/sdb/queue/scheduler:noop [deadline] cfq /sys/block/sdc/queue/scheduler:noop deadline [cfq]
Set deadline scheduler for non-rotating disks
[方法1]
/etc/udev/rules.d/10-ssd.rules
# Kernel Verion: 3 ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="deadline" # Kernel Version: 4, 5 ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="mq-deadline"
[方法2]
echo "block/sdX/queue/scheduler = deadline" >> /etc/sysfs.conf
systemctl restart sysfsutils
Checking
cat /sys/block/sdc/queue/scheduler
TRIM Command
The TRIM command should be translated from one layer to another until reaching the SSD.
i.e.
ext4 -> lvm -> ssd
* 每一層都要 support TRIM
定期 trim (fstrim)
日子久了 => degradation of write operations on SSDs
原因: 刪除了的資料沒有真正進行資料清空(erase)
系統支援 erase
OS >= Windows 7
Linux: util-linux package provides fstrim
fstrim - discard unused blocks on a mounted filesystem
Usage
# By default, fstrim will discard all unused blocks in the filesystem.
fstrim [-o offset] [-l length] [-m minimum-free-extent] [-v] mountpoint
Opts
-m, --minimum minimum-free-extent # Minimum contiguous free range to discard (Default value is zero => ALL )
# (Free ranges smaller than this will be ignored.)
-v, --verbose # Output the number of bytes passed from the filesystem down the block stack
# to the device for potential discard.
Unit
(2^N) suffixes KiB, MiB, GiB
i.e.
fstrim -v /ssd/xpenology
/ssd/xpenology: 6.4 GiB (6856876032 bytes) trimmed
Ubuntu
From 18.04 fstrim (discard unused blocks) is enabled to run weekly
by default for all mounted filesystems on devices that support the discard operation.
systemctl cat fstrim.timer
... [Timer] OnCalendar=weekly ...
systemctl cat fstrim.service
[Service] Type=oneshot ExecStart=/sbin/fstrim --listed-in /etc/fstab:/proc/self/mountinfo --verbose --quiet-unsupported
Info
- journalctl -u fstrim.service
- journalctl -u fstrim.timer
FS: btrfs, ext4 的 trim (Continuous TRIM)
/etc/fstab
# ext4
# commit=nrsec ( Default value is 5 seconds)
# This means that if you lose your power, you will lose as much as the latest 5 seconds of work
/dev/mapper/goofy-root / ext4 discard,noatime,commit=600,errors=remount-ro 0 1
Using the discard mount option for continuous TRIM in device operations
# btrfs
# ssd => optimizations for SSD drives
/dev/mapper/goofy-chroot /srv/chroot btrfs ssd,discard,noatime 0 2
* There is no need for the discard flag if you run fstrim periodically.
Speed Test on Sata Port
理論值:
SATA Express 16Gb/s 1600MB/s SATA 3.0 6Gb/s 600MB/s SATA 2.0 3Gb/s 300MB/s SATA 1.0 1.5Gb/s 150MB/s
SATA 3.0 有 revision 3.1~3.5(Released in July 2020)
Checking Sata Port Version
Speed Test on Sata 2.0 Port
Speed Test on Sata 3.0 Port
1. Seq
速度會接近 Sata Port 的理論值
- SATA3 : 520 MB/S
- Native SATA3 : 380 MB/S
- SATA2 : 270 MB/S
- SATA1 : 130 MB/S
2. 4K
6 個速度中最低者
3. 4K-64Thrd
4k, 64隊列深度
軟件會生成64個16MB大小的測試文件(共計1GB)
然後同時以4KB的單位尺寸同時在這64個文件中進行讀取
Window 's tuning
* 關閉 Superfetch 服務
win10: sc stop SysMain & sc config SysMain start= disabled
* 關閉 Windows Search 服務
* 關閉 contents index
right click on SSD Drive
Click "Properties" then uncheck “Allow files on this drive to have contents indexed in addition to file properties“.
* 關閉休眠(hibernate)功能
powercfg -h off
* Disable 碎片整理
* Turn Off the Page File on SSD Disk
* Verify TRIM is Functioning:
fsutil behavior query DisableDeleteNotify
# “1” => TRIM is disabled and you need to enable it.
NTFS DisableDeleteNotify = 0 (Disabled)
M.2 NVMe PCIe SSD
/dev/nvmeXnYpZ
linux 認唔到 M.2 NVMe PCIe SSD 時 => uefi boot -> legacy boot
Window 7 install on SSD
BIOS設置
啟用 SATA AHCI 糢式
Intel Driver
- iaStorA 驅動程式模組是 Intel SATA AHCI Driver
- iaStorAC 驅動程式模組是 Intel SATA AHCI RAID Driver
- iaStorAVC
Speed: intelide(有開啟AHCI模式) < msahci < iastora ...
Linux Check SSD SMART Script
chkssd.sh
#!/bin/bash opt="-e Reallocated_Sector_Ct \ -e Program_Fail_Cnt_Total \ -e Erase_Fail_Count_Total \ -e Uncorrectable_Error_Cnt \ -e Total_LBAs_Written \ -e Wear_Leveling_Count" chkdsk() { echo "Checking $1" smartctl -d sat -A /dev/$1 | grep $opt } chkdsk sdc
Low-level Format
1) If the drive shows "frozen" you must first "un-freeze" it
[方案1]
cat /sys/power/state
freeze mem
echo -n mem > /sys/power/state
After letting the computer sleep for a few seconds,
wake it up and check to see if the drive is no longer in frozen state by issuing the command
原因:
Your BIOS freezes the disk when booting,
that's why suspend/resume helps because it power cycles the drive without the BIOS getting its hands on it again.
BIOS 係有掌管的: Dell 1420 NB: BIOS > Security > Internal HDD PW
[方案2]
Hotplug SSD to Hotplug SATA Port
2) set a temporary password "p" in order to issue the secure erase command:
Hardware
Samsung 860 EVO HK$ 480@202010
Kingston 480GB A400 Series 2.5" SATA 3 6Gb/s SSD SA400S37/480G HK$ 435@202001
Kingston 480GB UV500 2.5" SATA 3 6Gb/s SSD SUV500/480G HK$ 490@202001
Kingston A400, UV500 的分別
A400 (TLC)[ 3 年保固]
- 讀取速度高達500MB/秒,寫入速度320M/秒
UV500 (TLC) [ 5 年保固]
- 採用Marvell 88SS1074 控制器 及 3D Nand
- 其讀寫速度最高可達 520MB/s 和 500MB/s
- 支持256位 AES硬件加密(SED)和 TCG Opal 2.0 安全管理解決方案
2015 HW
Samsung SSD 850 EVO 250GB
Cache Memory
Samsung SSD 850 EVO 250GB: Samsung 512 MB Low Power DDR3 SDRAM
Total/Terrabytes Bytes Written (TBW)
Samsung SSD 850 EVO 250GB: 75 TBW
計算程式
V = SMART attribute #241 (Total_LBAs_Written)
V X 512 / 1024^4 = N TB
Wear_Leveling_Count (ID 177)
This attribute represents the number of media program and erase operations
(the number of times a block has been erased)
This value is directly related to the lifetime of the SSD
The raw value of this attribute shows the total count of P/E Cycles
- SLC: 100,000
- MLC: 3,000
* The ssd will die from other reasons before wearing out.
POR_Recovery_Count
A count of the number of sudden power off cases.
the firmware must recover all of the mapping and user data during the next power on
Notes
如果平日工作有大量寫入 (40-50 GB per day), 唔建議用 TLC / QLC NAND