HP c-Class Performance Tuning manual Using direct I/O on Windows ++ code sample

Page 26

memset(buf, 0xaa, ps*256);

if( (fd = open(FILENAME, O_WRONLY O_DIRECT) ) < 0 ) { perror("Open failed");

exit(ret);

}

bytes_written = 0;

while( (ret = pwrite(fd, buf, ps*256, bytes_written)) == ps*256) { bytes_written += ret;

}

printf("Wrote %lld GB\n", bytes_written/1000/1000/1000); close(fd);

free(buf);

}

Using direct I/O on Windows

Direct I/O on Windows operating systems is set up through the CreateFile() call, using the FILE_FLAG_NO_BUFFERING flag. For more information, see the "CreateFile Function (http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx)" topic on MSDN.

When using direct IO, HP recommends that you keep read, writes, and buffers used for read/write sector size aligned. For a discussion of alignment requirements, see the “File Buffering (http://msdn.microsoft.com/en-us/library/cc644950(VS.85).aspx)” topic on MSDN. The HP IO Accelerator sector size defaults to 512 bytes.

C++ code sample

The following code sample writes to the block device using O_DIRECT. The code sample has a class that encapsulates the operating system file functions that support O_DIRECT.

#include <unistd.h> #include <iostream> #include <errno.h> #include <fcntl.h> using namespace std;

//Short demonstration of a container class that writes using O_DIRECT.

//Compiled using GNU C++.

#define FILENAME "/dev/fioc" class DirectFile

{

public: DirectFile() {}; ~DirectFile() { ::close(fd); };

Programming using direct I/O 26

Image 26
Contents HP IO Accelerator Performance Tuning Guide Page Contents Setting Windows driver affinity About the Performance and Tuning Guide IntroductionSystem performance Verifying Linux system performanceWrite bandwidth test System performance Verifying Windows system performance with Iometer Oversubscribed bus Debugging performance issuesImproperly configured benchmark Handling PCIe errors PCIe link width improperly negotiated CPU thermal throttling or auto-idling Benchmarking through a filesystem Slow performance using RAID5 on LinuxUsing CP and other system utilities To avoid this issue. For more information, see the patch Multiple outstanding IOs General tuning techniquesUsing direct I/O, unbuffered, or zero copy Pre-conditioning $ dd if=/dev/zero of=/dev/fioX bs=10M oflag=directPre-allocating memory $ echo 4096 /sys/block/fio name/queue/nrrequestsPreallocatemb Tuning techniques for writes Increased steady-state write performance with fio-formatStride = chunk size / filesystem block size Linux filesystem tuningExt2-3-4 tuning Stripewidth = dbd * strideUsing the IO Accelerator as swap space Options iomemory-vsl preallocatememory=1072,4997,6710,10345$ tar xjvf fio-X.Y.Z.tar.bz2 $ cd fio-X.Y.Z Fio benchmarkCompiling the fio benchmark Page Fd = openfilename, Owronly Programming using direct I/OUsing direct I/O on Linux Fd = openfilename, Owronly OdirectUsing direct I/O on Windows ++ code sample Programming using direct I/O Programming using direct I/O Setting Windows driver affinity Windows driver affinityCreate the SetWorkerAffinity2 tag of type Regdword Acronyms and abbreviations Index Index