Bug 124626 - mmap use causes kernel panic
mmap use causes kernel panic
Status: CLOSED DUPLICATE of bug 124624
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: kernel (Show other bugs)
i686 Linux
medium Severity high
: ---
: ---
Assigned To: Arjan van de Ven
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2004-05-27 20:48 EDT by ara howard
Modified: 2007-11-30 17:07 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-02-21 14:03:50 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description ara howard 2004-05-27 20:48:14 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.2)

Description of problem:
programs which mmap large files, but in small chunks using offset and
length, in rw mode cause kernel panic

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. create a large file
  [ahoward@harp ahoward]$ dd if=/dev/zero of=1gb bs=8192 count=131072
  131072+0 records in
  131072+0 records out

2. compile this program

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

#define TILE_SIZE 1048576

 * ~ > gcc filemap_bug.c -o filemap_bug
 * ~ > filemap_bug big_file

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

  int ret;
  char *path;
  struct stat buf;
  off_t size, offset, length, tn;
  int fd;
  void *mem;
  unsigned char *start;
  unsigned char *byte;
  int i;

  if (argc < 2)
      fprintf (stderr, "%s huge_input_file\n", __FILE__);
      return (EXIT_FAILURE);

  path = *(argv + 1);
  ret = stat (path, &buf);
  size = buf.st_size;
  fd = open (path, O_RDWR);

  for (offset = 0, tn = 0; offset < size; offset += TILE_SIZE, tn++)
      length = size - offset;
      length = length > TILE_SIZE ? TILE_SIZE : length;
      fprintf (stdout, "<%s>[%d,%d] - tile_number <%d>\n", path,
offset, length, tn);

      mem = mmap (NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, offset);
      start = (unsigned char *)mem;
      madvise (start, length, MADV_SEQUENTIAL);
      for (byte = start; byte - start < length; byte++)
          *byte = 42; 
      msync (start, length, MS_SYNC); 
      munmap (start, length);

  close (fd);
  return (EXIT_SUCCESS);

3. run the program on created file

  ./a.out 1gb

4. watch the kernel panic (for me around tile 140)


Actual Results:  kernel panic

Expected Results:  every byte of the input file == 42

Additional info:
Comment 1 Rik van Riel 2004-05-27 21:42:40 EDT

*** This bug has been marked as a duplicate of 124624 ***
Comment 2 Red Hat Bugzilla 2006-02-21 14:03:50 EST
Changed to 'CLOSED' state since 'RESOLVED' has been deprecated.

Note You need to log in before you can comment on or make changes to this bug.