[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] [PATCH v3 00/10] mm: convert mm counter to take a folio#1977
Conversation
mainline inclusion from mainline-v6.9-rc1 category: performance Patch series "mm: convert mm counter to take a folio", v3. Make sure all mm_counter() and mm_counter_file() callers have a folio, then convert mm counter functions to take a folio, which saves some compound_head() calls. This patch (of 10): Thanks to the compound_head() hidden inside PageLocked(), this saves a call to compound_head() over calling page_folio(pfn_swap_entry_to_page()) Link: https://lkml.kernel.org/r/20240111152429.3374566-1-willy@infradead.org Link: https://lkml.kernel.org/r/20240111152429.3374566-2-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: David Hildenbrand <david@redhat.com> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 5662400) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion from mainline-v6.9-rc1 category: performance These callers only pass the result to PageAnon(), so we can save the extra call to compound_head() by using pfn_swap_entry_folio(). Link: https://lkml.kernel.org/r/20240111152429.3374566-3-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: David Hildenbrand <david@redhat.com> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 7101422) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion from mainline-v6.9-rc1 category: performance We only want to know whether the folio is anonymous, so use pfn_swap_entry_folio() and save a call to compound_head(). Link: https://lkml.kernel.org/r/20240111152429.3374566-4-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: David Hildenbrand <david@redhat.com> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit f2d571b) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion from mainline-v6.9-rc1 category: performance Call pfn_swap_entry_folio() in ptep_zap_swap_entry() as preparation for converting mm counter functions to take a folio. Link: https://lkml.kernel.org/r/20240111152429.3374566-5-willy@infradead.org Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 0601ac8) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion from mainline-v6.9-rc1 category: performance Call pfn_swap_entry_folio() in __split_huge_pmd_locked() as preparation for converting mm counter functions to take a folio. Link: https://lkml.kernel.org/r/20240111152429.3374566-6-willy@infradead.org Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 439992f) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion from mainline-v6.9-rc1 category: performance Call pfn_swap_entry_to_folio() in zap_huge_pmd() as preparation for converting mm counter functions to take a folio. Saves a call to compound_head() embedded inside PageAnon(). Link: https://lkml.kernel.org/r/20240111152429.3374566-7-willy@infradead.org Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 0103b27) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion from mainline-v6.9-rc1 category: performance Call pfn_swap_entry_folio() as preparation for converting mm counter functions to take a folio. Link: https://lkml.kernel.org/r/20240111152429.3374566-8-willy@infradead.org Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 530c2a0) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion from mainline-v6.9-rc1 category: performance Make should_zap_page() take a folio and rename it to should_zap_folio() as preparation for converting mm counter functions to take a folio. Saves a call to compound_head() hidden inside PageAnon(). [wangkefeng.wang@huawei.com: fix used-uninitialized warning] Link: https://lkml.kernel.org/r/962a7993-fce9-4de8-85cd-25e290f25736@huawei.com Link: https://lkml.kernel.org/r/20240111152429.3374566-9-willy@infradead.org Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit eabafaa) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion from mainline-v6.9-rc1 category: performance Now all callers of mm_counter() have a folio, convert mm_counter() to take a folio. Saves a call to compound_head() hidden inside PageAnon(). Link: https://lkml.kernel.org/r/20240111152429.3374566-10-willy@infradead.org Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Conflicts: mm/memory.c (cherry picked from commit a23f517) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
Reviewer's GuideThis PR introduces folio-aware mm counter helpers and a pfn_swap_entry_folio() helper, then systematically updates migration, zap, rmap, THP, userfaultfd, proc, uprobes and s390 code paths to operate on folios instead of pages, reducing compound_head() usage and aligning swap/migration handling with folio-centric APIs. Flow diagram for folio-based mm counter and swap entry handlingflowchart LR
entry[swp_entry_t entry]
pfn["pfn_swap_entry_folio(entry)"]
folio[folio]
anon["folio_test_anon(folio)"]
swapb["folio_test_swapbacked(folio)"]
mcf["mm_counter_file(folio)"]
mc["mm_counter(folio)"]
anonrss[MM_ANONPAGES]
filepages[MM_FILEPAGES]
shmem[MM_SHMEMPAGES]
entry --> pfn --> folio
folio --> anon
anon -- true --> anonrss
anon -- false --> swapb
swapb -- true --> mcf --> shmem
swapb -- false --> mcf --> filepages
folio --> mc --> anonrss
folio --> mc --> mcf
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In zap_huge_pmd(), the non-present huge PMD path when !thp_migration_supported() leaves folio as NULL but still calls folio_test_anon(folio) and mm_counter_file(folio), which will dereference NULL; this path should either return early, set folio appropriately, or guard those calls.
- The new pfn_swap_entry_folio() BUG_ON(!folio_test_locked(folio)) tightens the locking requirements for migration entries; please double-check all call sites (e.g. pagemap_* helpers, migration_entry_wait_on_locked, zap_pte_range) to ensure the folio is guaranteed locked there or consider weakening/annotating the invariant if that’s not universally true.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In zap_huge_pmd(), the non-present huge PMD path when !thp_migration_supported() leaves folio as NULL but still calls folio_test_anon(folio) and mm_counter_file(folio), which will dereference NULL; this path should either return early, set folio appropriately, or guard those calls.
- The new pfn_swap_entry_folio() BUG_ON(!folio_test_locked(folio)) tightens the locking requirements for migration entries; please double-check all call sites (e.g. pagemap_* helpers, migration_entry_wait_on_locked, zap_pte_range) to ensure the folio is guaranteed locked there or consider weakening/annotating the invariant if that’s not universally true.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
mainline inclusion from mainline-v6.9-rc1 category: performance Now all callers of mm_counter_file() have a folio, convert mm_counter_file() to take a folio. Saves a call to compound_head() hidden inside PageSwapBacked(). Link: https://lkml.kernel.org/r/20240111152429.3374566-11-willy@infradead.org Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 6b27cc6) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
c928ce0 to
8850dd8
Compare
Link: https://lore.kernel.org/all/20240111152429.3374566-1-willy@infradead.org/T/#u
Make sure all mm_counter() and mm_counter_file() callers have a folio,
then convert mm counter functions to take a folio, which saves some
compound_head() calls.
v3:
calls to compound_head().
v2:
drop some unneeded changes.
v1:
device private page, per Matthew Wilcox
Kefeng Wang (7):
s390: use pfn_swap_entry_folio() in ptep_zap_swap_entry()
mm: use pfn_swap_entry_folio() in __split_huge_pmd_locked()
mm: use pfn_swap_entry_to_folio() in zap_huge_pmd()
mm: use pfn_swap_entry_folio() in copy_nonpresent_pte()
mm: Convert to should_zap_page() to should_zap_folio()
mm: convert mm_counter() to take a folio
mm: convert mm_counter_file() to take a folio
Matthew Wilcox (Oracle) (3):
mm: Add pfn_swap_entry_folio()
proc: Use pfn_swap_entry_folio where obvious
mprotect: Use pfn_swap_entry_folio
arch/s390/mm/pgtable.c | 4 ++--
fs/proc/task_mmu.c | 4 ++--
include/linux/mm.h | 12 +++++-----
include/linux/swapops.h | 13 +++++++++++
kernel/events/uprobes.c | 2 +-
mm/filemap.c | 2 +-
mm/huge_memory.c | 23 ++++++++++---------
mm/khugepaged.c | 4 ++--
mm/memory.c | 49 ++++++++++++++++++++++-------------------
mm/mprotect.c | 4 ++--
mm/rmap.c | 10 ++++-----
mm/userfaultfd.c | 2 +-
12 files changed, 74 insertions(+), 55 deletions(-)
--
2.43.0
Summary by Sourcery
Convert memory management accounting and swap migration helpers to operate on folios instead of pages, and propagate these changes through mm, arch, and proc code paths to reduce compound_head() usage and align with folio-based APIs.
Enhancements: