« APT configuration filesInstallation des vmware-tools sous Debian Lenny/Testing »

Linux and 4096-Byte Sector Hard Drives

14.02.10

Permalink 11:07:47 pm, by mazet Email , 189 words   English (US) latin1
Categories: Systeme

Linux and 4096-Byte Sector Hard Drives

New hard drives uses 4k-byte sector but devices cheat on linux and say that they're using 512-byte sector as usual. If partitions are not aligned to 8 blocks, there's a huge throughput degradation. Use the 'expert' menu [x] on fdisk to move beginning of data in a partition [b] and align it to 8 blocks.

Test program:

#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

#define N 4096
char buffer[N];

int main(int argc, char *argv[])
{
  int fd, i, j;

  char *file = "test.dat";
  int size = 2048;

  printf ("usage: %s <file> <#blocs>\n", argv[0]);
  if (argc > 1) file = argv[1];
  if (argc > 2) size = atoi (argv[2]);

  fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC);
  printf ("open %s (fd=%d)\n", file, fd);
  if (fd <= 0) return 1;

  printf ("write %dx%d=%d data\n", size, N, size * N);
  for (i = 0; i < size; i++) {
    int rand = random ();
    for (j = 0; j < N; j++, rand = (rand << 1) ^ (rand >> sizeof (int)))
      buffer[j] ^= rand;
    write(fd, buffer, N);
  }
 
  close(fd);

  return 0;        
}