我尝试测试一些 SSD 的写入速度,直接写入磁盘时比格式化为 ext4 时写入磁盘要慢。这是如何运作的?这是正确的还是我测量的结果有误?
for i in {1..5}; do dd if=/dev/zero of=/dev/sda1 bs=1G count=1 oflag=dsync; done
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 7.18148 s, 150 MB/s
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 7.18312 s, 149 MB/s
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 7.1938 s, 149 MB/s
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 7.15976 s, 150 MB/s
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 7.2125 s, 149 MB/s
如果我现在将磁盘格式化为 ext4
mkfs.ext4 /dev/sda1
mount /dev/sda1 /tmp/test
mount -ls
/dev/sda1 on /tmp/test type ext4 (rw,relatime,data=ordered)
for i in {1..5}; do dd if=/dev/zero of=/tmp/test/test.txt bs=1G count=1 oflag=dsync; done
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 4.66437 s, 230 MB/s
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 4.60112 s, 233 MB/s
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 4.58899 s, 234 MB/s
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 4.61334 s, 233 MB/s
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 4.60241 s, 233 MB/s
谢谢
约翰内斯
编辑:当像frostschutz建议的那样激活/proc/sys/vm/block_dump然后复制到ext4驱动器时,很明显数据被内核以不同的方式分割。
for i in {1..5}; do dd if=/dev/zero of=/tmp/test/test.txt bs=1G count=1 oflag=dsync; done
[ 922.895200] dd(2571): READ block 74112 on unknown-block(8,0) (8 sectors)
[ 922.903712] dd(2571): READ block 8448 on unknown-block(8,0) (8 sectors)
[ 923.724470] dd(2571): dirtied inode 12 (test.txt) on sda
[ 923.729762] dd(2571): dirtied inode 12 (test.txt) on sda
[ 923.735005] dd(2571): dirtied inode 12 (test.txt) on sda
[ 924.543323] kworker/u8:0(2560): READ block 8320 on unknown-block(8,0) (8 sectors)
[ 924.553112] kworker/u8:0(2560): WRITE block 278528 on unknown-block(8,0) (2048 sectors)
[ 924.561496] kworker/u8:0(2560): WRITE block 280576 on unknown-block(8,0) (2048 sectors)
[ 924.570013] kworker/u8:0(2560): WRITE block 282624 on unknown-block(8,0) (2048 sectors)
[ 924.578534] kworker/u8:0(2560): WRITE block 284672 on unknown-block(8,0) (2048 sectors)
for i in {1..5}; do dd if=/dev/zero of=/dev/sda bs=1G count=1 oflag=dsync; done
[ 1504.428021] kworker/u8:0(2560): WRITE block 0 on unknown-block(8,0) (8 sectors)
[ 1504.435320] kworker/u8:0(2560): WRITE block 8 on unknown-block(8,0) (8 sectors)
[ 1504.442589] kworker/u8:0(2560): WRITE block 16 on unknown-block(8,0) (8 sectors)
[ 1504.449955] kworker/u8:0(2560): WRITE block 24 on unknown-block(8,0) (8 sectors)
[ 1504.457342] kworker/u8:0(2560): WRITE block 32 on unknown-block(8,0) (8 sectors)
[ 1504.464720] kworker/u8:0(2560): WRITE block 40 on unknown-block(8,0) (8 sectors)
答案1
mkfs
TRIM/丢弃整个器件,从而提供最佳基准条件。
另外,在/proc/sys/vm/block_dump
启用(警告 - 大量输出)的情况下,我看到 8 个扇区的写入(原始块设备上的 dd)与 16384 个扇区的写入(ext4 上的 dd),因此这可能是由于内核决定如何分割内容所致因为你不能真正发送 1G 块写入?
ext4 上的 dd:
dd(12080): dirtied inode 12 (test.txt) on loop0
dd(12080): dirtied inode 12 (test.txt) on loop0
dd(12080): dirtied inode 12 (test.txt) on loop0
kworker/u8:4(10318): READ block 2056 on loop0 (8 sectors)
kworker/u8:4(10318): WRITE block 278528 on loop0 (16384 sectors)
kworker/u8:4(10318): WRITE block 294912 on loop0 (16384 sectors)
kworker/u8:4(10318): WRITE block 311296 on loop0 (16384 sectors)
kworker/u8:4(10318): WRITE block 327680 on loop0 (16384 sectors)
kworker/u8:4(10318): WRITE block 344064 on loop0 (16384 sectors)
kworker/u8:4(10318): WRITE block 360448 on loop0 (16384 sectors)
...
直接dd:
dd(12116): WRITE block 0 on loop0 (8 sectors)
dd(12116): WRITE block 8 on loop0 (8 sectors)
dd(12116): WRITE block 16 on loop0 (8 sectors)
dd(12116): WRITE block 24 on loop0 (8 sectors)
dd(12116): WRITE block 32 on loop0 (8 sectors)
dd(12116): WRITE block 40 on loop0 (8 sectors)
dd(12116): WRITE block 48 on loop0 (8 sectors)
dd(12116): WRITE block 56 on loop0 (8 sectors)
dd(12116): WRITE block 64 on loop0 (8 sectors)
dd(12116): WRITE block 72 on loop0 (8 sectors)
dd(12116): WRITE block 80 on loop0 (8 sectors)
dd(12116): WRITE block 88 on loop0 (8 sectors)
dd(12116): WRITE block 96 on loop0 (8 sectors)
dd(12116): WRITE block 104 on loop0 (8 sectors)
dd(12116): WRITE block 112 on loop0 (8 sectors)
dd(12116): WRITE block 120 on loop0 (8 sectors)
dd(12116): WRITE block 128 on loop0 (8 sectors)
...
现在我只测试了循环设备,而不是真正的SSD,所以......它可能不准确。