标签:
作者:张华 发表于:2016-03-23
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明
( http://blog.csdn.net/quqi99 )
普通硬盘并不真正从硬盘里删除数据,只是在操作系统标记为删除,下次直接覆盖写;但SSD物理覆盖写却是很慢的(对于SSD,可以以4KB大小的页(128个page组成一个block)来读写数据,但却只能以512KB(128 page)大小来删除。要覆盖写一个4KB page的话,先要把512KB block全部复制到缓存里,然后删除这4kb page并替换成新的写数据,接下来清空SSD的这512KB block区域,并从缓存里把新的数据写回去)。所以当SSD的所有空闲块都被使用后,再有写的操作只能覆盖写到之前被操作系统标记为删除的区域,这也是速度下降的开始。特别是一系列小文件随机写入同时覆盖写很多的块,那样缓存一下子会快速过载而变得非常慢,所以SSD厂商都在新主控制器上加入了越来越大的外置缓存,这虽然可以一定程序上解决随机写入卡的问题,但是却不能解决SSD在覆盖写时速度下降的问题。如果操作系统在删除一个4KB page的时候不仅在操作系统记录里删除也控制SSD主控物理删除它的话,这就是TRIM干的事情,它将写时的延迟移到了删除时。需要内核、固件(SSD厂商在固件里放TRim算法)、驱动(如Intel的AHCI驱动)三者都支持TRIM才行。
可用fstrim命令回收一个已挂载的文件系统上所有未使用的块(sudo fstrim -v);
也可使用smartctl -a /dev/sda 命令检测磁盘是否有错,从结果里找类似"177 Wear_Leveling_Count 0x0013 099 099 000 Pre-fail Always - 9",那个9是SSD厂商估计的寿命,0代表新SSD盘,100代表可能明天就坏了。
下面是smartmontools自检工具的基本使用
1, 安装包
sudo apt-get install smartmontools
2, 查看硬盘是否enable了SMART自检特性,若没enable,可使用命令”sudo smartctl --smart=on --offlineauto=on --saveauto=on /dev/sda“打开。
hua@node1:~$ sudo smartctl -i /dev/sda
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-9-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF INFORMATION SECTION ===
Model Family: Seagate Barracuda 7200.14 (AF)
Device Model: ST2000DM001-9YN164
Serial Number: W1E0S44Q
LU WWN Device Id: 5 000c50 052bb6b91
Firmware Version: CC4B
User Capacity: 2,000,398,934,016 bytes [2.00 TB]
Sector Sizes: 512 bytes logical, 4096 bytes physical
Rotation Rate: 7200 rpm
Device is: In smartctl database [for details use: -P show]
ATA Version is: ATA8-ACS T13/1699-D revision 4
SATA Version is: SATA 3.0, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is: Wed Mar 23 14:50:55 2016 CST
==> WARNING: A firmware update for this drive may be available,
see the following Seagate web pages:
http://knowledge.seagate.com/articles/en_US/FAQ/207931en
http://knowledge.seagate.com/articles/en_US/FAQ/223651en
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
3, 检测
hua@node1:~$ sudo smartctl -H /dev/sda
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-9-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
4, 详细检测
hua@node1:~$ sudo smartctl -A /dev/sda
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-9-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
1 Raw_Read_Error_Rate 0x000f 117 099 006 Pre-fail Always - 141775376
3 Spin_Up_Time 0x0003 095 094 000 Pre-fail Always - 0
4 Start_Stop_Count 0x0032 100 100 020 Old_age Always - 561
5 Reallocated_Sector_Ct 0x0033 100 100 036 Pre-fail Always - 0
7 Seek_Error_Rate 0x000f 084 060 030 Pre-fail Always - 306606505
9 Power_On_Hours 0x0032 095 095 000 Old_age Always - 5237
10 Spin_Retry_Count 0x0013 100 100 097 Pre-fail Always - 0
12 Power_Cycle_Count 0x0032 100 100 020 Old_age Always - 667
183 Runtime_Bad_Block 0x0032 100 100 000 Old_age Always - 0
184 End-to-End_Error 0x0032 100 100 099 Old_age Always - 0
187 Reported_Uncorrect 0x0032 099 099 000 Old_age Always - 1
188 Command_Timeout 0x0032 100 099 000 Old_age Always - 0 0 1
189 High_Fly_Writes 0x003a 100 100 000 Old_age Always - 0
190 Airflow_Temperature_Cel 0x0022 067 054 045 Old_age Always - 33 (Min/Max 20/36)
191 G-Sense_Error_Rate 0x0032 100 100 000 Old_age Always - 0
192 Power-Off_Retract_Count 0x0032 100 100 000 Old_age Always - 77
193 Load_Cycle_Count 0x0032 100 100 000 Old_age Always - 1907
194 Temperature_Celsius 0x0022 033 046 000 Old_age Always - 33 (0 8 0 0 0)
197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 0
198 Offline_Uncorrectable 0x0010 100 100 000 Old_age Offline - 0
199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always - 0
240 Head_Flying_Hours 0x0000 100 253 000 Old_age Offline - 5111h+51m+54.467s
241 Total_LBAs_Written 0x0000 100 253 000 Old_age Offline - 12778926325684
242 Total_LBAs_Read 0x0000 100 253 000 Old_age Offline - 42981342412817
什么是SSD TRIM (by quqi99)
标签:
原文地址:http://blog.csdn.net/quqi99/article/details/50963308