Skip to content

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] proc: convert smaps_account and clear_refs_pte_range to use a folio #1998

Closed
opsiff wants to merge 2 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-07-20-update-5
Closed

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] proc: convert smaps_account and clear_refs_pte_range to use a folio #1998
opsiff wants to merge 2 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-07-20-update-5

Conversation

@opsiff

@opsiff opsiff commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary by Sourcery

Convert smaps accounting and clear_refs PTE handling to operate on folios instead of pages.

Enhancements:

  • Update smaps_account to use folio-based helpers for anon, swap-backed, dirty, KSM, young, and referenced checks, as well as refcount handling.
  • Update clear_refs_pte_range to use folio-based helpers for THP and normal PTE young/referenced bit clearing.

Matthew Wilcox (Oracle) added 2 commits July 20, 2026 14:52
mainline inclusion
from mainline-v6.10-rc1
category: performance

Patch series "Remove page_idle and page_young wrappers".

There are only a couple of places left using the page wrappers for idle &
young tracking.  Convert the two users in proc and then we can remove the
wrappers.  That enables the further simplification of autogenerating the
definitions when CONFIG_PAGE_IDLE_FLAG is disabled.

This patch (of 4):

Replaces four calls to compound_head() with two.

Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
(cherry picked from commit 03aa577)
Signed-off-by: Wentao Guan <[email protected]>
mainline inclusion
from mainline-v6.10-rc1
category: performance

Replace seven calls to compound_head() with one.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
(cherry picked from commit 6c977f3)
Signed-off-by: Wentao Guan <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR refactors procfs memory accounting and clear_refs handling to use folio-based APIs instead of struct page APIs, aligning smaps_account() and clear_refs_pte_range() with the kernel’s folio model while preserving existing behavior.

Flow diagram for clear_refs_pte_range folio-based young/referenced clearing

flowchart TD
  A[clear_refs_pte_range] --> B[pmd_trans_huge_lock]
  B --> C{pmd_present}
  C -->|true| D[pmd_folio]
  D --> E[pmdp_test_and_clear_young]
  E --> F[folio_test_clear_young]
  F --> G[folio_clear_referenced]
  C -->|false| H[return 0]

  A --> I[pte_offset_map_lock]
  I --> J[for each pte]
  J --> K{pte_present}
  K -->|true| L[vm_normal_folio]
  L --> M{folio != NULL}
  M -->|true| N[ptep_test_and_clear_young]
  N --> O[folio_test_clear_young]
  O --> P[folio_clear_referenced]
  M -->|false| Q[continue]
  K -->|false| Q

  J --> R[pte_unmap_unlock]
  R --> S[cond_resched]
Loading

File-Level Changes

Change Details Files
Convert smaps_account() to operate on folios instead of struct page helpers while keeping accounting semantics unchanged.
  • Introduce a local folio pointer using page_folio(page) and reuse it throughout the function.
  • Replace PageAnon, PageSwapBacked, PageDirty, PageKsm, page_is_young, and PageReferenced with the corresponding folio_test_* helpers for anon, swapbacked, dirty, ksm, young, and referenced.
  • Update the single-mapping check from page_count(page) to folio_ref_count(folio) and adjust comments to refer to refcount instead of page_count().
fs/proc/task_mmu.c
Update clear_refs_pte_range() to use folio-based lookups and young/referenced bit operations for both PMD and PTE paths.
  • Change local variable from struct page *page to struct folio *folio in clear_refs_pte_range().
  • Use pmd_folio() instead of pmd_page() for huge PMD mappings and vm_normal_folio() instead of vm_normal_page() for normal PTE mappings.
  • Replace test_and_clear_page_young() and ClearPageReferenced() with folio_test_clear_young() and folio_clear_referenced() in both PMD and PTE handling paths.
fs/proc/task_mmu.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
deepin-ci-robot requested a review from BLumia July 20, 2026 06:59
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates /proc memory accounting and clear-refs logic in fs/proc/task_mmu.c to use folio-based helpers instead of page-based helpers, aligning these code paths with the kernel’s folio APIs.

Changes:

  • Convert smaps_account() checks (anon/swap-backed/dirty/KSM/young/referenced/refcount) to folio helpers.
  • Convert clear_refs_pte_range() young/referenced clearing to operate on folios for both PMD (THP) and PTE paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fs/proc/task_mmu.c
goto out;

page = pmd_page(*pmd);
folio = pmd_folio(*pmd);
@opsiff opsiff closed this Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants