HP c-Class Performance Tuning manual Programming using direct I/O, Using direct I/O on Linux

Page 25

Programming using direct I/O

Using direct I/O on Linux

Under Linux, the best way to enable direct I/O is on a per-file basis. This is done by using the O_DIRECT flag to the open() system call. For example, in an application written in C, you might see a line similar to this:

fd = open(filename, O_WRONLY);

To make this file accessible through unbuffered or direct I/O, change the line to the following:

fd = open(filename, O_WRONLY O_DIRECT );

The IO Accelerator requires that all I/O performed on a device using O_DIRECT must be 512-byte aligned and a multiple of 512 bytes in size. Buffers used to read data to and write data from must be page-size aligned.

open(), getpagesize(), and posix_memalign().

The following is a simple application that writes a pattern to the entire IO Accelerator in 1 MiB chunks, using O_DIRECT: Generally, performance can be slightly enhanced by using pwrite instead of write.

#define _XOPEN_SOURCE 600 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #define __USE_GNU #include <fcntl.h> #include <string.h> #define FILENAME "/dev/fiob"

int main( int argc, char **argv)

{

void *buf; int ret = 0;

int ps = getpagesize();

unsigned long long int bytes_written = 0; int fd;

if( (ret = posix_memalign(&buf, ps, ps*256)) ) { perror("Memalign failed");

exit(ret);

}

Programming using direct I/O 25

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