Use the dd command to check hard disk I/O performance
How can I use the dd command to test my hard disk performance? In linux, how does one check the read/write speed of a hard disk?
You can use the following command to perform a simple I/O performance test on a Linux or Unix-like operating system.
- Dd command: it is used to test the Write Performance of hard disk devices in Linux and Unix-like systems.
- Hparm command: it is used to obtain or set hard disk parameters on a Linux-based system, including testing read performance and cache performance.
In this guide, you will learn how to use the dd command to test the hard disk performance.
Linux/UNIX: Use the dd command to create a 1 GB binary
Use the DD command in Linux to test the read/write speed of USB and SSD hard disks.
Brief Introduction to Linux dd commands
Use the dd command to monitor the read/write performance of the hard disk:
- Open the shell terminal.
- Or log on to the remote server through ssh.
- Use the dd command to measure the server throughput (write speed)
dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync
- Use the dd command to measure server latency
dd if=/dev/zero of=/tmp/test2.img bs=512 count=1000 oflag=dsync
Understanding dd Command Options
In this example, I will use a RAID-10 (Adaptec 5405Z with SAS SSD) server array running the Ubuntu Linux 14.04 LTS system. The basic syntax is:
dd if=/dev/input.file of=/path/to/output.file bs=block-size count=number-of-blocks oflag=dsync
# GNU dd syntax ##
dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync
# Another GNU dd syntax ##
dd if=/dev/zero of=/tmp/testALT.img bs=1G count=1 conv=fdatasync
Output example:
Figure 01 server throughput obtained using the dd command
Please note that in this experiment, we write a G data and we can find that the server throughput is 135 MB/s, where
if=/dev/zero(If =/dev/input. file): used to set the input file name read by the dd command.
of=/tmp/test1.img(Of =/path/to/output. file): name of the output file written by the dd command to input. file.
bs=1G(Bs = block-size): set the size of the block read by the dd command. In this example, 1G is used.
count=1(Count = number-of-blocks): number of blocks read by the dd command.
oflag=dsync(Oflag = dsync): use synchronous I/O. Do not omit this option. This option can help you remove the impact of caching, so as to present accurate results to you.
conv=fdatasyn: This option andoflag=dsyncThe meaning is the same.
In the following example, a total of 1000 write times are written, and 512 bytes are written each time to obtain the delay time of the RAID10 Server:
dd if=/dev/zero of=/tmp/test2.img bs=512 count=1000 oflag=dsync
Output example:
1000+0 records in
1000+0 records out
512000 bytes (512 kB) copied,0.60362 s,848 kB/s
Note that the server throughput and delay time also depend on the server/application load. Therefore, we recommend that you run the test on a server that has just been restarted and has been in peak time for more accurate measurement. Now you can compare the test results on all your devices.
Why is the server throughput and latency so bad?
A low value does not mean you are using poor hardware. It may be caused by the Controller cache of hardware raid 10.
Use the hdparm command to view the read speed of the hard disk cache.
I suggest you run the following command for 2-3 times to check the read performance of the device for reference and mutual comparison:
### Test the read performance of cached hard disks --/dev/sda ###
hdparm -t /dev/sda1
##Or ##
hdparm -t /dev/sda
Then run the following command 2-3 times to check the cache read performance:
# Cache read benchmark --/dev/sda ###
hdparm -T /dev/sda1
##Or ##
hdparm -T /dev/sda
Or simply combine the two tests:
hdparm -Tt/dev/sda
Output example:
Figure 02: Linux hdparm command used to check hard disk reading and cache Performance
Please note again that due to the cache attribute of file operations, you will always see a high read speed.
Run the dd command to test the read speed.
To obtain accurate read test data, first run the following command before the test to set the cache to invalid:
flush
echo 3| sudo tee /proc/sys/vm/drop_caches
time time dd if=/path/to/bigfile of=/dev/null bs=8k
Notebook example
Run the following command:
### Debian system laptop throughput with Cache ###
dd if=/dev/zero of=/tmp/laptop.bin bs=1G count=1 oflag=direct
### Invalidate cache ###
hdparm -W0 /dev/sda
### Debian laptop throughput without Cache ###
dd if=/dev/zero of=/tmp/laptop.bin bs=1G count=1 oflag=direct
For more details, please continue to read the highlights on the next page: