I read through the docs of man proc. When it comes to the overcommit_memory, the heuristics in overcommit_memory=0 isn't understood well. What the heuristics actually mean?

does "calls of mmap(2) with MAP_NORESERVE are not checked" mean that the Kernel only allocate virtual memory without being aware of even the existence of swap space?

 This file contains the kernel virtual memory accounting mode.  Values are:

                     0: heuristic overcommit (this is the default)
                     1: always overcommit, never check
                     2: always check, never overcommit

              In mode 0, calls of mmap(2) with MAP_NORESERVE are not checked, and the default check is very weak, leading to the  risk
              of getting a process "OOM-killed".

Apart from preceding questions, will exhaustion of the virtual address space cause the OOM regardless of the enough remaining physical memory.


1 Answer 1


The overcommit_memory setting is taken into account in three places in the memory-management subsystem.

  1. The main one is __vm_enough_memory in mm/util.c, which decides whether enough memory is available to allow a memory allocation to proceed (note that this is a utility function which isn’t necessarily invoked). If overcommit_memory is 1, this function always succeeds. If it’s 2, it checks the actual available memory. If it’s 0, it uses the famous heuristic which you mention; that proceeds as follows:

    • count the number of free pages
    • add the number of file-backed pages (these can be recovered)
    • remove pages used for shared memory
    • add swap pages
    • add reclaimable pages
    • account for reserved pages
    • leave some memory for root (if the allocation isn’t being done by a cap_sys_admin process)

    The resulting total is used as the threshold for memory allocations.

  2. mmap also checks the setting: MAP_NORESERVE is honoured if overcommit is allowed (modes 0 and 1), and results in allocations with no backing swap (VM_NORESERVE). In this particular case, mode 0 is effectively equivalent to mode 1; this is what “calls of mmap(2) with MAP_NORESERVE are not checked” is referring to: it means that MAP_NORESERVE mmap calls will always succeed, and over-allocation will result in the OOM-killer stepping in after the fact, or a segment violation when a write is attempted.

  3. shmem has similar behaviour to mmap.

Running out of address space should cause allocation failures, not OOM-kills, since the allocation can’t actually proceed.

  • Thanks Stephen. Regarding the last question. Actually I mean virtual memory by address space. Will running out of virtual memory result in OOM-kills? Jul 13, 2017 at 10:09
  • What do you mean by virtual memory here? Physical + swap? Jul 13, 2017 at 11:23

You must log in to answer this question.

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