Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Baoquan He <baoquan.he@linux.dev>
To: linux-mm@kvack.org
Cc: david@kernel.org, akpm@linux-foundation.org, kasong@tencent.com,
	baohua@kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev,
	axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com,
	baolin.wang@linux.alibaba.com, baoquan.he@linux.dev
Subject: [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter
Date: Mon, 23 Nov 2026 16:57:56 +0800	[thread overview]
Message-ID: <20261123085800.981256-1-baoquan.he@linux.dev> (raw)

Problem
=======

MGLRU's aging walks every PUD of every mm in the mm_list. For a PUD whose
512 PMDs all fail the existing PMD-level Bloom filter, the walker still
descends into the PUD and iterates all 512 PMD entries. When an mm has no
pages on a given node this is structural waste: lru_gen_use_mm() sets
mm->lru_gen.bitmap to -1 (all nodes) on every context switch, so the aging
walker of *every* node, e.g kswapd, direct reclaim, proactive aging walks
the same mm.

On a 2-node KVM guest with the workload pinned to node 0, node 1's aging
walks of those mms scan 1,362 leaf entries per walk while finding no young
folio for node 1's lruvec, and 94% of those walks are entirely empty.

Approach
========

Add a PUD-level Bloom filter, one level above the existing PMD filter.
The walker now:

  1. Tests the PUD filter before descending into a PUD subtree.
  2. If the PUD had nothing young for this lruvec last generation, skips the
     whole 1 GiB region -- avoiding 512 PMD lookups.
  3. walk_pmd_range() reports whether it found anything young;
     walk_pud_range() records that in the double-buffered PUD filter.
  4. The rmap feedback path marks hot PUDs, so regions whose hotness is only
     observed by eviction are re-examined promptly. This is done for both
     mapping types: lru_gen_look_around() covers PTE-mapped folios, and
     folio_referenced_one() covers PMD-mapped ones, which never reach
     lru_gen_look_around().
  5. force_scan walks bypass the PUD test, so manual aging and newly added
     mms always rescan and re-populate the filter.

The filter key is (mm, PUD-aligned address), as suggested by Kairui. It is
a stable identity of the range on both sides of the interface: the aging
walk computes it from args->mm and addr, the rmap path from vma->vm_mm and
the address. So the feedback path needs no page-table walk at all.

The double-buffered filter flips each generation and force_scan bypasses
it, so a missed re-mark costs at most one generation, and reclaim is still
safe for a wrongly skipped subtree because folio_referenced() consults the
PTE young bits, not the filter.

Change log
==========
v4 -> v5:

 - Rebased onto the latest mm-new commit 7d1a16abe4cc.

 - Drop MM_LEAF_ASSOCIATED: an empty walk is now "MM_LEAF_TOTAL > 0 and
   MM_LEAF_YOUNG == 0". MM_LEAF_YOUNG already means the young leaves of
   this lruvec, which is what the PUD filter needs, so the second counter
   added nothing. The debugfs columns and the tracepoint field are renamed
   to match. (Sashiko)

Test
====

8 GiB KVM guest, 4 vCPU, two 4 GiB NUMA nodes, 7.4.0-rc3 with the series.
"base" below is the same kernel with the filter disabled (patch 1 only):
same .config, same workload. Each result directory records its own cmdline
and per-node meminfo, so a wrong configuration would show.

1) Cross-node empty walks. 16 workers x 128 MiB pinned to node 0
   (numactl --membind=0), so node 1 owns none of these pages. 100 aging
   passes, both nodes aged, 3 runs, median:

                                        base   filter change
     node 1  leaf entries scanned      1,243      107   -91%
             walks with leaves            17     0.67   -96%
             PUDs skipped                  0       51
     node 0  leaf entries scanned     12,926   13,155  +1.8%
             young leaves              9,228    9,167  -0.7%
             worker RSS delta             0%       0%

   The base's own three runs spread 9,133 to 9,248 young leaves on node 0,
   so node 0 keeps its young leaves. The filter marks young leaves in
   exactly the same place it did before; what it drops is the walk into
   PUDs that had nothing young.

     forced pass, node 1 leaf/walk
       before the filtered passes   1,359-1,371  1,363-1,370
       after them                   1,361-1,371  1,363-1,370

   A forced pass bypasses the filter, so it costs the same on both kernels
   and the same before and after 100 filtered passes: the filter is a
   cache, not a state.

