1 - fdisk命令

Linux fdisk 命令

查看分区情况

sudo fdisk -l

输出类似,这里有两块sdd硬盘:

Disk /dev/nvme1n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WDS500G1B0C-00S6U0                  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: AB8D3D88-0124-404E-B1BC-658E567C569D

Device             Start       End   Sectors  Size Type
/dev/nvme1n1p1      2048   1050623   1048576  512M EFI System
/dev/nvme1n1p2   1050624 839911423 838860800  400G Linux filesystem
/dev/nvme1n1p3 839911424 976771071 136859648 65.3G Linux filesystem


Disk /dev/nvme0n1: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors
Disk model: YSSDHB-4TN7000                          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

对硬盘进行分区

通过 fdisk -l 命令找到要进行分区的硬盘,比如这里是 /dev/nvme0n1

sudo fdisk /dev/nvme0n1

如果硬盘没有分区表,则会提示:

Device does not contain a recognized partition table.
The size of this disk is 3.7 TiB (4096805658624 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).

Created a new DOS disklabel with disk identifier 0x55c9e168.

Command (m for help):

推荐使用 GPT 分区。

之后输入 m 可以得到帮助菜单:

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

这里首先输入 g 来创建 GPT 分区表:

Command (m for help): g
Created a new GPT disklabel (GUID: DA503D82-D785-4A47-A701-504DB1ED256C).

然后输入 n 来创建新的分区,这里简单起见,将整个硬盘作为一个单个分区 3.7T:

Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-8001573518, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-8001573518, default 8001573518): 

Created a new partition 1 of type 'Linux filesystem' and of size 3.7 TiB.

输入 w 写入硬盘并退出:

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

分区完成之后检查硬盘:

sudo fdisk -l 

Disk /dev/nvme1n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WDS500G1B0C-00S6U0                  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: AB8D3D88-0124-404E-B1BC-658E567C569D

Device             Start       End   Sectors  Size Type
/dev/nvme1n1p1      2048   1050623   1048576  512M EFI System
/dev/nvme1n1p2   1050624 839911423 838860800  400G Linux filesystem
/dev/nvme1n1p3 839911424 976771071 136859648 65.3G Linux filesystem


Disk /dev/nvme0n1: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors
Disk model: YSSDHB-4TN7000                          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DA503D82-D785-4A47-A701-504DB1ED256C

Device         Start        End    Sectors  Size Type
/dev/nvme0n1p1  2048 8001573518 8001571471  3.7T Linux filesystem

后续操作

格式化

再对分区进行格式化,这里采用 ext4 格式:

sudo mkfs.ext4 /dev/nvme0n1p1

➜  ~ sudo mkfs.ext4 /dev/nvme0n1p1
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done                            
Creating filesystem with 1000196433 4k blocks and 250052608 inodes
Filesystem UUID: 0478bcae-bab0-4762-a48a-6bdab9d99d5b
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848, 512000000, 550731776, 644972544

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done 

挂载

通过

lsblk --fs

命令查看分区的 UUID 备用:


NAME        FSTYPE   LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINT
nvme1n1                                                                        
|-nvme1n1p1 vfat           4FD8-D561                             504.9M     1% /boot/efi
|-nvme1n1p2 ext4           7a60bb3b-ea82-47c0-86d0-f92edba2a466  356.4G     4% /
`-nvme1n1p3 ext4           68100d98-ccea-4f5e-8663-16ff1b194ac1   52.7G    12% /timeshift
nvme0n1                                                                        
`-nvme0n1p1 ext4           0478bcae-bab0-4762-a48a-6bdab9d99d5b  

执行

sudo vi /etc/fstab

可以看到:

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/nvme0n1p2 during curtin installation
/dev/disk/by-uuid/7a60bb3b-ea82-47c0-86d0-f92edba2a466 / ext4 defaults 0 1
# /timeshift was on /dev/nvme0n1p3 during curtin installation
/dev/disk/by-uuid/68100d98-ccea-4f5e-8663-16ff1b194ac1 /timeshift ext4 defaults 0 1
# /boot/efi was on /dev/nvme0n1p1 during curtin installation
/dev/disk/by-uuid/4FD8-D561 /boot/efi vfat defaults 0 1

类似的增加一行记录

/dev/disk/by-uuid/0478bcae-bab0-4762-a48a-6bdab9d99d5b /data ext4 defaults 0 1

注意需要提前创建挂载的目录

sudo mkdir /data

保存后,重启或者执行 sudo mount -a 生效。

