如何监控三星SSD上的TBW?


13

众所周知,SSD在NAND单元死亡之前具有有限的PE(编程擦除)周期。

因此,了解多少数据已写入SSD非常有帮助,以确定在NAND死亡之前它将持续多长时间。

我有一个Samsung 850 Pro 512GB SSD,并且正在运行Ubuntu 14.04。

如何获得驱动器的TBW(总字节数)?

Answers:


16

完全公开:此答案中提供的scipt /命令不是我自己的,而是JDG Leaver的工作。它们来自他网站上的博客文章


注意:

  • 这只会报告三星SSD的准确数字
  • 您需要smartctl安装

方法1:

这是一个方便的小脚本,可让您监视SSD的TBW以及其他一些信息:

#!/bin/bash

#######################################
# Variables                           #
#######################################

SSD_DEVICE="/dev/sda"

ON_TIME_TAG="Power_On_Hours"
WEAR_COUNT_TAG="Wear_Leveling_Count"
LBAS_WRITTEN_TAG="Total_LBAs_Written"
LBA_SIZE=512 # Value in bytes

BYTES_PER_MB=1048576
BYTES_PER_GB=1073741824
BYTES_PER_TB=1099511627776

#######################################
# Get total data written...           #
#######################################

# Get SMART attributes
SMART_INFO=$(sudo /usr/sbin/smartctl -A "$SSD_DEVICE")

# Extract required attributes
ON_TIME=$(echo "$SMART_INFO" | grep "$ON_TIME_TAG" | awk '{print $10}')
WEAR_COUNT=$(echo "$SMART_INFO" | grep "$WEAR_COUNT_TAG" | awk '{print $4}' | sed 's/^0*//')
LBAS_WRITTEN=$(echo "$SMART_INFO" | grep "$LBAS_WRITTEN_TAG" | awk '{print $10}')

# Convert LBAs -> bytes
BYTES_WRITTEN=$(echo "$LBAS_WRITTEN * $LBA_SIZE" | bc)
MB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_MB" | bc)
GB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_GB" | bc)
TB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_TB" | bc)

