I got the impression of the mmap(2) man page and the search results that mmap limited only by the available system address spaces, minus the system reserved address spaces. So on 32-bit armv7l, I assume it is about 3 GB = (4 GB - 1 GB).
But it seemed to me that I really could mmap create a 5 GB file without problems:
int main(int argc, char** argv) { // stats char * path = argv[1]; struct stat sb; stat(path, &sb); std::cout << "File size: " << sb.st_size << std::endl; // open int fd = open(path, O_RDONLY, S_IRWXU); std::cout << "File descriptor: " << fd << std::endl; int i; for (i =0; i<10; ++i){ void *pa = mmap( nullptr, sb.st_size, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, fd, 0); std::cout << "PA: " << pa << ", MAP_FAILED: " << (pa == MAP_FAILED) << ", Status: " << strerror(errno) << std::endl; } }
Compile with the flag -D_FILE_OFFSET_BITS=64 :
g++ -D_FILE_OFFSET_BITS=64 test.cc
And the result gives:
File size: 5045966585 File descriptor: 3 PA: 0x89f80000, MAP_FAILED: 0, Status: Success PA: 0x5d34a000, MAP_FAILED: 0, Status: Success PA: 0x30714000, MAP_FAILED: 0, Status: Success PA: 0x3ade000, MAP_FAILED: 0, Status: Success PA: 0xffffffff, MAP_FAILED: 1, Status: Cannot allocate memory PA: 0xffffffff, MAP_FAILED: 1, Status: Cannot allocate memory PA: 0xffffffff, MAP_FAILED: 1, Status: Cannot allocate memory PA: 0xffffffff, MAP_FAILED: 1, Status: Cannot allocate memory PA: 0xffffffff, MAP_FAILED: 1, Status: Cannot allocate memory PA: 0xffffffff, MAP_FAILED: 1, Status: Cannot allocate memory
From the results, mmap succeeded four times before going into real problems. But this should not succeed, since the file is ~ 5 GB.
My questions:
- Is this behavior expected for
mmap ? - If not, where am I mistaken?
Edit:
In the case of physical extension extensions (PAEs), 32-bit systems can add much more than 2 ^ 32 bytes, if available.
No PAE support for this CPU
$> cat /proc/cpuinfo Processor : ARMv7 Processor rev 4 (v7l) processor : 0 BogoMIPS : 1436.46 processor : 1 BogoMIPS : 1436.46 Features : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xc07 CPU revision : 4 Hardware : sun7i Revision : 0000 Serial : 09c11b9d52544848804857831651664b