[Original] dd command for disk test and description of conv and oflag parameters

Use the dd command to perform disk read and write tests, and everyone may have done it, especially when testing VPS disk performance.

For a detailed description of this command and its parameters, please check the manual (execute the following command):
info coreutils 'dd invocation'
If you are running the disk performance test, use the following command:
dd if=/dev/zero of=test bs=64k count=4k
So, please continue to read this article. Because the test results are not accurate.

Now let's review the following two common commands:

Simulate database insertion operations (a small amount of data is frequently written to test) :
dd if=/dev/zero of=test bs=64k count=4k oflag=dsync
Big data continuous write test :
dd if=/dev/zero of=test bs=8k count=256k conv=fdatasync
先介绍下 conv 参数 CONVS 的含义:
‘fdatasync’
  Synchronize output data just before finishing.  This forces a
  physical write of output data.

‘fsync’
  Synchronize output data and metadata just before finishing.
  This forces a physical write of output data and metadata.

这两个参数的区别就在于是否写入元数据。

再介绍下 oflag 参数 FLAGS 的含义:
‘dsync’
  Use synchronized I/O for data.  For the output file, this
  forces a physical write of output data on each write.  For the
  input file, this flag can matter when reading from a remote
  file that has been written to synchronously by some other
  process.  Metadata (e.g., last-access and last-modified time)
  is not necessarily synchronized.

'sync'
  Use synchronized I/O for both data and metadata.

The difference between these two parameters is also whether to write metadata.

After reading the parameter description, let's talk about the above two lines of commands. These two lines of commands both test the disk write performance, but it takes a long time to execute the first command (the following test data comes from me Free EC2 server on AWS. OS: RHEL7.3 64bit):
$ dd if=/dev/zero of=test bs=64k count=4k oflag=dsync
4096+0 reads recorded
Recorded 4096+0 writes out
268435456 bytes (268 MB) copied, 48.6814 seconds, 5.5 MB/sec
$ dd if=/dev/zero of=test bs=8k count=256k conv=fdatasync
262144+0 reads recorded
Recorded write outs of 262144+0
2147483648 bytes (2.1 GB) copied, 41.277 sec, 52.0 MB/sec
We will find that the first line of command is executed, only 268 MB of data is generated, but it takes 48+ seconds.
After the second line of command is executed, although 2.1GB of data is generated, which is much larger than the data generated by the first line of command, the time is only 41+ seconds, but it takes less time.
why?

Please pay attention to the oflag=dsync parameter. This parameter indicates that whenever data needs to be written, it will actually be written to the disk. After writing to the disk, the next data writing will continue. The first line of command requires to write 4k times of data repeatedly, that is to say, it will actually write 4k times to the disk, and the time is taken for granted.

In the second line of command, although a total of 2.1 GB of data needs to be written, because the conv=fdatasync parameter is used, that is to say, before the dd command ends, all data is written to the disk at one time, so the writing speed is very fast.

Let's do another test, or use the above two commands, the parameters are the same, the only difference is that the count parameter is set to 1, and the bs is set to 256 MB. Then according to the previous description, we can speculate that the results of the two tests should be similar.
$ dd if=/dev/zero of=test bs=256MB count=1 oflag=dsync
1+0 reads recorded
Recorded the write out of 1+0
256000000 bytes (256 MB) copied, 3.85186 seconds, 66.5 MB/sec
$ dd if=/dev/zero of=test bs=256MB count=1 conv=fdatasync
1+0 reads recorded
Recorded the write out of 1+0
256000000 bytes (256 MB) copied, 4.23802 seconds, 60.4 MB/sec

Reference address:
http://www.hostloc.com/thread-256990-1-1.html
http://blog.csdn.net/menogen/article/details/38059671

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326313311&siteId=291194637