HP c-Class Performance Tuning manual Programming using direct I/O

Page 27

int open(char* filename);

int write(char* buf, int size_t); int close();

size_t gbytesWritten() { return bytes_written / 1000 / 1000 / 1000; } private:

int fd;

size_t bytes_written; };

int DirectFile::open(char* filename) { int ret = 0;

fd = ::open(filename, O_DIRECT O_WRONLY, S_IRUSR S_IWUSR S_IRGRP); if( fd == -1 ) {

ret = -1;

}

bytes_written = 0; return ret;

}

int DirectFile::write(char* buf, int bufsize) {

int written = pwrite(fd, buf, bufsize, bytes_written); if( written >= 0 )

bytes_written += written; return written;

}

int main( int argc, char **argv) { char* buf;

int ret = 0; enum { numpages = 256, };

int pagesize = getpagesize();

int bufsize = pagesize * numpages;

if( ret = posix_memalign((void**)&buf, pagesize, bufsize) ) { cerr << "Memalign failed" << endl;

exit(ret);

}

memset(buf, 0xaa, bufsize); DirectFile file;

if( file.open(FILENAME) ) {

cerr << "Open of " << FILENAME << " failed" << endl;

Programming using direct I/O 27

Image 27
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 Debugging performance issues Improperly configured benchmarkOversubscribed bus Handling PCIe errors PCIe link width improperly negotiated CPU thermal throttling or auto-idling Slow performance using RAID5 on Linux Using CP and other system utilitiesBenchmarking through a filesystem To avoid this issue. For more information, see the patch General tuning techniques Using direct I/O, unbuffered, or zero copyMultiple 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 writesStripewidth = dbd * stride Linux filesystem tuningExt2-3-4 tuning Stride = chunk size / filesystem block sizeOptions iomemory-vsl preallocatememory=1072,4997,6710,10345 Using the IO Accelerator as swap spaceFio benchmark Compiling the fio benchmark$ tar xjvf fio-X.Y.Z.tar.bz2 $ cd fio-X.Y.Z Page Fd = openfilename, Owronly Odirect Programming using direct I/OUsing direct I/O on Linux Fd = openfilename, OwronlyUsing 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