max size limit for mmap MAP_ANONYMOUS in different x86_64 kernels

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I ran this piece of code on centOS 5.3 x86_64 and ubuntu amd64 jaunty
server kernel:

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


#define SIZE (size_t)1024 * 1024 * 1024 * 16     /* 16GB */

int main(void) {
  void *buf = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,
                   MAP_SHARED | MAP_ANONYMOUS, -1, 0);
  if (MAP_FAILED == buf) {
    fprintf(stderr, "map failed\n");
    exit(EXIT_FAILURE);
  }

  return EXIT_SUCCESS;
}

However strace shows that mmap fails with -ENOMEM

This is the strace output:

[~/test]$ strace ./big_mmap_lab
execve("./big_mmap_lab", ["./big_mmap_lab"], [/* 47 vars */]) = 0
brk(0)                                  = 0xae0f000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x2b3761c6c000
uname({sys="Linux", node="oucs1198.otago.ac.nz", ...}) = 0
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=161548, ...}) = 0
mmap(NULL, 161548, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2b3761c6d000
close(3)                                = 0
open("/lib64/libc.so.6", O_RDONLY)      = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p\332A\3464\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1713160, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x2b3761c95000
mmap(0x34e6400000, 3494168, PROT_READ|PROT_EXEC,
MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34e6400000
mprotect(0x34e654c000, 2097152, PROT_NONE) = 0
mmap(0x34e674c000, 20480, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14c000) = 0x34e674c000
mmap(0x34e6751000, 16664, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x34e6751000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x2b3761c96000
arch_prctl(ARCH_SET_FS, 0x2b3761c96210) = 0
mprotect(0x34e674c000, 16384, PROT_READ) = 0
mprotect(0x34e561b000, 4096, PROT_READ) = 0
munmap(0x2b3761c6d000, 161548)          = 0
mmap(NULL, 17179869184, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
write(2, "map failed\n", 11map failed
)            = 11
exit_group(1)                           = ?
[~/test]$ vim big_mmap.c



Isn't the address space of amd64 architecture very big?  Also please
try the above code on other distribution and tell me which
distribution allows this mmap.

Thanks!

Mark

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux