The Mac OS X mmap man page says that you can select superpages, and I understand that this is the same as huge Linux pages.
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/mmap.2.html
However, the following simple test fails on Mac OS X (Yosemite 10.10.5):
#include <stdio.h>
#include <sys/mman.h>
#include <mach/vm_statistics.h>
int
main()
{
void *p = mmap((void *) 0x000200000000, 8 * 1024 * 1024,
PROT_READ | PROT_WRITE,
MAP_ANON | MAP_FIXED | MAP_PRIVATE,
VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);
printf("%p\n", p);
if (p == MAP_FAILED)
perror(NULL);
return 0;
}
Output:
0xffffffffffffffff
Cannot allocate memory
The result is the same as MAP_FIXEDremoved from the flags and NULLspecified as an address argument. Replacing VM_FLAGS_SUPERPAGE_SIZE_2MBwith -1leads to the expected result, that is, an error does not occur, but, obviously, the allocated memory space uses regular 4k pages.
What could be a problem when distributing superpages this way?