OSX mmap with VM_FLAGS_SUPERPAGE_SIZE_2MB

Viewed 491

I'm trying to allocate large memory pages (2MB) on the Mac (OSX 10.12.6, Sierra) using

void *got = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);

but in general I can't allocate a very large region (I wanted 128MB, the machine has 16GB RAM). I think this is because my Mac has been on for a while and the memory has become fragmented - i.e. there isn't a 128MB contiguous region available. I can sometimes get 16MB, but rarely anything bigger than that.

Is there a way to tell the Operating System to defragment the RAM before I call mmap()? Is there a way to do this with mach_vm_allocate() that will cause a defrag first?

Thanks.

0 Answers
Related