# Output results...
echo "------------------------------"
echo " SSD Status:   $SSD_DEVICE"
echo "------------------------------"
echo " On time:      $(echo $ON_TIME | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') hr"
echo "------------------------------"
echo " Data written:"
echo "           MB: $(echo $MB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo "           GB: $(echo $GB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo "           TB: $(echo $TB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo "------------------------------"
echo " Mean write rate:"
echo "        MB/hr: $(echo "scale=3; $MB_WRITTEN / $ON_TIME" | bc | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo "------------------------------"
echo " Drive health: ${WEAR_COUNT} %"
echo "------------------------------"

这是输出示例:

------------------------------
 SSD Status:   /dev/sda
------------------------------
 On time:      2 hr
------------------------------
 Data written:
           MB: 25,098.917
           GB: 24.510
           TB: .023
------------------------------
 Mean write rate:
        MB/hr: 12,549.458
------------------------------
 Drive health: 100 %
------------------------------

这些数据是准确的,因为我只是安装了新的850 Pro。


方法2:

另外,这是只获得TBW的单线服务:

echo "GB Written: $(echo "scale=3; $(sudo /usr/sbin/smartctl -A /dev/sda | grep "Total_LBAs_Written" | awk '{print $10}') * 512 / 1073741824" | bc | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"

这不适用于我的SAMSUNG MZ7LN512HMJP-000L7 SSD。smartctl报告Total_LBAs_Written为2268,并产生1.1 MB的写入数据–对于已经使用了一年以上的驱动器,显然是不正确的,并且该驱动器是我的主要系统驱动器:(
Icydog

@Icydog :(您正在运行什么版本的Ubuntu?
You'reAGitForNotUsingGit

我使用的是Fedora27。我认为我的SSD可能只是无法正确报告数字。
Icydog '18年

我的研究表明,每个SSD对于每个“写入的LBA”的实际含义似乎都有自己的乘数。我没有Samsung 850的电话号码,但绝对不是一个部门……
ljwobker

3

至关重要的SSD剩余使用寿命

对于Crucial SSD(由Micron制造),剩余寿命的问题变得容易一些。

https://www.micron.com/~/media/documents/products/technical-note/solid-state-storage/tnfd22_client_ssd_smart_attributes.pdf

此文档将202标识为剩余生存时间百分比。例如,在Ubuntu 16.04(sudo smartctl /dev/sda1 -a)上报告202为未知,但值90(在我的情况下)与pdf中的描述匹配,并指示剩余90%的寿命。可以通过critical.com有关驱动器的文献中提供的TBW来适当地缩放比例。实际上,剩余生命期更为有用。


1

可接受的答案使输出output肿,过多的无用脚本-wizardry并从中隐藏了初始参数名称smartctl。这是一个更好的版本;

#!/bin/bash

device=${1:-/dev/sda}
sudo smartctl -A $device |awk '
$0 ~ /Power_On_Hours/ { poh=$10; printf "%s / %d hours / %d days / %.2f years\n",  $2, $10, $10 / 24, $10 / 24 / 365.25 }
$0 ~ /Total_LBAs_Written/ {
    lbas=$10;
    bytes=$10 * 512;
    mb= bytes / 1024^2;
    gb= bytes / 1024^3;
    tb= bytes / 1024^4;
    printf "%s / %s  / %d mb / %.1f gb / %.3f tb\n", $2, $10, mb, gb, tb
    printf "mean writes per hour:  / %.2f",  mb/poh
}
$0 ~ /Airflow_Temperature_Cel/ { print $2 " / " $10}
$0 ~ /Wear_Leveling_Count/ { printf "%s / %d (%% health)\n", $2, int($4) }
' |
    sed -e 's:/:@:' |
    sed -e "s\$^\$$device @ \$" |
    column -ts@

样本输出:

$ for i in /dev/sd{a,b,c,d}; do ssd-tbw $i;done   |sort -k2,2
/dev/sda    Airflow_Temperature_Cel    49
/dev/sdb    Airflow_Temperature_Cel    49
/dev/sdc    Airflow_Temperature_Cel    45
/dev/sdd    Airflow_Temperature_Cel    47
/dev/sda    mean writes per hour:      655.80
/dev/sdb    mean writes per hour:      646.97
/dev/sdc    mean writes per hour:      874.49
/dev/sdd    mean writes per hour:      733.95
/dev/sda    Power_On_Hours             27292 hours / 1137 days / 3.11 years
/dev/sdb    Power_On_Hours             27300 hours / 1137 days / 3.11 years
/dev/sdc    Power_On_Hours             14432 hours / 601 days / 1.65 years
/dev/sdd    Power_On_Hours             23255 hours / 968 days / 2.65 years
/dev/sda    Total_LBAs_Written         36655329806  / 17898110 mb / 17478.6 gb / 17.069 tb
/dev/sdb    Total_LBAs_Written         36172538301  / 17662372 mb / 17248.4 gb / 16.844 tb
/dev/sdc    Total_LBAs_Written         25846999325  / 12620605 mb / 12324.8 gb / 12.036 tb
/dev/sdd    Total_LBAs_Written         34955224738  / 17067980 mb / 16668.0 gb / 16.277 tb
/dev/sda    Wear_Leveling_Count        93 (% health)
/dev/sdb    Wear_Leveling_Count        93 (% health)
/dev/sdc    Wear_Leveling_Count        95 (% health)
/dev/sdd    Wear_Leveling_Count        94 (% health)

和一线

$ sudo /usr/sbin/smartctl -A /dev/sda | 
     awk '$0~/LBAs/{ printf "TBW %.1f\n", $10 * 512 / 1024^4 }'
TBW 17.1
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.