Skip to content

RFC mm/rmap: support arbitrary folio mappings

David Hildenbrand (Arm) cgroups linux-doc linux-fsdevel linux-mm lkml 1 version New

Get series with b4
b4 am [email protected] change-id 20260330-mapcount-32066c687010

Versions newest first

  1. v1 RFC Latest13 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13mm/rmap: remove folio->_nr_pages_mappedDocumentation/admin-guide/cgroup-v1/memory.rst Documentation/admin-guide/cgroup-v2.rst Documentation/mm/transhuge.rst +6 more+69 -1720 replies
2/13fs/proc/task_mmu: remove CONFIG_PAGE_MAPCOUNT handling for "mapmax"Documentation/filesystems/proc.rst fs/proc/task_mmu.c+7 -120 replies
3/13fs/proc/page: remove CONFIG_PAGE_MAPCOUNT handling for kpagecountDocumentation/admin-guide/mm/pagemap.rst fs/proc/page.c+7 -160 replies
4/13fs/proc/task_mmu: remove CONFIG_PAGE_MAPCOUNT handling for PM_MMAP_EXCLUSIVEDocumentation/admin-guide/mm/pagemap.rst fs/proc/task_mmu.c+9 -200 replies
5/13fs/proc/task_mmu: remove mapcount comment in smaps_account()fs/proc/task_mmu.c+0 -50 replies
6/13fs/proc/task_mmu: remove CONFIG_PAGE_MAPCOUNT handling in smaps_account()Documentation/filesystems/proc.rst fs/proc/internal.h fs/proc/task_mmu.c+22 -910 replies
7/13mm/rmap: remove CONFIG_PAGE_MAPCOUNTDocumentation/mm/transhuge.rst include/linux/rmap.h mm/Kconfig +1 more+7 -600 replies
8/13mm: re-consolidate folio->_entire_mapcountinclude/linux/mm.h include/linux/mm_types.h mm/internal.h +1 more+9 -170 replies
9/13mm: move _large_mapcount to _mapcount in page[1] of a large folioinclude/linux/mm_types.h+5 -50 replies
10/13mm: re-consolidate folio->_pincountinclude/linux/mm.h include/linux/mm_types.h mm/debug.c +2 more+8 -250 replies
11/13mm/rmap: stop using the entire mapcount for hugetlb foliosfs/proc/internal.h include/linux/mm.h include/linux/rmap.h +2 more+7 -70 replies
12/13mm/rmap: large mapcount interface cleanupsinclude/linux/rmap.h+31 -300 replies
13/13mm/rmap: support arbitrary folio mappingsDocumentation/mm/transhuge.rst fs/proc/internal.h include/linux/mm.h +8 more+214 -2360 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH RFC 00/13] mm/rmap: support arbitrary folio mappings

This series is related to my LSF/MM/BPF topic:

[LSF/MM/BPF TOPIC] Towards removing CONFIG_PAGE_MAPCOUNT [1]

And does the following things:

(a) Gets rid of CONFIG_PAGE_MAPCOUNT, stopping rmap-related code to no

    longer use page->_mapcount.

(b) Converts the entire mapcount to a "total mapped pages" counter, that can trivially be used to calculate the per-page average mapcount in a folio.

(c) Cleans up the code heavily,

(d) Teaches RMAP code to support arbitrary folio mappings: For example, supporting PMD-mapping of folios that span multiple PMDs.

Initially, I wanted to use a PMD + PUD mapcount, but once I realized that we can do the same thing much easier with a "total mapped pages" counters, I tried that. And was surprised how clean it looks.

More details in the last patch.

Functional Changes
------------------

The kernel now always behaves like CONFIG_PAGE_NO_MAPCOUNT currently does, in particular:

(1) System/node/memcg stats account large folios as fully mapped as soon as a single page is mapped, instead of the precise number of pages a partially-mapped folio has mapped. For example, this affects "AnonPages:", "Mapped:" and "Shmem" in /proc/meminfo.

(2) "mapmax" part of /proc/$PID/numa_maps uses the average page mapcount in a folio instead of the effective page mapcount.

(3) Determining the PM_MMAP_EXCLUSIVE flag for /proc/$PID/pagemap is based on folio_maybe_mapped_shared() instead of the effective page mapcount.

(4) /proc/kpagecount exposes the average page mapcount in a folio instead of the effective page mapcount.

(5) Calculating the Pss for /proc/$PID/smaps and /proc/$PID/smaps_rollup uses the average page mapcount in a folio instead of the effective page mapcount.

(6) Calculating the Uss for /proc/$PID/smaps and /proc/$PID/smaps_rollup uses folio_maybe_mapped_shared() instead of the effective page mapcount.

(7) Detecting partially-mapped anonymous folios uses the average page-page mapcount. This implies that we cannot detect partial mappings of shared anonymous folios in all cases.

TODOs
-----

Partially-mapped folios:

If deemed relevant, we could detect more partially-mapped shared anonymous folios on the memory reclaim path (e.g., during access-bit harvesting) and flag them accordingly, so they can get deferred-split. We might also just let the deferred splitting logic perform more such scanning of possible candidates.

Mapcount overflows:

It may already be possible to overflow a large folio's mapcount (+refcount). With this series, it may be possible to overflow "total mapped pages" on 32bit; and I'd like to avoid making it an unsigned long long on 32bit.

In a distant future, we may want a 64bit mapcountv value, but for the time being (no relevant use cases), we should likely reject new folio mappings if there is the possibility for mapcount + "total mapped pages" overflows early. I assume doing some basic checks during fork() + file folio mapping should be good enough (e.g., stop once it would turn negative).

This series saw only very basic testing on 64bit and no performance fine-tuning yet.

[1] https://lore.kernel.org/all/[email protected]/

---
David Hildenbrand (Arm) (13):
mm/rmap: remove folio->_nr_pages_mapped
fs/proc/task_mmu: remove CONFIG_PAGE_MAPCOUNT handling for "mapmax" fs/proc/page: remove CONFIG_PAGE_MAPCOUNT handling for kpagecount fs/proc/task_mmu: remove CONFIG_PAGE_MAPCOUNT handling for PM_MMAP_EXCLUSIVE fs/proc/task_mmu: remove mapcount comment in smaps_account() fs/proc/task_mmu: remove CONFIG_PAGE_MAPCOUNT handling in smaps_account() mm/rmap: remove CONFIG_PAGE_MAPCOUNT
mm: re-consolidate folio->_entire_mapcount
mm: move _large_mapcount to _mapcount in page[1] of a large folio
mm: re-consolidate folio->_pincount
mm/rmap: stop using the entire mapcount for hugetlb folios mm/rmap: large mapcount interface cleanups
mm/rmap: support arbitrary folio mappings

 Documentation/admin-guide/cgroup-v1/memory.rst |   6 +-
 Documentation/admin-guide/cgroup-v2.rst        |  13 +-
 Documentation/admin-guide/mm/pagemap.rst       |  30 ++-
 Documentation/filesystems/proc.rst             |  41 ++--
 Documentation/mm/transhuge.rst                 |  29 +--
 fs/proc/internal.h                             |  58 +----
 fs/proc/page.c                                 |  10 +-
 fs/proc/task_mmu.c                             |  69 ++----
 include/linux/mm.h                             |  37 +--
 include/linux/mm_types.h                       |  22 +-
 include/linux/pgtable.h                        |  22 ++
 include/linux/rmap.h                           | 221 ++++++++----------
 mm/Kconfig                                     |  17 --
 mm/debug.c                                     |  10 +-
 mm/internal.h                                  |  30 +--
 mm/memory.c                                    |   3 +-
 mm/page_alloc.c                                |  31 +--
 mm/rmap.c                                      | 302 ++++++++-----------------
 18 files changed, 325 insertions(+), 626 deletions(-)

---
base-commit: 196ab4af58d724f24335fed3da62920c3cea945f
change-id: 20260330-mapcount-32066c687010

Best regards,

Signature · 1 line
David Hildenbrand (Arm) <[email protected]>