2 - dd命令

Linux dd 命令

2.1 - dd命令介绍

Linux dd 命令介绍

介绍

使用

测试硬盘读取速度

dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync

dd if=/dev/zero of=/root/temp/test1.img bs=10G count=1 oflag=dsync

参考资料

2.2 - 三星pm983测试数据

三星pm983测试数据

硬盘型号 三星 pm983,容量 900G, m2 接口 nvme 协议, pcie 3.0 x4, 规格为 22110。

华硕z690

主板为华硕 z690-p d4, m2 接口 pcie 4.0 x4,受硬盘限制实际为 pcie 3.0 x4。

安装 pve 8.0 系统,6.2 内核。

基本信息

$ lspci | grep SSD 

08:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM981/PM981/PM983

磁盘数据:

$ fdisk -l

Disk /dev/nvme1n1: 838.36 GiB, 900185481216 bytes, 219771846 sectors
Disk model: MZ1LB960HBJR-000FB                      
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 131072 bytes / 131072 bytes
Disklabel type: gpt
Disk identifier: 87408245-67E3-47E0-AF90-85B8DDDAD75D

Device             Start       End   Sectors   Size Type
/dev/nvme1n1p1 193462528 219771647  26309120 100.4G Linux filesystem
/dev/nvme1n1p2       256    262399    262144     1G EFI System
/dev/nvme1n1p3    262400 193462272 193199873   737G Linux LVM

分区信息:

$ hdparm /dev/nvme1n1p3

/dev/nvme1n1p3:
 readonly      =  0 (off)
 readahead     = 512 (on)
 geometry      = 754687/64/32, sectors = 1545598984, start = 2099200

速度测试

硬盘写入速度:

$ dd if=/dev/zero of=/root/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 14.4349 s, 744 MB/s

只有 744 兆,低的有点出乎意外,应该是缓存耗尽。

硬盘读取速度:

dd if=/root/temp/test1.img of=/dev/null bs=8k

对比

hdparm -tT /dev/nvme1n1p3

/dev/nvme1n1p3:
 Timing cached reads:   32260 MB in  2.00 seconds = 16152.14 MB/sec
 Timing buffered disk reads: 5074 MB in  3.00 seconds = 1691.16 MB/sec

参考资料

2.3 - 爱国者p7000z测试数据

爱国者p7000z 测试数据

硬盘型号 爱国者p7000z,容量 4T , m2 接口 nvme 协议, pcie 4.0 x4, 规格为 2280。

华硕z690 + pve 8

主板为华硕 z690-p d4, m2 接口 pcie 4.0 x4。

安装 ubuntu 20.04 系统,5.4 内核, ext4 格式。

基本信息

$ lspci | grep Volatile

02:00.0 Non-Volatile memory controller: Device 1e4b:1602 (rev 01)

磁盘数据:

$ sudo fdisk -l

Disk /dev/nvme0n1: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors
Disk model: aigo NVMe SSD P7000Z 4TB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: EE02EE97-D530-4107-9D83-6A15532005BA

Device              Start        End    Sectors  Size Type
/dev/nvme0n1p1       2048    1050623    1048576  512M EFI System
/dev/nvme0n1p2    1050624 1074792447 1073741824  512G Linux filesystem
/dev/nvme0n1p3 1074792448 1179650047  104857600   50G Linux filesystem
/dev/nvme0n1p4 1179650048 8001570815 6821920768  3.2T Linux filesystem

测试分区为 nvme0n1p4,分区信息:

$ sudo hdparm /dev/nvme0n1p4

/dev/nvme0n1p4:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 readonly      =  0 (off)
 readahead     = 256 (on)
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 geometry      = 3331016/64/32, sectors = 6821920768, start = 1179650048

速度测试

硬盘写入速度:

$ dd if=/dev/zero of=/mnt/data/share/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 5.96539 s, 1.8 GB/s

只有 1.4 GB,有点低的,p7000z 是 pcie 4.0,按说写入速度应该是5-6GB级别。

持续写入 100G的文件,还是 1.8 GB/秒:

$ dd if=/dev/zero of=/mnt/data/share/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 60.8423 s, 1.8 GB/s

硬盘读取速度(直接以 8M 的 block size 读取 100GB 大文件):

$ dd if=/mnt/data/share/temp/test1.img of=/dev/null bs=8M
                                             
12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 26.7172 s, 4.0 GB/s

4.0GB/s 的速度只能说差强人意,凑合吧。

2.4 - 凯侠cd6测试数据

