mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH v1 0/4] mm: port MADV_VOLATILE and MADV_NONVOLATILE to v7.3-rc1
@ 2026-11-30  8:34 Hirotaka Yamagata
  2026-11-30  8:34 ` [RFC PATCH v1 1/4] mm: introduce VM_VOLATILE and MADV_VOLATILE/MADV_NONVOLATILE VMA handling Hirotaka Yamagata
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Hirotaka Yamagata @ 2026-11-30  8:34 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-api, Liam R. Howlett, Lorenzo Stoakes, David Hildenbrand,
	Chris Li, Kairui Song, Steven Rostedt, Masami Hiramatsu,
	Arnd Bergmann, Johannes Weiner, Michal Hocko, Roman Gushchin,
	Shakeel Butt, linux-kernel, linux-mm, linux-fsdevel,
	linux-trace-kernel, linux-arch, cgroups, John Stultz,
	Minchan Kim, Alexandre Marciano Gimenez, Tatsuyuki Ishi

This RFC series revives and modernizes the volatile ranges patchset
originally proposed by John Stultz and Minchan Kim [1].

Volatile ranges allow userspace caches holding regenerable data (such as
decoded image bitmaps or other private caches) to mark private anonymous
memory as safe for the kernel to discard under memory pressure,
bypassing swap. Such ranges are marked via madvise(MADV_VOLATILE).
Before reusing the buffer, userspace calls madvise(MADV_NONVOLATILE),
which unmarks the range and returns 1 if any pages in the range were
purged while volatile (or 0 if all pages remained intact).

Unlike MADV_FREE, which silently zero-fills dropped pages on re-access,
calling MADV_NONVOLATILE before reuse gives userspace deterministic
notification of whether cached data was lost without having to touch
every page.

If userspace instead accesses a purged page while the range is still
volatile, the fault raises SIGBUS; after MADV_NONVOLATILE, the next
access to it maps a zero page. Zero-filling on fault was considered,
but this series chooses SIGBUS to catch missing MADV_NONVOLATILE calls
and partially purged reads instead of silently seeing zeros, and to
keep the optimistic read model from earlier series possible so readers
can skip per-access MADV_NONVOLATILE/MADV_VOLATILE calls.

Volatile pages share the regular anon LRU, so currently they are not
purged when swap is disabled or full. Two alternatives were considered,
but neither was satisfactory:
- Keeping volatile pages on a separate LRU: changes eviction order and
  creates balancing issues against page cache and swap.
- Keeping a linked list of volatile pages only, in addition to the anon
  LRU: allows scanning for volatile pages cheaply when swap is full, but
  making pages volatile then requires scanning, which is expensive.

As a future extension, finer-grained purge reporting could avoid
regenerating an entire large buffer when only part of it was purged.
Within madvise(2), up to 31 bits of a positive int return value could
encode a coarse mask over N equal sub-ranges; configurable granularity
or an arbitrary-length bitmap would instead call for a dedicated syscall
taking an output bitmap pointer (similar to mincore(2)).

Key changes from the earlier v14 series [1]:
- Use PTE markers (PTE_MARKER_PURGED) instead of consuming a swap type.
- Defer purging in shrink_folio_list() until after checking references
  (immediately before folio_alloc_swap()), allowing frequently accessed
  volatile pages to age normally via LRU/MGLRU.
- Port VMA handling to Maple Tree and modern folio APIs.
- Add a PGPURGE vmstat/memcg counter and a tracepoint.

This series was evaluated with Chromium patched to back discardable
memory with MADV_VOLATILE/MADV_NONVOLATILE, running the
multiwindow-memory-stress benchmark from chromium/web-tests (30 tabs
across 5 windows alongside 4 background Chromium instances in an 8 GiB
VM with 8 GiB swap). Backing decoded image caches with volatile ranges
reduced the software image decode count per run by 18.0% and total
software image decode time per run by 24.9%
(Renderer4.ImageDecodeTaskDurationUs.Software). Under slab_nomerge,
VMA-related slab overhead (vm_area_struct, anon_vma_chain, anon_vma,
maple_node) was +228 KiB mean (+1.55%, ~0.003% of ~7.2 GiB total
Chromium PSS) and +76 KiB peak (+0.42%).

[1] https://lore.kernel.org/lkml/1398806483-19122-1-git-send-email-john.stultz@linaro.org/
    ("[PATCH 0/4] Volatile Ranges (v14 - madvise reborn edition!)")

Hirotaka Yamagata (4):
  mm: introduce VM_VOLATILE and MADV_VOLATILE/MADV_NONVOLATILE VMA
    handling
  mm: add PTE_MARKER_PURGED and TTU_PURGE for purged volatile pages
  mm/volatile: purge volatile anonymous folios during reclaim
  mm/volatile: add PGPURGE vmstat counter and purge tracepoint

 MAINTAINERS                            |   2 +
 fs/proc/task_mmu.c                     |   1 +
 include/linux/leafops.h                |  14 ++
 include/linux/mm.h                     |  12 +
 include/linux/mm_inline.h              |   5 +-
 include/linux/mvolatile.h              |  48 ++++
 include/linux/rmap.h                   |   1 +
 include/linux/swapops.h                |  18 +-
 include/linux/vm_event_item.h          |   1 +
 include/trace/events/mmflags.h         |   7 +
 include/trace/events/vmscan.h          |  24 ++
 include/uapi/asm-generic/mman-common.h |   3 +
 mm/Makefile                            |   2 +-
 mm/khugepaged.c                        |  17 ++
 mm/madvise.c                           |  29 +++
 mm/memcontrol.c                        |   1 +
 mm/memory.c                            |   5 +
 mm/mprotect.c                          |   6 +-
 mm/mseal.c                             |  20 ++
 mm/mvolatile.c                         | 311 +++++++++++++++++++++++++
 mm/rmap.c                              |  14 ++
 mm/vmscan.c                            |  14 ++
 mm/vmstat.c                            |   1 +
 23 files changed, 550 insertions(+), 6 deletions(-)
 create mode 100644 include/linux/mvolatile.h
 create mode 100644 mm/mvolatile.c


base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
-- 
2.56.0.611.g1030f0b940-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-30 10:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30  8:34 [RFC PATCH v1 0/4] mm: port MADV_VOLATILE and MADV_NONVOLATILE to v7.3-rc1 Hirotaka Yamagata
2026-11-30  8:34 ` [RFC PATCH v1 1/4] mm: introduce VM_VOLATILE and MADV_VOLATILE/MADV_NONVOLATILE VMA handling Hirotaka Yamagata
2026-11-30  8:34 ` [RFC PATCH v1 2/4] mm: add PTE_MARKER_PURGED and TTU_PURGE for purged volatile pages Hirotaka Yamagata
2026-11-30  8:34 ` [RFC PATCH v1 3/4] mm/volatile: purge volatile anonymous folios during reclaim Hirotaka Yamagata
2026-11-30  8:34 ` [RFC PATCH v1 4/4] mm/volatile: add PGPURGE vmstat counter and purge tracepoint Hirotaka Yamagata
2026-11-30 10:39 ` [RFC PATCH v1 0/4] mm: port MADV_VOLATILE and MADV_NONVOLATILE to v7.3-rc1 David Hildenbrand (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®