Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We're quite interested in exploring the possibility of using SSD drives in a server environment. However, one thing that we need to establish is expected drive longevity. According to this article manufacturer's are reporting drive endurance in terms of 'total bytes written' (TBW). E.g. from that article a Crucial C400 SSD is rated at 72TB TBW. Do any scripts/tools exist under the Linux ecosystem to help us measure TBW? (and then make a more educated decision on the feasibility of using SSD drives)

share|improve this question

4 Answers 4

up vote 9 down vote accepted

Another possibility is to look at /proc/diskstats. It's not persistent across reboots, but it has data for every block device. Probably most interesting to you is field 10, which contains the total number of sectors written. On a system with scsi disks with a sector size of 512 bytes, you could run

awk '/sd/ {print $3"\t"$10 / 2 / 1024}' /proc/diskstats

to see how many megabytes were written to each device. The output will look like

sda 728.759
sda1 79.0908
sda2 649.668

share|improve this answer
2  
Sector size could be found by running command #cat /sys/block/sda/queue/hw_sector_size –  Antonio Jul 3 '12 at 15:19
    
@Antonio thanks! I'm not sure when that was added. It looks like it is in 3.2 but not 2.6.18. –  sciurus Jul 3 '12 at 19:04
    
@sciurus could you explain the math behind your calculations please ? You're talking about the size of the sector = 512 but your calculations are dividing the read value with 2/1024 –  gyre Jan 14 '13 at 18:07
    
@gyre Field 10 contains the number of 0.5 kilobyte sectors written. I divide that by 2 to get the number of kilobytes written. I then divide that by 1024 to convert to megabytes. –  sciurus Jan 15 '13 at 18:19
    
@antonio That does show the sector size being used with the underlying hardware, but afaict from the kernel source, iostat source, and empirical tests, the "sectors" number in /proc/diskstats always refers to 512 bytes, even when hw_sector_size is different (at least since the 2.4 series). See block/cfq-iosched.c, particularly cfqg_stats_update_dispatch(). –  the paul Feb 7 at 20:36

You can see how much data has been written to an ext4 filesystem by looking in /sys/fs/ext4/$DEVICE/lifetime_write_kbytes.

share|improve this answer
    
That's a cool feature I didn't know about! A shame most of our systems are running ext3 and also some raw LVM partitions for VMs :) –  badnews Feb 21 '11 at 8:06
    
ext3 (and to a slightly lesser extent) ext4 are not designed for writing to flash. The failure will occur depending on the number of times a location is written - and with conventional filesystems, hotspots develop very rapidly. The figures cited by manufacturers are very misleading since they assume an even spread of writes. There are filesystems - such as JFFS2 - specifically designed to extend the life of your SSDs. –  symcbean Feb 21 '11 at 12:47
    
@symcbean - with present-day flash devices, this is largely a non-issue. They all have wear-leveling routines built into their on board controllers. –  EEAA Feb 21 '11 at 14:50
    
@ErikA - I assumed the same. The flash controller should perform wear-levelling which would make the "total bytes written" metric a useful guideline :) (or so I hope!) –  badnews Feb 21 '11 at 22:32
    
@symcbean - There are two kinds of flash devices. Memory Technology Devices (or MTDs) present a direct interface to the flash memory. These are typically found in embedded devices and are what filesystem like JFFS2 are designed for. The other kind of flash device hides the flash memory behind a Flash Translation Later (FTL) so that it looks like a regular block device. This is how consumer technology like SSDs, usb sticks, and memory cards are implemented. Filesystems like JFFS2 aren't appropriate for these; instead, you have to use filesystems like ext4 that are designed for block devices. –  sciurus Feb 23 '11 at 4:10

I was struggling with the same problem on my notebook, but as I reboot it pretty much on a daily basis, the accepted answer wasn't helpful. I have a Samsung mSATA SSD, which happens to have the SMART attribute #241 Total_LBAs_Written. According to the official documentation,

To calculate the total size (in Bytes), multiply the raw value of this attribute by 512B.

So the following command gives me the total Gb written on my SSD disk (sdb)

sudo smartctl -A /dev/sdb | awk '/^241/ {print $10 * 512 / 1024 ^ 4, "Tb " } '

As it also works on my HDD, I assume that it should work on pretty much every modern hard disk.

share|improve this answer
2  
No, this only exists on certain models of SSD drives. It is not universal. –  Michael Hampton Feb 3 at 3:50

You can try iostat. It gives you statistics related to IO and CPU usage. Have a look at the manual man iostat.

share|improve this answer
    
I suppose that could work but I was hoping there was something higher-level available that could provide cumulative byte totals :) –  badnews Feb 21 '11 at 8:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.