Thursday 31 January 2019

Does fstrim wear out SSD


I bought a samsung 840 pro 250 GB ssd ~two months ago, and I was wondering how much has been written to it. Actually, I have four partitions: /,/home,boot, and swap. To figure out how much was written to home, I wrote


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


the output was 8,985,606,440 (I added the commas). So that's 8TB. I was wondering to myself, boy I must be writing a lot. I wonder how? I monitored how much I wrote from browsing the internet and other common tasks, then I remembered that I set up a daily cron to do fstrim, because the internet told me to. So I ran


$sudo fstrim -v /home


and the output was 606,591,360 bytes were trimmed.


Then I ran


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


again and sure enough I get 8,986,209,516. So my writes increased 600MB. Now this is not really enough to account for 8TB of writes, but I had just run fstrim a few minutes earlier, so I think fstrim usually trims a lot more than 600 MB. I will have to confirm this.


Regardless, do the writes caused by fstrim actually count towards decreasing the life of your SSD? I had the impression they didn't.



I don't have to guess how much is typically trimmed by the cron job. It turns out the internet told me to log the output of fstrim. Looking at the log, I see it trimmed an average of about 150 GB/day since Aug 24, 150 GB/day * 60 days is about 9 TB. So I think the fstrim does account for the 9TB of writes I have to my SSD.



smart was not enabled on the SSD, but I ran $sudo smartctl -s on /dev/sda7. Then I ran $sudo smartctl -a /dev/sda7. This was the output:


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.

Answer



fstrim does not wear out your ssd; on the contrary, it increases its lifespan. The writes reported in lifetime_write_kbytes refer to file system writes at a higher abstraction level and don't necessarily correspond to physical writes to the drive. So although there are 40 TB of writes reported in lifetime_write_kbytes, running $sudo smartctl -s on /dev/sda7 followed by $sudo smartctl -a /dev/sda7 reveals that I have only written 750,000,000 blocks of 512 bytes each, which comes out to 375GB, which is a more reasonable value for two months of use.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...