编辑

编辑

我大约两个月前买了一块三星 840 pro 250 GB 的固态硬盘,我想知道它被写入了多少数据。实际上,我有四个分区:/、/home、boot 和 swap。为了弄清楚有多少数据被写入了 home,我写了

$cat /sys/fs/ext4/sda7/lifetime_write_kbytes

输出是8,985,606,440(我添加了逗号)。所以这是 8TB。我心里想,天哪,我肯定写了很多东西。我想知道怎么做到的?我通过浏览互联网和其他常见任务监控了我写了多少内容,然后我想起我设置了一个每日 cron 来执行 fstrim,因为互联网告诉我这样做。所以我运行了

$sudo fstrim -v /home

并且输出是606,591,360被修剪的字节。

然后我就跑了

$cat /sys/fs/ext4/sda7/lifetime_write_kbytes

再次,果然我得到了8,986,209,516。所以我的写入增加了 600MB。现在这还不足以解释 8TB 的写入,但我几分钟前刚刚运行了 fstrim,所以我认为 fstrim 通常会修剪掉 600MB 以上的空间。我必须确认这一点。

无论如何,fstrim 引起的写入是否真的会缩短 SSD 的使用寿命?我的印象是不会。

编辑

我不需要猜测 cron 作业通常会修剪多少。事实证明,互联网告诉我要记录 fstrim 的输出。查看日志,我发现自 8 月 24 日以来,它平均每天修剪约 150 GB,150 GB/天 * 60 天约为 9 TB。所以我认为 fstrim 确实占了我对 SSD 的 9 TB 写入量。

编辑2

SSD 上没有启用 smart,但我运行了$sudo smartctl -s on /dev/sda7。然后我运行了$sudo smartctl -a /dev/sda7。这是输出:

smartctl 5.43 2012-06-30 r3573 [x86_64-linux-3.8.0-25-generic] (local build)
Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF INFORMATION SECTION ===
Device Model:     Samsung SSD 840 PRO Series
Serial Number:    S1ATNSAD780426K
LU WWN Device Id: 5 002538 5a00ae961
Firmware Version: DXM05B0Q
User Capacity:    256,060,514,304 bytes [256 GB]
Sector Size:      512 bytes logical/physical
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   8
ATA Standard is:  ATA-8-ACS revision 4c
Local Time is:    Wed Oct 30 09:43:18 2013 CDT
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x00) Offline data collection activity
                    was never started.
                    Auto Offline Data Collection: Disabled.
Self-test execution status:      (   0) The previous self-test routine completed
                    without error or no self-test has ever 
                    been run.
Total time to complete Offline 
data collection:        (53956) seconds.
Offline data collection
capabilities:            (0x53) SMART execute Offline immediate.
                    Auto Offline data collection on/off support.
                    Suspend Offline collection upon new
                    command.
                    No Offline surface scan supported.
                    Self-test supported.
                    No Conveyance Self-test supported.
                    Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                    power-saving mode.
                    Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                    General Purpose Logging supported.
Short self-test routine 
recommended polling time:    (   2) minutes.
Extended self-test routine
recommended polling time:    (  20) minutes.
SCT capabilities:          (0x003d) SCT Status supported.
                    SCT Error Recovery Control supported.
                    SCT Feature Control supported.
                    SCT Data Table supported.

SMART Attributes Data Structure revision number: 1
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  9 Power_On_Hours          0x0032   099   099   000    Old_age   Always       -       458
 12 Power_Cycle_Count       0x0032   099   099   000    Old_age   Always       -       28
177 Wear_Leveling_Count     0x0013   099   099   000    Pre-fail  Always       -       2
179 Used_Rsvd_Blk_Cnt_Tot   0x0013   100   100   010    Pre-fail  Always       -       0
181 Program_Fail_Cnt_Total  0x0032   100   100   010    Old_age   Always       -       0
182 Erase_Fail_Count_Total  0x0032   100   100   010    Old_age   Always       -       0
183 Runtime_Bad_Block       0x0013   100   100   010    Pre-fail  Always       -       0
187 Reported_Uncorrect      0x0032   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0032   072   068   000    Old_age   Always       -       28
195 Hardware_ECC_Recovered  0x001a   200   200   000    Old_age   Always       -       0
199 UDMA_CRC_Error_Count    0x003e   100   100   000    Old_age   Always       -       0
235 Unknown_Attribute       0x0012   001   001   000    Old_age   Always       -       4294967148
241 Total_LBAs_Written      0x0032   099   099   000    Old_age   Always       -       748699270

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
No self-tests have been logged.  [To run self-tests, use: smartctl -t]


SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
  255        0    65535  Read_scanning was never started
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

答案1

fstrim 不会磨损您的 ssd;相反,它会延长其使用寿命。lifetime_write_kbytes 中报告的写入是指更高抽象级别的文件系统写入,并不一定对应于驱动器的物理写入。因此,尽管 lifetime_write_kbytes 中报告了 40 TB 的写入,但运行$sudo smartctl -s on /dev/sda7$sudo smartctl -a /dev/sda7发现我只写入了 750,000,000 个 512 字节的块,总计 375GB,这对于两个月的使用来说是一个更合理的值。

答案2

lifetime_write_kbytes在 Linux 的其他所有级别统计中,修剪操作都算作写入,例如,请iostat参阅sar发帖. 写入统计数据很容易被算作写入的修剪所主导,尤其是对于中等填充的文件系统。

换句话说:lifetime_write_kbytes对于写入 SSD 磁盘的数据量来说,这不是一个可靠的估计。

相关内容