我无法在新安装的 SSD 上启用 TRIM。 Ubuntu 服务器 12.04、Linux 3.11.0-15-通用。我通过 /etc/fstab 中的丢弃设置打开 TRIM。 TRIM 也不能与 fstrim 命令一起使用。
以下是我检查 TRIM 是否有效的方法:
#for i in {1..100000}; do echo "1" >> tempfile; done
#sudo hdparm --fibmap tempfile
#sudo hdparm --read-sector 293865512 /dev/sda
#rm tempfile
#sync
#sudo hdparm --read-sector 293865512 /dev/sda
如果启用 TRIM,第二次运行 hdparm --read-sector 命令应返回零,但结果与第一次运行该命令相同。
fstrim 命令不起作用:
#sudo fstrim -v /
/: 0 bytes were trimmed
这是 hdparm -i /dev/sda 的结果:
Model=KINGSTON SV300S37A240G, FwRev=520ABBF0, SerialNo=50026B7243004D3E
Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs RotSpdTol>.5% }
RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=4
BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSect=1
CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=468862128
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes: pio0 pio1 pio2 pio3 pio4
DMA modes: mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6
AdvancedPM=yes: unknown setting WriteCache=disabled
Drive conforms to: unknown: ATA/ATAPI-2,3,4,5,6,7
这是 sudo hdparm -I /dev/sda 的结果:
/dev/sda:
ATA device, with non-removable media
Model Number: KINGSTON SV300S37A240G
Serial Number: 50026B7243004D3E
Firmware Revision: 520ABBF0
Transport: Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0
Standards:
Used: unknown (minor revision code 0x0110)
Supported: 8 7 6 5
Likely used: 8
Configuration:
Logical max current
cylinders 16383 16383
heads 16 16
sectors/track 63 63
--
CHS current addressable sectors: 16514064
LBA user addressable sectors: 268435455
LBA48 user addressable sectors: 468862128
Logical Sector size: 512 bytes
Physical Sector size: 512 bytes
Logical Sector-0 offset: 0 bytes
device size with M = 1024*1024: 228936 MBytes
device size with M = 1000*1000: 240057 MBytes (240 GB)
cache/buffer size = unknown
Nominal Media Rotation Rate: Solid State Device
Capabilities:
LBA, IORDY(can be disabled)
Queue depth: 32
Standby timer values: spec'd by Standard, with device specific minimum
R/W multiple sector transfer: Max = 16 Current = 1
Advanced power management level: 254
DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6
Cycle time: min=120ns recommended=120ns
PIO: pio0 pio1 pio2 pio3 pio4
Cycle time: no flow control=120ns IORDY flow control=120ns
Commands/features:
Enabled Supported:
* SMART feature set
Security Mode feature set
* Power Management feature set
Write cache
Look-ahead
* Host Protected Area feature set
* WRITE_BUFFER command
* READ_BUFFER command
* NOP cmd
* DOWNLOAD_MICROCODE
* Advanced Power Management feature set
Power-Up In Standby feature set
* SET_FEATURES required to spinup after power up
SET_MAX security extension
* 48-bit Address feature set
* Mandatory FLUSH_CACHE
* FLUSH_CACHE_EXT
* SMART error logging
* SMART self-test
* General Purpose Logging feature set
* WRITE_{DMA|MULTIPLE}_FUA_EXT
* 64-bit World wide name
* IDLE_IMMEDIATE with UNLOAD
Write-Read-Verify feature set
* {READ,WRITE}_DMA_EXT_GPL commands
* Segmented DOWNLOAD_MICROCODE
unknown 119[6]
* Gen1 signaling speed (1.5Gb/s)
* Gen2 signaling speed (3.0Gb/s)
* Gen3 signaling speed (6.0Gb/s)
* Native Command Queueing (NCQ)
* Phy event counters
* NCQ priority information
* unknown 76[15]
* DMA Setup Auto-Activate optimization
Device-initiated interface power management
* Software settings preservation
* SMART Command Transport (SCT) feature set
* SCT LBA Segment Access (AC2)
* SCT Data Tables (AC5)
* reserved 69[3]
* DOWNLOAD MICROCODE DMA command
* SET MAX SETPASSWORD/UNLOCK DMA commands
* WRITE BUFFER DMA command
* READ BUFFER DMA command
* Data Set Management TRIM supported (limit 1 block)
Security:
Master password revision code = 65534
supported
not enabled
not locked
not frozen
not expired: security count
supported: enhanced erase
4min for SECURITY ERASE UNIT. 2min for ENHANCED SECURITY ERASE UNIT.
Logical Unit WWN Device Identifier: 50026b7243004d3e
NAA : 5
IEEE OUI : 0026b7
Unique ID : 243004d3e
Checksum: correct
这是 dmesg | grep 丢弃:
[ 6.417350] EXT4-fs (sda1): re-mounted. Opts: discard,errors=remount-ro
[ 6.471628] EXT4-fs (sdb1): mounted filesystem with ordered data mode. Opts: discard
这是 cat /etc/mtab | grep 丢弃:
/dev/sda1 / ext4 rw,noatime,nodiratime,discard,errors=remount-ro 0 0
/dev/sdb1 /home/backup ext4 rw,noatime,nodiratime,discard 0 0
此外,我还成功在另外两台具有相同操作系统但不同 SSD 的计算机上通过丢弃启用了 TRIM。
答案1
我认为这里主要的误解是发出 TRIM 会导致块被擦除。实际上,TRIM 命令所做的就是通知 SSD 操作系统不再需要此位置的数据,之后发生的具体情况取决于固件 理想情况下,固件应使用此信息来:
当块的另一部分被重写时,避免复制和重写此数据。请记住,SSD 的擦除块大小(总是?)大于写入块大小,因此当必须重新写入特定块时,通常必须复制更大的区域,擦除并重新写入更大的区域。包含更新数据的区域。如果已针对该区域的一部分发出 TRIM,则不必复制或重写该部分。这样速度更快,并且可以防止不必要的写入,从而缩短设备的使用寿命。
执行其他磨损均衡优化。
这些都不需要立即删除数据。事实上,如果修剪区域小于擦除块的大小时不会发生这种情况,则可能对 SSD 的使用寿命更好。也就是说,SSD 在 TRIM 发出后立即擦除覆盖整个擦除块的区域可能是一个好的做法。
如果您以前使用上述方法取得过成功,则可能是所使用的 SSD 的擦除块大小较小。不幸的是,制造商很少公布这些数据,但仔细研究一下,512k 似乎并不是闻所未闻。如果您尝试读取和写入覆盖多个擦除块的更大区域并从该区域的中间而不是开始或结束处读取,则可能会成功,因为第一部分可能没有自己的擦除块。
但请注意,即使使用 16 MiB 连续块,我也得到与问题相同的结果。