凯侠cd6 测试数据

硬盘信息

硬盘型号 凯侠cd6,容量 3.84T , u2 接口 nvme 协议, pcie 4.0 x4。

windows 下测试的性能数据:

as-ssd-bench

CrystalDiskMark_20230810091559

华硕z690 + ubuntu 22.04

主板为华硕 z690-p d4, m2 接口 pcie 4.0 x4 转 u2。

安装 linux lint 操作系统,基于 ubuntu 22.04,5.15 内核。

基本信息

$ lspci | grep SSD 

02:00.0 Non-Volatile memory controller: KIOXIA Corporation NVMe SSD Controller Cx6 (rev 01)

磁盘数据:

sudo fdisk -l
Disk /dev/nvme0n1: 3.49 TiB, 3840755982336 bytes, 7501476528 sectors
Disk model: KCD61LUL3T84                            
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: FBEFBE02-9843-4FEC-8B2C-C50B5EAD8069

Device              Start        End    Sectors   Size Type
/dev/nvme0n1p1       2048     206847     204800   100M EFI System
/dev/nvme0n1p2     206848     239615      32768    16M Microsoft reserved
/dev/nvme0n1p3     239616 1047643943 1047404328 499.4G Microsoft basic data
/dev/nvme0n1p4 1047644160 1048813567    1169408   571M Windows recovery environment
/dev/nvme0n1p5 1048815616 2097391615 1048576000   500G Microsoft basic data
/dev/nvme0n1p6 2097391616 7340271615 5242880000   2.4T Microsoft basic data
/dev/nvme0n1p7 7340271616 7501475839  161204224  76.9G Microsoft basic data

测试两个分区,nvme0n1p5 是 ex4 格式(上面的数据有问题) ,nvme0n1p6 是 ntfs 格式,通过 ntfs-3g 读写。

分区信息:

$ sudo hdparm /dev/nvme0n1p5

/dev/nvme0n1p5:
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 512000/64/32, sectors = 1048576000, start = 1048815616

$ sudo hdparm /dev/nvme0n1p6

/dev/nvme0n1p6:
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 2560000/64/32, sectors = 5242880000, start = 2097391616

nvme0n1p5 速度测试

nvme0n1p5 硬盘写入速度:

$ dd if=/dev/zero of=/home/sky/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 7.69088 s, 1.4 GB/s

只有 1.4 GB,低的有点出乎意外,cd6 是 pcie 4.0,按说写入速度应该是5-6GB级别。

持续写入 100G的性能,还是 1.4 GB/秒:

$ dd if=/dev/zero of=/home/sky/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 77.9087 s, 1.4 GB/s

nvme0n1p5 硬盘读取速度:

$ dd if=/home/sky/temp/test1.img of=/dev/null bs=8k

1310720+0 records in
1310720+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 0.681243 s, 15.8 GB/s

15.8 GB 的速度又离谱了,应该是有缓存在。尝试读取 100G 大小:

$ dd if=/home/sky/temp/test1.img of=/dev/null bs=8k
13107200+0 records in
13107200+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 53.4742 s, 2.0 GB/s

每秒2GB的速度还是有点低,离 pcie 4.0 硬盘的标称速度 6-7 GB差距很大,尝试将 bs (block-size)加大到 8M 继续读取这个 100GB的文件:

$ dd if=/home/sky/temp/test1.img of=/dev/null bs=8M
12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 24.9262 s, 4.3 GB/s

4.3 GB/s 就相对比较合理了。

对比

$ sudo hdparm -tT /dev/nvme0n1p5

/dev/nvme0n1p5:
 Timing cached reads:   48164 MB in  2.00 seconds = 24121.05 MB/sec
 Timing buffered disk reads: 7166 MB in  3.00 seconds = 2388.55 MB/sec

nvme0n1p6 速度测试

nvme0n1p6 这个分区是 ntfs 格式。

nvme0n1p6 硬盘写入速度:

$ dd if=/dev/zero of=/media/d/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 29.3955 s, 365 MB/s

只有 365 兆,低的有点出乎意外,应该是 linux 读写 ntfs 格式有速度问题。

nvme0n1p6 硬盘读取速度:

$ dd if=/media/d/temp/test1.img of=/dev/null bs=8k

1310720+0 records in
1310720+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 1.91374 s, 5.6 GB/s

5.6GB 的速度有点偏高,估计还是缓存。尝试读取 100 GB大小的文件:

$ dd if=/dev/zero of=/media/d/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 242.065 s, 444 MB/s

444 MB/s 每秒的速度和前面 ext4 下的 4.3 GB/s 相比,nfts 格式会让磁盘性能下降到 10% ,实在恐怖。所以还是要避免在 linux 下使用 ntfs 格式。

对比

$ sudo hdparm -tT /dev/nvme0n1p6

/dev/nvme0n1p6:
 Timing cached reads:   49004 MB in  2.00 seconds = 24540.33 MB/sec
 Timing buffered disk reads: 7452 MB in  3.00 seconds = 2483.48 MB/sec

2483.48 MB/sec 这个数据完全不真实。

2.5 - 西数sn550测试数据

西数 sn550 测试数据

硬盘型号 西数 sn520,容量 500 GB , m2 接口 nvme 协议, pcie 3.0 x4。

技嘉 x99 + ubuntu 20.04

主板为技嘉 x99 ud4 主板, m2 接口 pcie 3.0 x4。但这个主板自带的 m2 接口速度只有 10G,不是正常满血 pcie 3.0 x4 的 32G。

安装 ubuntu 20.04 操作系统,5.4 内核。

基本信息

$ lspci | grep Non-Volatile 

06:00.0 Non-Volatile memory controller: Sandisk Corp WD Black 2018/PC SN520 NVMe SSD (rev 01)

磁盘数据:

$ sudo fdisk -l

Disk /dev/nvme1n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WDS500G1B0C-00S6U0                  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: AB8D3D88-0124-404E-B1BC-658E567C569D

Device             Start       End   Sectors  Size Type
/dev/nvme1n1p1      2048   1050623   1048576  512M EFI System
/dev/nvme1n1p2   1050624 839911423 838860800  400G Linux filesystem
/dev/nvme1n1p3 839911424 976771071 136859648 65.3G Linux filesystem

测试分区为 nvme1n1p2,分区信息:

$ sudo hdparm /dev/nvme1n1p2

/dev/nvme1n1p2:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 readonly      =  0 (off)
 readahead     = 256 (on)
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 geometry      = 409600/64/32, sectors = 838860800, start = 1050624

速度测试

硬盘写入速度:

$ dd if=/dev/zero of=/home/sky/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 23.3803 s, 459 MB/s

只有 459 MB/s,低的有点出乎意外,虽然是块笔记本用的 ssd 硬盘,但这个速度也没比机械硬盘快多少。

持续写入 100G的性能,还是 454 MB/s:

$ dd if=/dev/zero of=/home/sky/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 236.347 s, 454 MB/s

硬盘读取速度(直接以 8M 的 block size 读取 100GB 大文件):

$ dd if=/home/sky/temp/test1.img of=/dev/null bs=8M

dd if=/home/sky/temp/test1.img of=/dev/null bs=8M
12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 131.35 s, 817 MB/s

817 MB/s ,看来这就是这块硬盘的最大速度了,10G 接口对它而言反而不是瓶颈。

对比

$ sudo hdparm -tT /dev/nvme1n1p2

/dev/nvme1n1p2:
 Timing cached reads:   19496 MB in  1.99 seconds = 9792.62 MB/sec
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 Timing buffered disk reads: 2298 MB in  3.00 seconds = 765.56 MB/sec

765.56 MB/sec 这个数据还比较符合实际测试性能。

总结

这个 sn520 硬盘的性能实在不堪,二手出掉吧。

2.6 - 隐速4TN7000测试数据

隐速4TN7000测试数据

硬盘型号 隐速4TN7000,容量 4T , m2 接口 nvme 协议, pcie 4.0 x4, 规格为 2280。

技嘉x99 ud4 + ubuntu server

主板为技嘉x99 ud4, 通过pcie拆分卡得到了一个 m2 接口 pcie 4.0 x4。

安装 ubuntu 20.04 系统,5.4 内核, ext4 格式。

基本信息

$ lspci | grep Volatile

03:00.0 Non-Volatile memory controller: Device 1e4b:1602 (rev 01)

磁盘数据:

$ sudo fdisk -l

Disk /dev/nvme0n1: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors
Disk model: YSSDHB-4TN7000                          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DA503D82-D785-4A47-A701-504DB1ED256C

Device         Start        End    Sectors  Size Type
/dev/nvme0n1p1  2048 8001573518 8001571471  3.7T Linux filesystem

测试分区为 nvme0n1p1,分区信息:

$ sudo hdparm /dev/nvme0n1p1

/dev/nvme0n1p1:
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 3907017/64/32, sectors = 8001571471, start = 2048

速度测试

硬盘写入速度:

$ sudo dd if=/dev/zero of=/data/temp/test1.img bs=1G count=10 oflag=dsync
10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 11.6533 s, 921 MB/s

只有 0.9 GB,低的离谱,虽然主板限制只能跑pcie 3.0 x4 32G的带宽, 但按说写入速度应该是3-4GB级别,就算打折扣也不应该这么低。参考爱国者p7000z的速度是 1.8GB/秒。

读取速度为 6.6GB/S,这个还行,应该是缓存:

$ dd if=/data/temp/test1.img of=/dev/null bs=8M
1280+0 records in
1280+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 1.62146 s, 6.6 GB/s

持续写入 100G的文件,还是 0.9 GB/秒:

$ sudo dd if=/dev/zero of=/data/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 118.151 s, 909 MB/s

硬盘读取速度(直接以 8M 的 block size 读取 100GB 大文件):

$ dd if=/data/temp/test1.img of=/dev/null bs=8M                           
12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 37.7508 s, 2.8 GB/s

2.8 GB的速度有点低,对比爱国者p7000z 是 4.0GB/s 。

持续写入 1T的文件,还是 0.9 GB/秒,看来缓外速度就真的只有900M了:

$ sudo dd if=/dev/zero of=/data/temp/test-1t.img bs=1G count=1000 oflag=dsync
1000+0 records in
1000+0 records out
1073741824000 bytes (1.1 TB, 1000 GiB) copied, 1221.81 s, 879 MB/s

硬盘读取速度(以 8M 的 block size 读取 1 TB 大文件):

dd if=/data/temp/test-1t.img of=/dev/null bs=8M     
128000+0 records in
128000+0 records out
1073741824000 bytes (1.1 TB, 1000 GiB) copied, 368.641 s, 2.9 GB/s

看来 2.8/2.9G 就是 pcie3 下的无缓存极限速度了。

华硕z690 + windows10

TBD

华硕z690 + ubuntu

TBD

速度参考资料

2.7 - 三星980测试数据

三星 980 测试数据

硬盘信息

硬盘型号 三星980,容量 1 T, m2 接口 nvme 协议, pcie 3.0 x4。

三星官方给到980 1TB的参数为:

  • pcie3.0×4,nvme1.4,HMB无缓设计
  • 最大读:3500MB/s
  • 最大写:3000MB/s
  • 最大随读:50W IOPS
  • 最大随写:48W IOPS

相关资料参考:

技嘉 x99 + ubuntu 20.04

主板为技嘉 x99 ud4 主板, m2 接口 pcie 3.0 x4。

安装 ubuntu 20.04 操作系统,5.4 内核。

基本信息

$ lspci | grep Non-Volatile 

03:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd Device a809

磁盘数据:

$ sudo fdisk -l

Disk /dev/nvme0n1: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 980 1TB                     
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 16384 bytes / 131072 bytes
Disklabel type: gpt
Disk identifier: DB6DCF2B-7BCD-4C10-8B72-B95EF2DD634A

Device         Start        End    Sectors   Size Type
/dev/nvme0n1p1  2048 1953525134 1953523087 931.5G Linux filesystem

测试分区为 nvme0n1p1,分区信息:

$ sudo hdparm /dev/nvme0n1p1

/dev/nvme0n1p1:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 readonly      =  0 (off)
 readahead     = 256 (on)
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 geometry      = 953868/64/32, sectors = 1953523087, start = 2048

速度测试

硬盘写入速度:

$ dd if=/dev/zero of=/mnt/data/share/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 11.9802 s, 896 MB/s

只有 896 MB/s,低的有点出乎意外,这个标称写入速度是3G啊。

持续写入 100G的性能,这次只有 794 MB/s:

$ dd if=/dev/zero of=/mnt/data/share/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 135.252 s, 794 MB/s

硬盘读取速度(直接以 8M 的 block size 读取 100GB 大文件):

$ dd if=/mnt/data/share/temp/test1.img of=/dev/null bs=8M

12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 44.1279 s, 2.4 GB/s

2.4 GB/s ,和宣称的 3G 速度有一点出入,但好在没有离谱。

对比

$ sudo hdparm -tT /dev/nvme0n1p1

/dev/nvme0n1p1:
 Timing cached reads:   20218 MB in  1.99 seconds = 10157.69 MB/sec
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 Timing buffered disk reads: 5302 MB in  3.00 seconds = 1767.28 MB/sec

1767.28 MB/sec 这个数据比实际测试性能(2.4 GB/s)要小一点。

总结

这个 三星 980 硬盘按说是 pcie3.0 中高端硬盘,宣称的读写性能应该在 3 GB这个级别,接近 pcie3.0 x4 32G 的理论带宽。但实际测试下来,读 2.4 GB/s 勉强还能凑合,写 800M 就差的很远。

3 - hdparm命令

Linux hdparm 命令

3.1 - hdparm命令

hdparm 命令用于显示与设定硬盘的参数,还可以测试硬盘的读取速度

介绍

在Linux下可以使用hdparm工具查看硬盘的相关信息或对硬盘进行测速、优化、修改硬盘相关参数设定。

安装

一般 ubutu server 都自带 hdparm 命令,如果没有则通过下面的命令安装:

sudo apt install hdparm

更新,如果遇到 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device 错误:

$ sudo hdparm -tT /dev/nvme0n1p1

/dev/nvme0n1p1:
 Timing cached reads:   20218 MB in  1.99 seconds = 10157.69 MB/sec
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 Timing buffered disk reads: 5302 MB in  3.00 seconds = 1767.28 MB/sec

则需要更新 hdparm 的版本,一般 apt 安装的版本是 v9.58:

$ hdparm -V
hdparm v9.58

最新版本下载地址: https://sourceforge.net/projects/hdparm/

目前最新的版本是 v9.65,下载完成后执行:

tar xvf hdparm-9.65.tar.gz
cd hdparm-9.65
make
sudo make install

查看新安装的版本:

$ hdparm -V
hdparm v9.65

这个时候就不会再出现 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device 的报错了。

实践案例

查看硬盘的相关设置

sudo hdparm /dev/sdb1

输出为:

/dev/sdb1:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 multcount     =  0 (off)
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 401023/255/63, sectors = 6442448863, start = 2048

其中 geometry 的参数解释为:

geometry = 401023[柱面数]/ 255[磁头数]/ 63[扇区数], sectors = 6442448863[总扇区数], start = 2048[起始扇区数]

测试硬盘的读取速度

sudo hdparm -t /dev/sdb1

输出为:

/dev/sdb1:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 Timing buffered disk reads: 9652 MB in  3.00 seconds = 3217.29 MB/sec

测试硬盘缓存的读取速度

sudo hdparm -T /dev/sdb1

输出为:

/dev/sdb1:
 Timing cached reads:   25838 MB in  1.99 seconds = 12959.95 MB/sec

检测硬盘的电源管理模式

sudo hdparm -C /dev/sdb1

输出为:

/dev/sdb1:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 drive state is:  standby

参考资料

3.2 - sandisk sn520的测试结果

sandisk sn520的测试结果

硬盘型号 sandisk sn520,容量 512G, m2 接口 nvme 协议, pcie 3.0 x4。

技嘉x99 + 10G M2

在技嘉 x99 ud4 主板上,m2 接口为 10G 带宽。

物理机安装 ubuntu 20.04 系统, 5.4 内核。

基本信息

$ lspci | grep disk
05:00.0 Non-Volatile memory controller: Sandisk Corp WD Black 2018/PC SN520 NVMe SSD (rev 01)

磁盘数据:

Disk /dev/nvme0n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WDS500G1B0C-00S6U0                  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: AB8D3D88-0124-404E-B1BC-658E567C569D

Device             Start       End   Sectors  Size Type
/dev/nvme0n1p1      2048   1050623   1048576  512M EFI System
/dev/nvme0n1p2   1050624 839911423 838860800  400G Linux filesystem
/dev/nvme0n1p3 839911424 976771071 136859648 65.3G Linux filesystem

分区信息:

sudo hdparm /dev/nvme0n1p3


/dev/nvme0n1p3:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 readonly      =  0 (off)
 readahead     = 256 (on)
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 geometry      = 66826/64/32, sectors = 136859648, start = 839911424

速度测试

读取速度测试:

sudo hdparm -t /dev/nvme0n1p3


/dev/nvme0n1p3:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 Timing buffered disk reads: 2294 MB in  3.00 seconds = 764.43 MB/sec

缓存读取速度测试:

sudo hdparm -T /dev/nvme0n1p3


/dev/nvme0n1p3:
 Timing cached reads:   20412 MB in  1.99 seconds = 10261.23 MB/sec

4 - du命令

Linux fdisk 命令: 展示磁盘使用量的统计信息

du 命令,全称是 disk usage,用来展示磁盘使用量的统计信息。