dd

How to install dd

No need to install, almost all of the linux distributions have this tool, it is included in coreutils package on RHEL and Fedora.

Features and Functions

  • The most simply tool used to test disk performance.
  • Can set non-buffered I/O or buffered I/O to test disk read/write performance.
  • Can set block size for I/O units.

How to use dd

  1. Create a testfile under the disk which you want to test the performance with a proper size
# dd if=/dev/zero of=testfile bs=1M count=20000

Sequential read

  1. Test the sequential read performance with bs=1M and buffered IO
# dd if=testfile of=/dev/null bs=1M conv=fdatasync
  1. Test the sequential read performance with bs=1M and direct IO
# dd if=testfile of=/dev/null bs=1M iflag=direct

Sequential write

  1. Test the sequential write performance with bs=1M and buffered IO
# dd if=/dev/zero of=testfile bs=1M count=20000 conv=fdatasync
  1. Test the sequential write performance with bs=1M and direct IO
# dd if=/dev/zero of=testfile bs=1M count=20000 oflag=direct

Note:
When test buffered I/O, you must specify ‘oflag=sync’ or ‘conv=fdatasync’ option to write data from memory to disk.
For the write performance testing, we can also use ‘oflag=sync’, but this is not recommended. Because sync schedules the writes, but may return before the actual writing is done. But fdatasync will wait untill the data actual write to the disk.

Results analysis

Issue the dd command, command will give some output include throughput.

# dd if=testfile of=/dev/null bs=1M iflag=direct
200+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 0.416249 s, 504 MB/s

209715200 bytes (210 MB) copied, 0.416249 s, 504 MB/s we see the Throughput is 504MB/s, the bigger the better.

The main parameters of dd

Command line options

  • if=FILE - read from FILE instead of stdin
  • of=FILE - write to FILE instead of stdout
  • iflag=FLAGS - FLAGS: direct, sync, dsync
  • oflag=FLAGS - FLAGS: direct, sync, dsync
  • bs=BYTES - read and write up to BYTES bytes at a time(K/M/G)
  • count=N - copy only N input blocks

FLAGS

  • sync - schedules the writes, but may return before the actual writing is done. It will also write the file metadata.
  • dsync - schedules the writes, but may return before the actual writing is done. It only write the file data.
  • fsync - schedules the writes, will wait untill the data actual write to the disk. It also write the file metadata.
  • fdatasync - schedules the writes, will wait untill the data actual write to the disk. It only write the file data.
  • direct - For non-buffered I/O.

Shortcomings

  • Can only test sequential read and sequential write performance.
  • Can only used to test disk performance.

Reference

  • man dd
  • sync, fsync, and the fdatasync function of the difference between
  • How to use ‘dd’ to benchmark your disk or CPU?

你可能感兴趣的:(dd)