2) Correctness, 11 checks, all pass: a cold PUD is skipped; touching it
   does not revive it; force_scan re-marks it and the next pass walks it
   again; a munmap + mmap at the same address shows no stale suppression; a
   1 GiB range migrated from node 0 to node 1 is re-scanned by node 1 after
   one forced pass; no premature reclaim in any of them; dmesg clean.

3) A PUD that holds only PMD-mapped huge pages. 1 GiB is mapped with
   THP=always (AnonHugePages = 1 GiB, 262,144 of 262,144 pages resident) and
   aged until its PUD is skipped (S +4 over 3 passes). The memcg is then
   put under reclaim pressure (memory.max below the current usage) and the
   range is touched again, so folio_referenced() runs on PMD-mapped folios.
   The next normal aging pass walks the range again:

     leaf_total 1560,  leaf_young 387

4) Reclaim pressure.  Four 512 MiB workers in a memory.max=2G/swap.max=1G
   memcg, at the limit so reclaim never stops; each flips a 256 MiB half
   every second. Both nodes are aged every 0.5 s for 600 s. Rates per
   second, because some runs stopped early on both kernels:

                             base                filter
     pgscan_anon          23.7-27.4k/s (3)    34.6-35.3k/s (2)
     pgsteal_anon          3.95-4.10k/s        3.74-4.63k/s
     pswpout               3.94-4.10k/s        3.74-4.61k/s
     refault_anon          3.95-4.10k/s        3.74-4.63k/s
     oom_kill              0                   0
     hot half resident     262,140-262,144     262,144
     node 1 walks w/ leaves  2,812-4,544          4

   Evictions, swap-out, refaults and residency are the same. The scanner
   examines 26-49% more folios with the filter: a folio under a skipped PUD
   is not promoted that generation, so it sits in an older generation a
   little longer and takes more scanning to reach. Extra scanning, not
   extra reclaim. The per-walk statistics cannot cause it, nothing outside
   lru_gen_seq_show() reads them.

5) Aging cost on a single node.  Per pass, 200 passes, perf stat and the
   median wall time around the same fork-free debugfs write:

     shape                                base      filter   change
     2 procs x 32 GiB VA, 0.2% touched
       time per pass                  1,577-1,596  1,278-1,392 us  -15%
       instructions per pass              5.79M        4.27M       -26%
     20 procs x 3 GiB VA, 2% touched
       time per pass                 9,889-10,097 9,563-9,775 us    -4%
       instructions per pass              29.6M        28.1M        -5%
     20 procs x 64 MiB, fully touched
       time per pass                10,294-10,579 10,167-10,411 us  -2%
       instructions per pass              30.06M       30.05M        0%

   The leaf counters are the same in all three rows; only the skips differ.
   The wide shape has 34 PUD regions per mm and skips all of them, so it is
   1.5M instructions lighter per pass, about 22,000 per skipped PUD, which
   is the 512 PMD-level Bloom tests it no longer runs.  With 5 and 1 PUD
   regions per mm there is little to skip, so the other two cost nothing.

Baoquan He (4):
  mm/mglru: add MM_WALK_EMPTY stats and tracepoint
  mm/mglru: add PUD-level Bloom filter state and generic helpers
  mm/mglru: skip cold PUD subtrees during aging
  mm/mglru: count PUD subtrees skipped by the PUD-level filter

 include/linux/mmzone.h |  20 ++++-
 mm/rmap.c              |   5 +-
 mm/trace_vmscan.h      |  30 ++++++++
 mm/vmscan.c            | 169 +++++++++++++++++++++++++++++++++--------
 4 files changed, 189 insertions(+), 35 deletions(-)


base-commit: 7d1a16abe4cc5dccd21e3d6262e44433a5885d27
-- 
2.52.0



             reply	other threads:[~2026-11-23  8:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  8:57 Baoquan He [this message]
2026-11-23  8:57 ` [PATCH v5 1/4] mm/mglru: add MM_WALK_EMPTY stats and tracepoint Baoquan He
2026-11-23  8:57 ` [PATCH v5 2/4] mm/mglru: add PUD-level Bloom filter state and generic helpers Baoquan He
2026-11-23  8:57 ` [PATCH v5 3/4] mm/mglru: skip cold PUD subtrees during aging Baoquan He
2026-11-23  8:58 ` [PATCH v5 4/4] mm/mglru: count PUD subtrees skipped by the PUD-level filter Baoquan He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123085800.981256-1-baoquan.he@linux.dev \
    --to=baoquan.he@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=kasong@tencent.com \
    --cc=linux-mm@kvack.org \
    --cc=qi.zheng@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox