Checking the Disk Access Mode in Linux
If a standard performance test is conducted in a Linux environment, it is recommended that you set the disk access mode to Direct I/O.
Linux has a kernel buffer. The buffered I/O mechanism stores I/O data to the page cache. That is, data is first copied to the buffer of the Linux kernel and then to the address space of the application program. Comparatively, the Direct I/O mechanism enables data to be directly transmitted between the buffer of the user address space and disks without the need to use the page cache.
If you use the Vdbench tool or the dd command to test performance without specifying Direct I/O, Buffered I/O is used by default. The default page cache size employed by Linux is 4 KB. If an I/O is larger than 4 KB, the following issues occur:
- In the kernel buffer, the host splits the I/O. On the block device layer, small I/Os are combined. As a result, the high CPU overheads are required.
- In a high-concurrency scenario, small I/Os may not be combined into large I/Os on the block device layer before being written to disks. As a result, the I/O model is changed, and disks may not be able to provide the maximum bandwidth performance.
Set the disk access mode to Direct I/O as follows:
- When Vdbench is used, set openflags to o_direct in sd.
sd=default,openflags=o_direct,threads=32
- When the dd command is used:
- Set oflag to direct to test the write performance.
dd if=/dev/zero of=/testw.dbf bs=4k oflag=direct count=100000
- Set iflag to direct to test the read performance.
dd if=/dev/sdb of=/dev/null bs=4k iflag=direct count=100000
- Set oflag to direct to test the write performance.