NVME Cli -- nvme command to view the internal status of NVME devices | Perspective Nvme SSD from NVMe Cli

statement

Homepage : Metastorage Blog_CSDN Blog

Arranged based on public knowledge and experience, please leave a message if there is any error.

Personal hard work, reprinting is prohibited.


abstract

The full text is 4200 words, the main content is


foreword

My laptop has an NVMe drive and they are fast. I like.

This is interesting, but I'd like to know more about the internals of my particular NVMe drive

Out of curiosity, Yuan will take you to experience the NVMe perspective tool   nvme-cli .


1 Exploring NVMe CLI

1.1 What is Nvme CLI

   nvme-cli  is an open source project with a set of tools for managing NVMe drives. Most of the code of Nvme-cli is to spell the command field and send it to the kernel through ioctl. You can download the source code from github to see the specific implementation. (nvme can also use smartctl to get log)

1.2 Install nvme-cli

Source code download address
https://github.com/linux-nvme/nvme-cli

You can install directly from your distribution's package manager  nvme-cli. For example,:

  1. $ sudo apt install nvme-cli

1.3 NVMe Cli Help Menu

nvme-cli There is no man page, but you can  nvme help get a lot of help by typing:

insert image description here

Note: Different nvme cli versions have different functions, please refer to the computer version you use, of course you can also install the latest nvme cli

2 NVMe Common Commands and Practices

2.1 List all NVMe drives

$ sudo nvme list
Node SN Model Namespace Usage Format FW Rev
--------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------
/dev/nvme0n1    S42GMY9M1412819 SAMSUNG MZVLB256HAHQ-000L7 1
214.68 GB / 256.06 GB 512  B + 0 B 0L2QEXD7

 There is a  nvme0n1 drive named . It lists the serial number (S42GMY9M1412819), brand (SAMSUNG), namespace (MZVLB256HAHQ-000L7), capacity (256GB), format (512B), firmware version (0L2QEXD7), and more.

You can get more information about the drive and its supported features by using  id-ctrl subcommands:

$ sudo nvme id-ctrl /dev/nvme0n1
NVME Identify Controller:
vid : 0x144d
ssvid : 0x144d
sn : S42GMY9M141281
mn : SAMSUNG MZVLB256HAHQ-000L7 -- 品牌、命名空间
fr : 0L2QEXD7  -- 固件版本
rab : 2
ieee : 002538
cmic : 0
mdts : 9
cntlid : 0x4
ver : 0x10200
rtd3r : 0x186a0
rtd3e : 0x7a1200
[...]

2.2 Formatting an NVMe drive

It is possible to  nvme-cli format an NVMe drive with , but be careful. This will delete all data on the drive! If you have important data on your hard drive, you must back it up before doing this, or you will lose data. The subcommands are  format:

$ sudo nvme format /dev/nvme0nX

(To be on the safe side, I  X replaced the actual location of the drive with , to prevent copy-paste errors. Replace  X or  1 with  nvme list the actual location listed in the results.)

Commonly used methods
1) nvme format -s 1 /dev/nvme1n1 to format the hard disk (secure erase drives)

2) nvme format /dev/nvme1n1 -n 1 -l 1 4KB alignment

3) nvme format /dev/nvme1n1 -n 1 -l 0 to restore the initial state 512

4)nvme format /dev/nvme1n1 -l 0 Optane device Units512

Depending on actual needs, 4KB alignment is recommended

Refer to [ NVMe CLI commands using _nvme-cli_dry dry ]

2.3 Securely Erase NVMe Drives

When you're ready to sell or dispose of your NVMe computer, you may want to securely wipe the drive. The warnings here are the same as during formatting. Backup important data first, as this command will delete them!

$ sudo nvme sanitize /dev/nvme0nX

This part is reproduced from (with deletion)

Tech | Learn about your NVMe drives with Linux command line tools

via: Use this Linux command-line tool to learn more about your NVMe drives | Opensource.com

Author: Don Watkins  Topic: lujun9972  Translator: geekpi  Proofreading: turbokernel

2.4 NVMe SMART health information 

You can use  smart-log subcommands to understand the overall health status of the hard disk (Chinese author's note):

$ sudo nvme smart-log /dev/nvme0n1
Smart Log for NVME device:nvme0n1 namespace-id:ffffffff
critical_warning : 0             -- 警告
temperature : 21 C               -- 当前温度
available_spare : 100%           -- 剩余可用备用空间
available_spare_threshold : 10%  -- 当可用备用空间低于该阈值时就会发出预警
percentage_used : 2%             -- 已使用寿命百分比
endurance group critical warning summary: 0
data_units_read : 5,749,452      -- 读操作数据量
data_units_written : 10,602,948  -- 写操作数据量
host_read_commands : 77,809,121  -- 主机发送读命令个数
host_write_commands : 153,405,213-- 主机发送写命令个数
controller_busy_time : 756       -- 控制器忙次数统计
power_cycles : 1,719             -- (断电/上电)次数
power_on_hours : 1,311           -- 累计带电工作时间
unsafe_shutdowns : 129           -- 非安全断电次数
media_errors : 0                        -- 闪存和数据完整性错误
num_err_log_entries : 1,243             -- err log 次数
Warning Temperature Time : 0            -- 过热警告时间
Critical Composite Temperature Time : 0 --过热临界温度时间
Temperature Sensor 1 : 21 C             -- 温度传感器 1 温度
Temperature Sensor 2 : 22 C             -- 温度传感器 2 温度
Thermal Management T1 Trans Count : 0
Thermal Management T2 Trans Count : 0
Thermal Management T1 Total Time : 0
Thermal Management T2 Total Time : 0

endurance group critical warning summary 

This item needs to observe the data in the "Original Value" column, which should be 0 under normal circumstances. If it is displayed as 1, it means that the current hard disk is overheated; if it is displayed as 2, it means that the reliability of the flash memory is degraded due to a serious error, and it is time to consider replacing it; if it is displayed as 3, it means that the flash memory has entered a read-only state (life is exhausted, lock the disk to protect user data) ). There is also a status 4, which is only available for enterprise-level SSDs, which means that the enhanced power-off protection function fails (usually due to battery/capacitor failure) 

Available Spare available spare space

This item shows the percentage of the spare blocks of the flash memory that can be used to replace bad blocks to the total number at the time of delivery, and is a very important health indicator. NVMe SSDs equipped with Toshiba BiCS flash memory can maintain 100% status after a long time of use.

Data Units Read read sector count

The value of this item multiplied by 1000 is the number of read sectors (1 sector = 512 bytes).

Data Units Write write sector count

Multiplying the value of this item by 1000 is the statistics of the number of sectors written (1 sector = 512 bytes).

Controller Busy Time master busy time count

This item counts the total time (unit: minute) that the main controller is busy processing IO commands. When there are unfinished commands in the IO queue, the main control is in the "busy" state.

Unsafe Shut downs Unsafe shutdown times (abnormal power failure count)

Abnormal power failure is the enemy that threatens solid state drives, we should avoid forced shutdown as much as possible. Every abnormal power failure consumes the service life of the SSD.

Media and Data Integrity Errors Flash and Data Integrity Errors

The number of times the master detected unrecovered data integrity errors. This value will increase when there is an ECC that the error correction engine cannot correct, a CRC check failure, or an LBA label mismatch error occurs. If the value of this item is not zero, it means that the solid-state hard drive has become unstable.

The SMART health information of the NVMe solid-state drive is very comprehensive, but the fly in the ointment is that an interface speed is missing. When the SSD is in use, if the motherboard’s PCIE interface is relatively old, or because it is loosely plugged, it will be compatible with low speed. Maybe the PCIE 4.0 SSD actually runs at the speed of PCIE 3.0, or the speed of PCIE 2.0. Or channel 4 only recognizes channel 2 because the interface is loose, which may also cause a slowdown.


 This part is reproduced from (with deletion)

The status information of the solid state drive is all in English, can't you read it? Storage geeks will teach you_China IT News

Author: Storage Geek

2.5 NVME firmware device upgrade    

Firmware is a software program in the chip, and there are also bugs. When a bug is found and repaired, the supplier will provide a new firmware version to fix known problems. Follow-up firmware updates can avoid triggering known defects, and stability-improving patch packages are updated in a timely manner. Of course, the frequency of firmware upgrades will not be very high, generally no more than 5 times a year, and the longer the mass production time, the more stable it will be. Before the upgrade, you can check the version information of the firmware upgrade with the supplier.

Confirm firmware version

nvme id-ctrl /dev/nvme0 |grep "fr "


Download the firmware and apply it

nvme fw-download /dev/nvme0 -
nvme fw-commit /dev/nvme0 -a 0

Note here that the action mode specified by -a in the commit process has different meanings

0 : The downloaded firmware image replaces the original firmware image, but it will not be activated. That is, it will not make this image run
1: The downloaded firmware image replaces the original firmware image, and it will run after NVME reset. (Hot-swappable, power-off, power-on will also run)
2: The image specified by the firmware slot will be activated after the next reset
3: The obtained firmware image will be activated immediately without reset and
downloaded If you need to reset the firmware, you can execute the following command:

nvme reset /dev/nvme0

————————————————

 This part is reproduced from (with deletion)

Copyright statement: This article is an original article of CSDN blogger "z_stand", which follows the CC 4.0 BY-SA copyright agreement. For reprinting, please attach the original source link and this statement.
Original link: https://blog.csdn.net/Z_Stand/article/details/111415236

2.6 OP(Over-Provisioning)

nvme admin-passthru /dev/nvme0 -o 0x9 --cdw10=0xc1 --cdw11=0x2000000 --cdw12=0x0
OP to GB
1.The decimal value of LBA is (X * 1000 * 1000 * 1000 / 512), then convert it to Hex Value.
2. Put the Hex Value to cdw11
3. If the Hex Value over 0xFFFFFFFF, put the high overflow digits to cdw 12.
4. Example:
⦁ 3200 GB
⦁ Decimal value is 6,250,000,000 and Hex Value is 0x174876E80
The value for cdw12 should be 0x1 and for cdw11 is 0x74876E80.
⦁ 2000 GB
⦁ Decimal value is 3,906,250,000 and Hex Value is 0xE8D4A510
The value for cdw12 should be 0x0 and for cdw11 is 0xE8D4A510.
⦁ 4000 GB
⦁ 7,814,037,168 // 0x1 D1C0 BEB0
⦁ 7200 GB - 0x3 4630 B8A0
6400 GB - 0x2 E90E DD00
Example 1:

two,

Original capacity OPed to 3.4T
[root@localhost nvme-cli-master]# nvme admin-passthru /dev/nvme9n1 -o 0x9 --cdw10=0xc1 --cdw11=0x18BCFE568 --cdw12=0x1 NVMe command
result:00000000 

2.7 nvme-cli create namespaces

What is a Namespace?
To put it simply, a namespace is a logical division of the user space, which is to divide the big pizza of the user space, and everyone can eat their own. So what does a big pizza look like? What about sliced ​​pizza? We know that, like other traditional storage devices, non-volatile memory can also be formatted into logical blocks. Each logical block has its own address, commonly known as logical block address, or LBA for short. We eat pizza through LBA (Read and write IO). The logical address looks very common, from 0, 1, 2... until the largest block address.
The calculation of the logical block address is exquisite, strictly according to the formula of the relationship between the logical block and the capacity defined in JEDEC218A. For example, for a logical block of 4KiB, 500G requires 2646 + 244188 * 500 = 122096646 logical addresses, and these logical blocks form a namespace (for a logical block of 512B, 500G requires 21168+1953504*500=976773168 logical addresses) . So can an SSD be divided into multiple namespaces for different application scenarios? The answer is yes.

For example: Create a 500G and a 465G namaspaces
to check whether the remaining space on the SSD is enough to create the target namespace. Use the Identify command to view the value of unvmcap to know the remaining allocatable capacity, the unit is Byte.


#Please make sure your SSD supports NS before performing the following steps
#Generally large manufacturers will have the need for NS, please contact your manufacturer to ensure SSD support.
# Personal disk is not recommended to try NS operation
1.detach
nvme detach-ns /dev/nvme0 -n 1 -c 0
nvme delete-ns /dev/nvme0 -n 1
nvme reset /dev/nvme0

2. Create
**#1953125000 = 1,000,000,000,000/512 = 1,953,125,000 (1TB)**
nvme create-ns /dev/nvme0 -s 976562500 -c 976562500 -f 0 -d 0 -m 0
nvme attach-ns /dev /nvme0 - n 1 -c 0

nvme create-ns /dev/nvme0 -s 975175680 -c 975175680 -f 0 -d 0 -m 0 #The second creation must be
nvme attach-ns /dev/nvme0 -n 2 -c 0

nvme reset /dev/nvme0
nvme list
[root@localhost Muti-namespace_Test]# nvme list
Node             SN                   Model                                    Namespace Usage                      Format           FW Rev  
---------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------
/dev/nvme0n1     XXXXXX   XXXXX                      1         500.36  GB / 500.36  GB    512   B +  0 B   ss10152
/dev/nvme0n2     XXXXXX   XXXXX                      2         499.29  GB / 499.29  GB    512   B +  0 B   ss10152

3. Delete
nvme detach-ns /dev/nvme0 -n 1 -c 0
nvme detach-ns /dev/nvme0 -n 2 -c 0

nvme delete-ns /dev/nvme0 -n 1
nvme delete-ns /dev/nvme0 -n 2

4. Restore
NVMe Create -NS /DEV /NVME0 -S 1000204886016 -C 1000204886016 -F 0 -M 0 #1000204886016. It is "NVMe ID -CTRL /DEV /NVME0N1 | GREP TNVMCAP" and divide it with 51 2
nvme attach-ns /dev/nvme0 -n 1 -c 0
nvme reset /dev/nvme0

2.8 PCIe Hard Disk Life Calculation

You can read the smart information of the PCIe hard disk through nvme-cli , and calculate the Endurance and DWPD (Drive Writes Per Day) of the hard disk.
It is recommended that life testing may only be necessary at the enterprise level, and it is not necessary for individuals to perform this operation.
a. Read hard disk smart-log information before testing

[root@localhost nvme-cli-master]# nvme intel smart-log-add /dev/nvme0n1       
Additional Smart Log for NVME device:nvme0n1 namespace-id:ffffffff
key                               normalized raw
program_fail_count                             :   0%       0
erase_fail_count                                :   0%       0
wear_leveling                                   :   0%       min: 0, max: 0, avg: 0
end_to_end_error_detection_count: 100%       159
crc_error_count                                 : 100%       25963
timed_workload_media_wear       : 100%       0.000%
timed_workload_host_reads       : 100%       8%
timed_workload_timer            : 100%       120864 min
thermal_throttle_status         : 100%       0%, cnt: 1
retry_buffer_overflow_count     : 100%       0
pll_lock_loss_count             : 100%       0
nand_bytes_written              :   0%       sectors: 0
host_bytes_written              : 100%       sectors: 26008485


b.fio reads and writes certain data
c.executes nvme intel smart-log-add /dev/nvme0n1 again after fio ends to read smart-log information
d.calculates

 After the disk enters the steady state (when the SLC buffer is consumed and the speed decreases), it is more accurate to obtain the value of DWPD by random writing

DWPD: Drive Wriytes Per Dat, that is, within the warranty period of the SSD, how many times each household can fill the disk every day

WAF: Write Aplication factor, that is, write amplification

PE Cycle: Write Program(P) once and Erase(E) once, count as a PE. So PE Cycle refers to the number of erasures

————————————————
Copyright statement: This part is the original article of CSDN blogger "Qiangan", following the CC 4.0 BY-SA copyright agreement, please attach the original source link and this statement.
Original link: https://blog.csdn.net/hailangdeyingzi/article/details/121039000


reference

[1]  Technology|Use Linux command line tools to understand your NVMe drive
[2]  Solid state drive status information is all in English Can't understand? Storage geeks will teach you_China IT News

262abfa94e2b5642120b21810384ce4b.png

Disclaimer :

This article is organized based on public information and aims to introduce more storage knowledge. The articles contained in the article are only the author's opinion and do not constitute investment or commercial advice. This article is only for learning and communication, not for commercial use. If you have any questions or infringements, please contact the author.

Supongo que te gusta

Origin blog.csdn.net/vagrant0407/article/details/131819003
Recomendado
Clasificación