Explanation of dd command instances in CentOS
When talking about the dd commands in linux, many technical bloggers are familiar with the usage. Today I will share with you several methods to test the hard disk read/write speed.
When we have no suitable hard disk I/O testing tool at hand, dd is our best choice. Let's take a closer look at the four methods of line and plane. Where is the difference?
Dd bs = 1 M count = 128 if =/dev/zero of = test
Dd bs = 1 M count = 128 if =/dev/zero of = test_01; sync
Dd bs = 1 M count = 128 if =/dev/zero of = test_02 conv = fdatasync
Dd bs = 1 mcount = 128 if =/dev/zero of = test_03 oflag = dsync
Did you think of it? Here: the difference lies in the processing method of writing cache in memory.
# ---------------------- Graphic analysis is as follows ----------------------------#
First:
Dd bs = 4 M count = 1024 if =/dev/zero of = test
No parameters are added. The default dd method does not include the "sync" command. That is to say, before the dd command is completed, the system did not actually write the file to the disk. Therefore, the above command simply reads the mb data into the memory buffer (write cache [write cache]). So what you get is a super fast speed. In fact, dd only gives you the read speed, and the system does not actually write data to the disk until dd is complete, but you cannot see this speed. So if this speed is fast, don't be happy first. Haha
Second:
Dd bs = 4 M count = 1024 if =/dev/zero of = test_01
It is exactly the same as in previous 1. Only two independent commands are separated by semicolons. When the sync command is ready to write data to the disk, the previous dd command has displayed the incorrect "write speed" value on the screen. So you still cannot get the real write speed.
Third:
Dd bs = 4 M count = 1024 if =/dev/zero of = test_02 conv = fdatasync
After this parameter is added, the dd command will actually execute a "sync" operation until the end, so what you get at this time is the time required to read the M data to the memory and write it to the disk. The calculated time is more realistic.
Fourth:
Dd bs = 4 M count = 1024 if =/dev/zero of = test_03 oflag = dsync
After this parameter is added, dd performs synchronous write operations every time it is executed. That is to say, this command writes the 1 M to the disk every time it reads the 1 M, and then reads the following 1 M, repeating 128 times. This may be the slowest way, because write cache is basically not used ).
Which of the following is the most useful:
Dd bs = 4 M count = 1024 if =/dev/zero of = test_02conv = fdatasync
Because this method is the closest to the actual operation of the computer, the data tested has the most reference value.