Linux and Unix Test Disk I/O Performance with DD Command

The DD command is a powerful command-line utility in Linux and Unix systems that can test hard disk I/O performance by measuring read and write speeds. This article demonstrates how to use DD command to benchmark your storage device performance effectively.

What is DD Command?

DD is a command-line utility for Unix and Unix-like operating systems where the primary purpose is to copy and convert files. It reads from an input source and writes to an output destination, making it ideal for disk performance testing by creating controlled I/O operations.

Testing Write Performance

Open your Linux terminal and run the following command to test write speed −

$ sudo dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync

Expected output −

tp@linux:~$ sudo dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync
[sudo] password for tp:
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 11.9635 s, 89.8 MB/s

This test writes 1GB of data and shows a throughput of 89.8 MB/s for the write operation.

Understanding DD Command Parameters

Parameter Description
if=/dev/zero Input file source (here, /dev/zero generates null bytes)
of=/tmp/test1.img Output file destination where data will be written
bs=1G Block size for each read/write operation (1 Gigabyte)
count=1 Number of blocks to process
oflag=dsync Forces synchronous I/O for more accurate timing
oflag=direct Bypasses system cache for direct disk access

Testing Read Performance

First, clear the system cache to get accurate read performance results −

$ echo 3 | sudo tee /proc/sys/vm/drop_caches

Then test read speed using an existing file −

$ dd if=/tmp/test1.img of=/dev/null bs=1G count=1

Testing With and Without Cache

With Direct I/O (Bypass Cache)

Run the following command to test performance without cache interference −

$ dd if=/dev/zero of=/tmp/laptop.bin bs=1G count=1 oflag=direct
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 11.4265 s, 94.0 MB/s

Disabling Drive Cache

To disable the hard drive's internal write cache for more accurate results −

$ sudo hdparm -W0 /dev/sda
/dev/sda:
setting drive write-caching to 0 (off)
write-caching = 0 (off)

After disabling cache, rerun the test −

1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 11.5062 s, 93.3 MB/s

Key Points

  • Use oflag=dsync for synchronous writes that reflect real-world performance

  • Use oflag=direct to bypass system cache and test actual disk speed

  • Clear cache with /proc/sys/vm/drop_caches before read tests

  • Larger block sizes (like 1G) provide more accurate throughput measurements

  • Test results show both data transferred and transfer rate in MB/s

Conclusion

The DD command provides a simple yet effective method to benchmark disk I/O performance on Linux systems. By using different flags like dsync and direct, you can measure both cached and uncached performance to understand your storage device's true capabilities.

Updated on: 2026-03-17T09:01:38+05:30

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements