public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* mmap'ing a large file
@ 2002-08-14 15:42 Mike Black
  2002-08-14 16:32 ` Gianni Tedesco
  2002-08-15 10:02 ` DervishD
  0 siblings, 2 replies; 5+ messages in thread
From: Mike Black @ 2002-08-14 15:42 UTC (permalink / raw)
  To: linux-kernel

Is there a logical reason why a process can't mmap more than a 2G file?

I seem to get stuck at 2142208000 with
mmap: Cannot allocate memory

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

#define FILESIZE 2500000000

int
main ()
{
    unsigned long long offset = 0;
    unsigned long maplength = getpagesize () * 1000;
    int i;
    unsigned char *p;
    char mynull = 0;
    int fd = open ("test.map", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
    if (fd < 0) {
        perror ("test.map");
        exit (-1);
    }
    lseek (fd, FILESIZE - 1, SEEK_SET);
    write (fd, &mynull, 1);
    for (offset = 0; offset < FILESIZE - maplength; offset += maplength) {
        p = mmap (p, maplength, PROT_READ | PROT_WRITE, MAP_SHARED, fd,offset);
        printf ("%lld %p\n", offset, p);
        fflush (stdout);
        if (p == (unsigned char *) -1) {
            perror ("mmap");
            exit (-1);
        }
        memset (p, 1, maplength);
#if 0
        munmap (p, maplength);  /* this of course let's things go on */
#endif
    }
    return 0;
}


Michael D. Black mblack@csi-inc.com
http://www.csi-inc.com/
http://www.csi-inc.com/~mike
321-676-2923, x203
Melbourne FL


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-08-15 19:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-14 15:42 mmap'ing a large file Mike Black
2002-08-14 16:32 ` Gianni Tedesco
2002-08-14 19:42   ` Jamie Lokier
2002-08-15 19:34   ` H. Peter Anvin
2002-08-15 10:02 ` DervishD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox