When a user process invokes malloc(n), are there any physical pages allocated to the process? I believe No since malloc allocates from the heap. Is this correct?

1 Answer 1


For Linux, I believe the short answer to your question is "usually no physical pages are allocated". This is called "memory overcommit" and you can find tons of documentation on it. Unix variants have had different policies about actual physical page allocation at malloc-time. 4BSD-based systems traditionally did not overcommit, which in combination with the chill program (can't find a reference) was endless fun. chill allocated and held as much memory as it could. Because SunOS (4.2BSD-based) always allocated physical pages for any malloc(), a mere user could allocate all RAM and cause everyone else to page endlessly.

For linux you can find out what your system's policy is: cat /proc/sys/vm/overcommit_memory should give out a "0", "1" or "2" with the meanings "heuristic overcommit", "always overcommit" and "never overcommit" respectively.

  • Does malloc allocate from the heap?
    – user100503
    Commented Aug 15, 2014 at 0:34
  • Also are physical pages allocated once you have started to write to the memory allocated by malloc?
    – user100503
    Commented Aug 15, 2014 at 0:42
  • 1
    @user100503 - Yes, malloc()/calloc()/realloc() allocate from the heap. A little-used function alloca() allocates on the stack, but it's easy to make mistakes with alloca(). I believe that writing to an allocated page causes the kernel to actually allocate the physical memory. I can't point at any code or anything, but I'm still pretty sure.
    – user732
    Commented Aug 15, 2014 at 2:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .