v1 2026-09-06

mm/collapse: separate a collapse from its callers · v1

重构 khugepaged:以 policy 表达调用方许可,拆分扫描与执行两个阶段并以 mmap_lock 为界,将 MADV_COLLAPSE 移入 madvise.c。

原始补丁链接

子 Patch(12)

1/12
mm/khugepaged: drop redundant mm_struct pin in madvise_collapse()
[Re: [PATCH 01/12] mm/khugepaged: drop redundant mm_struct pin in madvise_collapse()] On Fri Sep 4, 2026 at 11:10 AM EDT, Kiryl Shutsemau wrote: > From: “Kiryl Shutsemau (Meta)” kas@kernel.org > > m
2/12
mm/khugepaged: count collapses where khugepaged makes them
On Fri Sep 4, 2026 at 11:10 AM EDT, Kiryl Shutsemau wrote: > From: “Kiryl Shutsemau (Meta)” kas@kernel.org > > collapse_single_pmd() bumps khugepaged_pages_collapsed for its caller, and > tests cc->
3/12
mm/khugepaged: rename mthp_present_ptes bitmap to eligible_ptes
From: “Kiryl Shutsemau (Meta)” kas@kernel.org The name says less than the bit means. A set bit means not only that the PTE is present, but also that it passed the other checks: uffd, lazyfree, ano
4/12
mm/collapse: add collapse.h for the collapse interface
From: “Kiryl Shutsemau (Meta)” kas@kernel.org khugepaged.c holds both the users of collapse and the machinery that performs it. The daemon’s scan loop, the sysfs tunables, MADV_COLLAPSE’s entry po
5/12
mm/collapse: state what a collapse may do in the policy
From: “Kiryl Shutsemau (Meta)” kas@kernel.org Tests scattered through the collapse path decide what a collapse is allowed to do by asking whether khugepaged started it. Between them they settle:
6/12
mm/collapse: drop the collapse_possible() wrapper
From: “Kiryl Shutsemau (Meta)” kas@kernel.org collapse_possible() only forwards to collapse_possible_orders() and turns its mask into a bool. Its three callers can test the mask themselves. No fu
7/12
mm/collapse: name the per-table scan reset for what it resets
From: “Kiryl Shutsemau (Meta)” kas@kernel.org collapse_control_init_scan() resets what one scan accumulates: the node load, the allocation nodemask and the eligible-PTE bitmap. It runs before ever
8/12
mm/collapse: separate scanning a PTE table from collapsing it
From: “Kiryl Shutsemau (Meta)” kas@kernel.org A collapse is two jobs. One reads a PTE table under mmap_lock and decides whether the range is worth collapsing. The other allocates, isolates, copie
9/12
mm/collapse: open-code collapse_single_pmd() in its two callers
From: “Kiryl Shutsemau (Meta)” kas@kernel.org collapse_scan_pmd() and collapse_run_pmd() each have a clear locking contract. The scan is called with mmap_lock held for reading and returns with it
10/12
mm/collapse: work out the orders a VMA allows once per VMA
From: “Kiryl Shutsemau (Meta)” kas@kernel.org The scan asked collapse_possible_orders() for every PTE table, for an answer that is a property of the VMA. Both callers walk a VMA a table at a time,
11/12
mm/collapse: declare the collapse interface in collapse.h
From: “Kiryl Shutsemau (Meta)” kas@kernel.org A collapse takes four calls: - collapse_control_init() - set up the control a caller carries; - collapse_scan_pmd() - scan one PTE table, under mm
12/12
mm/collapse: implement MADV_COLLAPSE in madvise.c
From: “Kiryl Shutsemau (Meta)” kas@kernel.org MADV_COLLAPSE is a madvise operation, but its implementation sat in khugepaged.c. The daemon’s file therefore also held a syscall’s worth of code that