[parisc-linux] unreliable mmap

Jochen Friedrich jochen@scram.de
Thu, 24 Oct 2002 01:01:42 +0200 (CEST)


Hi,

> i recognized that mmap operations seem unreliable on HP720 platform. The
> following test program (taken from cyrus imap configure) demonstrates the
> problem:
> [...]
>
> This only seems to happen on 720 (i couldn't replicate the bug on a 715
> with the same kernel booted up).

While debugging cyrus21-imapd, i experienced pretty fishy behaviour
of the skiplist database backend. It turned out that the 715 is affected
by the mmap problem, as well.

Here is a new test program which performs random writes to a file and
verifies the mmapped memory afterwards which demonstrates the problem:

Cheers,
--jochen

-------------------------------------8<-------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
  char *base;
  int fd;
  char buf[2000];
  int i, j;
  char c;

  for (i=0; i<2000; i++)
    {
      c = (char) ((float) rand() / (float) (RAND_MAX) * 26) + 'a';
      buf[i] = c;
    }

  fd = open("mmap.test", O_CREAT|O_TRUNC|O_RDWR, 0664);
  write(fd, buf, 2000);

  base = (char *)mmap((caddr_t)0, 2000, PROT_READ, MAP_SHARED
#ifdef MAP_FILE
| MAP_FILE
#endif
#ifdef MAP_VARIABLE
| MAP_VARIABLE
#endif
  , fd, 0L);

  for (i=0; i<2000; i++)
    {
      j = (int) ((float) rand() / (float) (RAND_MAX) * 2000);
      c = (char) ((float) rand() / (float) (RAND_MAX) * 26) + 'a';
      lseek(fd, j, SEEK_SET);
      write(fd, &c, 1);
      if (*(base+j) != c)
        printf("Error: mmap inconsistent at %d\n", j);
    }
  close(fd);
}