Skip to content

[Request]: Set container-friendly defaults for vm.overcommit_memory and vm.max_map_count in the guest VM #2053

Description

@jglogan

Feature or enhancement request details

Feature or enhancement request details

Summary

Container guest VMs currently boot with Linux's stock kernel defaults for two memory-related sysctls that container tooling commonly relies on being tuned: vm.overcommit_memory (default 0, heuristic overcommit) and vm.max_map_count (default 65530, the per-process memory-mapping ceiling). Because each container's guest VM is sized to a small, fixed amount of RAM with no swap configured, both of these stock limits are hit far more easily than on a typical bare-metal host or general-purpose VM — causing common oversubscribed-mmap and many-mapping workloads to fail inside a container even though they work fine elsewhere.


Issue 1: vm.overcommit_memory

Steps to Reproduce

Run a container with a modest memory limit, then call mmap() for a size larger than that limit, writing to only a small portion of it:

container run --rm --memory=4G python:3-alpine python3 -c "
import mmap
size = 16*1024*1024*1024
m = mmap.mmap(-1, size)
print('mmap OK for', size, 'bytes')
m.close()
"

Expected Result

The mmap call succeeds. The kernel should only fail an allocation when the process actually tries to use more memory than is available (at page-fault time), not merely because the initial address-space reservation exceeds the memory limit.

Actual Result

mmap FAILED: [Errno 12] Out of memory

Root Cause

The guest kernel boots with the Linux default vm.overcommit_memory=0 ("heuristic overcommit"). In this mode, the kernel rejects a new anonymous mapping outright whenever the requested size exceeds the guest's currently free RAM plus swap, regardless of whether the process will ever touch that memory. Since the guest's total RAM is sized to roughly match --memory (with no swap device configured), that free-memory-plus-swap figure is small relative to the limit, so any oversubscribed mmap request fails immediately.


Issue 2: vm.max_map_count

Steps to Reproduce

Run a workload that creates a large number of distinct memory mappings — for example, Elasticsearch, many JVM-based applications, or a test program that repeatedly mmaps small anonymous regions without a corresponding munmap, until the process's total mapping count exceeds 65530.

Expected Result

Mapping creation continues to succeed well past the stock Linux default, matching the higher ceiling that most container hosts and general-purpose Linux distributions configure out of the box (commonly 262144).

Actual Result

Once the process's map count reaches the default limit of 65530, further mmap calls fail with ENOMEM, even though the workload's actual memory usage may be nowhere near the container's memory limit.

Root Cause

The guest kernel boots with the Linux kernel's stock default vm.max_map_count=65530. Nothing in the current guest boot path raises this value, so any workload that legitimately needs a higher mapping count — a well-documented requirement for several common memory-mapping-heavy applications — fails inside a container.


Proposed Fix

Set container-friendly defaults for both sysctls at guest VM boot:

  • vm.overcommit_memory=1 ("always overcommit"), so the kernel skips its up-front admission check and instead relies on the existing cgroup memory limit and OOM killer to enforce memory usage at page-fault time.
  • vm.max_map_count=262144, matching the higher ceiling many other container hosts and Linux distributions already ship with by default.

Workaround

Until this is addressed, users can set both sysctls themselves at container startup. Writing to /proc/sys/vm/* only requires running as root (the default for most images) and does not require --privileged or extra capabilities:

container run --rm --memory=4G <image> sh -c "echo 1 > /proc/sys/vm/overcommit_memory && echo 262144 > /proc/sys/vm/max_map_count && <your command>"

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added this to the 2026-08 milestone on Aug 1, 2026
  2. added theissue type on Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions