HP IO Accelerator for BladeSystem c-Class Performance Tuning Manual do Utilizador Página 25

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 33
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 24
Programming using direct I/O 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);
}
Vista de página 24
1 2 ... 20 21 22 23 24 25 26 27 28 29 30 31 32 33

Comentários a estes Manuais

Sem comentários