From: "Mike Black" <mblack@csihq.com>
To: "linux-kernel" <linux-kernel@vger.kernel.org>
Subject: mmap'ing a large file
Date: Wed, 14 Aug 2002 11:42:16 -0400 [thread overview]
Message-ID: <050a01c243a9$2afa3590$f6de11cc@black> (raw)
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
next reply other threads:[~2002-08-14 15:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-14 15:42 Mike Black [this message]
2002-08-14 16:32 ` mmap'ing a large file Gianni Tedesco
2002-08-14 19:42 ` Jamie Lokier
2002-08-15 19:34 ` H. Peter Anvin
2002-08-15 10:02 ` DervishD
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='050a01c243a9$2afa3590$f6de11cc@black' \
--to=mblack@csihq.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.