Alex Rivera | Logout

In a 64 bit process, will my mmap / malloc request ever be denied?

Asked 2011-02-07T15:33:35.673
13

The address space for 64 bit addressing is absolutely huge. I have a program that will mmap several chunks of memory, each of the order of 100 - 500 MB. I will inevitably be remapping a few times, which may cause some fragmentation of available contiguous space.

Whatever fragmentation of space occurs, it is surely going to be trivially small concerned the available address space.

My question is: given these constraints, under normal circumstances, can I expect all mmap requests to succeed (i.e. not fail due to fragmentation)? What reasons might there be for them failing?

I am aware that the heap doesn't have the whole space to itself, but I imagine it has the vast majority.

Mac OS / Linux.

Edit
Report

1 Answer

0

Well, the OS / C library is free to decide whether there is enough memory or not. There's really no way for you to know how it decides this (it's obviously OS-specific, possibly even tunable), but it's possible that at some point the OS says "no more".

Possible reasons for failure to allocate memory:

  • Linux will overcommit memory, but this is tunable. Depending on how it is configured, you may get ENOMEM as soon as you exceed RAM+Swap.
  • If memory limits have been set using ulimit, you may get ENOMEM even sooner
answered 2011-02-07T16:02:26.750

Your Answer