Skip to content

mm: Refactor and improve VMA count limit code

Kalesh Singh linux-fsdevel linux-kselftest linux-mm linux-trace-kernel lkml llvm oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v4 Latest5 patches 4 repliesIn review

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5mm: Document lenient map_count checksmm/mmap.c mm/vma.c+15 -01 reply
2/5mm/selftests: add max_vma_count testsMAINTAINERS tools/testing/selftests/mm/.gitignore tools/testing/selftests/mm/Makefile +2 more+724 -02 replies
3/5mm: Introduce max_vma_count() to abstract the max map count sysctlinclude/linux/mm.h mm/internal.h mm/mmap.c +5 more+27 -131 reply
4/5mm: rename mm_struct::map_count to vma_countfs/binfmt_elf.c fs/coredump.c include/linux/mm_types.h +9 more+60 -600 replies
5/5mm/tracing: introduce trace_mm_insufficient_vma_slots eventMAINTAINERS include/trace/events/vma.h mm/mmap.c +4 more+55 -40 replies

Reviews trailers per patch

1 of 5 patches has a Reviewed-by or Acked-by.

PatchDavid Hildenbrand (Red Hat)
1/5A-b
2/5
3/5
4/5
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/5] mm: Refactor and improve VMA count limit code

Hi all,

This series refactors the VMA count limit code to improve clarity, test coverage, and observability.

The VMA count limit, controlled by sysctl_max_map_count, is a safeguard that prevents a single process from consuming excessive kernel memory by creating too many memory mappings.

A major change since v3 is the first patch in the series which instead of attempting to fix overshooting the limit now documents that this is the intended behavior. As Hugh pointed out, the lenient check (>) in do_mmap() and do_brk_flags() is intentional to allow for potential VMA merges or expansions when the process is at the sysctl_max_map_count limit. The consensus is that this historical behavior is correct but non-obvious.

This series now focuses on making that behavior clear and the surrounding code more robust. Based on feedback from Lorenzo and David, this series retains the helper function and the rename of map_count.

The refined v4 series is now structured as follows:

1. Documents the lenient VMA count checks with comments to clarify their purpose.

2. Adds a comprehensive selftest to codify the expected behavior at the limit, including the lenient mmap case.

3. Introduces max_vma_count() to abstract the max map count sysctl, making the sysctl static and converting all callers to use the new helper.

4. Renames mm_struct->map_count to the more explicit vma_count for better code clarity.

5. Adds a tracepoint for observability when a process fails to allocate a VMA due to the count limit.

Tested on x86_64 and arm64:

1. Build test:
allyesconfig for rename

2. Selftests:

      cd tools/testing/selftests/mm && \
          make && \
          ./run_vmtests.sh -t max_vma_count

3. vma tests:

      cd tools/testing/vma && \
          make && \
          ./vma

Link to v3:
https://lore.kernel.org/r/[email protected]/

Thanks to everyone for the valuable discussion on previous revisions.

-- Kalesh

Kalesh Singh (5):
mm: Document lenient map_count checks
mm/selftests: add max_vma_count tests
mm: Introduce max_vma_count() to abstract the max map count sysctl
mm: rename mm_struct::map_count to vma_count mm/tracing: introduce trace_mm_insufficient_vma_slots event

 MAINTAINERS                                   |   2 +
 fs/binfmt_elf.c                               |   2 +-
 fs/coredump.c                                 |   2 +-
 include/linux/mm.h                            |   2 -
 include/linux/mm_types.h                      |   2 +-
 include/trace/events/vma.h                    |  32 +
 kernel/fork.c                                 |   2 +-
 mm/debug.c                                    |   2 +-
 mm/internal.h                                 |   3 +
 mm/mmap.c                                     |  25 +-
 mm/mremap.c                                   |  13 +-
 mm/nommu.c                                    |   8 +-
 mm/util.c                                     |   1 -
 mm/vma.c                                      |  42 +-
 mm/vma_internal.h                             |   2 +
 tools/testing/selftests/mm/.gitignore         |   1 +
 tools/testing/selftests/mm/Makefile           |   1 +
 .../selftests/mm/max_vma_count_tests.c        | 716 ++++++++++++++++++
 tools/testing/selftests/mm/run_vmtests.sh     |   5 +
 tools/testing/vma/vma.c                       |  32 +-
 tools/testing/vma/vma_internal.h              |  13 +-
 21 files changed, 856 insertions(+), 52 deletions(-)
 create mode 100644 include/trace/events/vma.h
 create mode 100644 tools/testing/selftests/mm/max_vma_count_tests.c

base-commit: b227c04932039bccc21a0a89cd6df50fa57e4716

Signature · 1 line
2.51.1.851.g4ebd6896fd-goog