我买了一张Highpoint a HBA卡,里面有4 block 三星960PRO。官方网站说这张卡的写入速度为7500MB/s,读取速度为13000MB/s。
当我在ubuntu 16.04系统中使用fio测试这张卡时,我的写入速度约为7000MB/s,这是我的测试参数:
sudo fio -filename=/home/xid/raid0_dir0/fio.test -direct=1 -rw=write -ioengine=sync -bs=2k -iodepth=32 -size=100G -numjobs=1 -runtime=100 -time_base=1 -group_reporting -name=test-seq-write
我在卡中制作了raid0并制作了xfs文件系统。如果我想在控制台应用程序中使用“open(),read(),write()”等函数或“fopen(),fread(),fwrite()”等函数,我想知道如何实现与fio一样高的磁盘写入速度。
最佳答案
我只是注意到 fio
您指定的工作似乎有点缺陷:
-direct=1 -rw=write -ioengine=sync -bs=2k -iodepth=32
(为了简单起见,我们假设破折号实际上是双的)
上面的请求试图要求同步 ioengine 使用 iodepth
大于一的。这通常没有意义, iodepth
section of the fio documentation warns about this :
iodepth=int
Number of I/O units to keep in flight against the file. Note that increasing iodepth beyond 1 will not affect synchronous ioengines (except for small degrees when verify_async is in use). Even async engines may impose OS restrictions causing the desired depth not to be achieved. [emphasis added]
您没有发布 fio 输出,因此我们无法判断您是否实现了大于 1 的 iodepth。 7.5GByte/s 对于这样的工作来说似乎很高,我不禁认为你的文件系统悄悄地在你背后进行了缓冲,但谁知道呢?我不能说更多,因为恐怕你 fio run 的输出不可用。
另请注意 data fio was writing might not have been random enough to defeat compression从而帮助实现人为的高 I/O 速度...
不管怎样,你的主要问题是:
how to achieve disk write speed as high as fio does?
您的示例显示您正在告诉 fio 使用 ioengine that does regular write
calls 。考虑到这一点,理论上您应该能够通过以下方式达到类似的速度:
- 预分配文件并仅写入已分配的部分(因此您不会进行扩展写入)
- 满足使用
O_DIRECT
的所有要求(必须满足严格的内存对齐和大小限制) - 确保您的
write
操作正在以 2048 字节(或更大,只要它们是 2 的幂)的 block 写入缓冲区。 - 正在提交您的
write
尽快:-)
您可能会发现没有使用O_DIRECT
如果由于某种原因您无法每次都提交“大”且对齐良好的缓冲区(从而允许缓冲 I/O 进行合并)会更好。
关于linux - 如何让磁盘写入速度达到fio一样高?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53553945/