Skip to content

work around heuristic overcommit causing fork failure + improve behaviour with no overcommit #193

Closed

Description

@thestinger

Linux has 3 settings for vm.overcommit_memory:

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

The current chunk allocation design is perfect for the case where full overcommit is enabled, but is flawed for the other two cases.

improving the case where overcommit is disabled

In the glibc allocator, the overcommit setting is detected at start-up and used to determine whether MADV_DONTNEED purging is used. If overcommit is disabled, it drops the commit charge by clobbering the memory with a clean PROT_NONE mapping using mmap with MAP_FIXED and then toggles it back to PROT_READ|PROT_WRITE to recycle it. Using PROT_NONE like this isn't faster than unmapping and remapping but it's usable inside chunks and avoids the fragmentation issues caused by Linux using a naive heuristic instead of best-fit.

I think MADV_FREE vs. dropping commit charge should be a runtime tunable with the default determined from the overcommit state like glibc.

working around heuristic overcommit

The default heuristic overcommit is designed to catch obvious errors, but it tends to result in spurious failures with jemalloc. The problem is that fork will fail when the process has more than approximately half of the available memory as commit charge. This is a much bigger problem in jemalloc than other allocators because it never unmaps memory, at least in the default high-performance build.

The overcommit heuristic is clearly not sensible when using jemalloc, so I think it would make sense to detect it and set MAP_NORESERVE on all of the mappings. Rather than catching obvious errors, it's resulting in an inability to use all of (well, more than half of) the system's resources. Alternatively, MAP_NORESERVE could just be set by default. It's a no-op for the other 2 overcommit states (it's not documented correctly in the man pages project).

Activity

  1. changed the title [-]work around heuristic overcommit causing fork failure + improve default behaviour when memory accounting is enabled[/-] [+]work around heuristic overcommit causing fork failure + improve behaviour with no overcommit[/+] on Feb 5, 2015
  2. added this to the 4.2.0 milestone on Mar 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions