我有一个外部硬盘 (不是固态硬盘),它报告:
Sector Sizes: 512 bytes logical, 4096 bytes physical
我应该使用 --sector-size 512
还是 --sector-size 4096
使用cryptosetup LuksFormat
?使用默认参数(不确定它是否会尝试自动检测或始终使用 512)最终得到 512。
如果重要的话,设置将是[disk]->[gpt]->[physical partition]->[LUKSv2]->[btrfs]
继续使用这两种方式来收集基准:
512
# sysbench fileio prepare
2147483648 bytes written in 34.28 seconds (59.75 MiB/sec).
# sysbench fileio --file-test-mode=rndrw run
Extra file open flags: (none)
128 files, 16MiB each
2GiB total file size
Block size 16KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...
Threads started!
File operations:
reads/s: 14.42
writes/s: 9.62
fsyncs/s: 31.25
Throughput:
read, MiB/s: 0.23
written, MiB/s: 0.15
General statistics:
total time: 12.4778s
total number of events: 562
Latency (ms):
min: 0.00
avg: 17.84
max: 365.73
95th percentile: 84.47
sum: 10024.98
Threads fairness:
events (avg/stddev): 562.0000/0.00
execution time (avg/stddev): 10.0250/0.00
# sysbench fileio --file-test-mode=seqrewr run
Extra file open flags: (none)
128 files, 16MiB each
2GiB total file size
Block size 16KiB
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing sequential rewrite test
Initializing worker threads...
Threads started!
File operations:
reads/s: 0.00
writes/s: 815.93
fsyncs/s: 1045.19
Throughput:
read, MiB/s: 0.00
written, MiB/s: 12.75
General statistics:
total time: 10.0488s
total number of events: 18576
Latency (ms):
min: 0.00
avg: 0.54
max: 433.66
95th percentile: 0.02
sum: 9996.57
Threads fairness:
events (avg/stddev): 18576.0000/0.00
execution time (avg/stddev): 9.9966/0.00
4096年
# sysbench fileio prepare
2147483648 bytes written in 28.85 seconds (70.99 MiB/sec).
# sysbench --test=fileio --file-test-mode=rndrw run
File operations:
reads/s: 26.17
writes/s: 17.45
fsyncs/s: 58.35
Throughput:
read, MiB/s: 0.41
written, MiB/s: 0.27
General statistics:
total time: 11.4636s
total number of events: 1041
Latency (ms):
min: 0.00
avg: 9.63
max: 370.49
95th percentile: 44.98
sum: 10021.97
Threads fairness:
events (avg/stddev): 1041.0000/0.00
execution time (avg/stddev): 10.0220/0.00
# sysbench fileio --file-test-mode=seqrewr run
File operations:
reads/s: 0.00
writes/s: 1229.02
fsyncs/s: 1574.44
Throughput:
read, MiB/s: 0.00
written, MiB/s: 19.20
General statistics:
total time: 10.0071s
total number of events: 27929
Latency (ms):
min: 0.00
avg: 0.36
max: 471.49
95th percentile: 0.02
sum: 9997.75
Threads fairness:
events (avg/stddev): 27929.0000/0.00
execution time (avg/stddev): 9.9978/0.00
对于人工小文件,4K 的读取速度似乎快两倍,写入速度快 0.25 倍。
另一次编辑。进行了同样的测试,但复制了 110G 的文件包,大小从 2.5Mb(95%tile)到 300Mb 不等。
512 和 4096 格式化驱动器均耗时 20 分 30 秒 +-4 秒
具有 4K 扇区但报告 512 字节逻辑扇区的磁盘称为“高级格式”(AF) 驱动器。它们模拟512 字节扇区。但它们以低效的方式执行此操作;例如,要写出 512 字节扇区,驱动器必须读取现有的 4k 数据,更新必要的数据,然后写出结果。这是一个额外的“读取”步骤,如果写出 4K 扇区,则不需要此步骤。
您可以在测试中看到结果;4K 测试速度要快得多。
注意,这也适用于对磁盘进行分区
fdisk
;确保您的分区是 4K 对齐的,否则操作系统的每次写入都可能影响 2 个扇区! 类似工具会警告这种错位。使用 4K 扇区的缺点是,您最终可能会失去有用的空间;例如,如果您创建一个 300 字节的文件,它将占用磁盘上的 4K,而使用 512 字节扇区则仅占用 512 字节。我认为这是速度优势的公平权衡。
因此,对于您而言,我会使用带有 cryptsetup 的 4K 扇区。