Subject: Re: munmap(2) fails on previously mmaped large files
To: None <current-users@netbsd.org>
From: Christos Zoulas <christos@astron.com>
List: current-users
Date: 05/11/2007 20:55:17
In article <20070511190844.GA373397@medusa.sis.pasteur.fr>,
Nicolas Joly  <njoly@pasteur.fr> wrote:
>-=-=-=-=-=-
>
>
>Hi,
>
>I just encountered a problem where munmap(2) fails for large files
>that were successfully mmaped ...
>
>njoly@lanfeust [embl/blastwu]> uname -a
>NetBSD lanfeust.sis.pasteur.fr 4.99.19 NetBSD 4.99.19 (LANFEUST_DEVEL)
>#156: Thu May 10 11:15:46 CEST 2007 
>njoly@lanfeust.sis.pasteur.fr:/local/src/NetBSD/obj/amd64/sys/arch/amd64/compile/LANFEUST_DEVEL amd64
>
>njoly@lanfeust [embl/blastwu]> ls -l embl.*
>-rw-r--r--  1 997  997  12882733250 May  9 00:17 embl.xnd
>-rw-r--r--  1 997  997  42205936685 May  9 00:17 embl.xns
>-rw-r--r--  1 997  997    914661870 May  9 00:17 embl.xnt
>
>njoly@lanfeust [embl/blastwu]> ~/mmap ./embl.xnt 
>njoly@lanfeust [embl/blastwu]> ~/mmap ./embl.xnd
>mmap: munmap failed: Invalid argument
>njoly@lanfeust [embl/blastwu]> ~/mmap ./embl.xns
>mmap: munmap failed: Invalid argument
>
>Here follow the ktrace output for the last command:
>
>  8950      1 mmap     CALL  open(0x7f7fffffed19,0,0x7f7fffffeba0)
>  8950      1 mmap     NAMI  "./embl.xns"
>  8950      1 mmap     RET   open 3
>  8950      1 mmap     CALL  __fstat30(3,0x7f7fffffeaa0)
>  8950      1 mmap     RET   __fstat30 0
>  8950      1 mmap     CALL  mmap(0,0x9d3ab7c2d,1,1,3,0,0)
>  8950      1 mmap     RET   mmap 140145487806464/0x7f762a048000
>  8950      1 mmap     CALL  munmap(0x7f762a048000,0x9d3ab7c2d)
>  8950      1 mmap     RET   munmap -1 errno 22 Invalid argument
>
>Thanks in advance.
>
>NB: Just in case, this is a NFS mounted directory.
>
>-- 
>Nicolas Joly
>
>Biological Software and Databanks.
>Institut Pasteur, Paris.
>
>-=-=-=-=-=-
>
>
>#include <sys/mman.h>
>#include <sys/stat.h>
>
>#include <err.h>
>#include <errno.h>
>#include <fcntl.h>
>#include <stdio.h>
>#include <unistd.h>
>
>int main(int argc, char **argv) {
>  int i, f;
>  void *v;
>  struct stat st;
>
>  if (argc != 2) {
>    errx(1, "%s <file>", argv[0]); }
>
>  f = open(argv[1], O_RDONLY);
>  if (f == -1) {
>    err(1, "open failed"); }
>
>  i = fstat(f, &st);
>  if (i == -1) {
>    err(1, "fstat failed"); }
>
>  v = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, f, 0);
>  if (v == MAP_FAILED) {
>    err(1, "mmap failed"); }
>
>  i = munmap(v, st.st_size);
>  if (i == -1) {
>    err(1, "munmap failed"); }
>
>  close(f);
>
>  return 0; }

cvs update.

christos