From: Jinjiang Tu <tujinjiang@huawei.com>
To: <akpm@linux-foundation.org>, <ziy@nvidia.com>, <david@kernel.org>,
<luizcap@redhat.com>, <willy@infradead.org>,
<linmiaohe@huawei.com>, <svetly.todorov@memverge.com>,
<xu.xin16@zte.com.cn>, <chengming.zhou@linux.dev>,
<linux-fsdevel@vger.kernel.org>, <linux-mm@kvack.org>
Cc: <wangkefeng.wang@huawei.com>, <sunnanyong@huawei.com>
Subject: Re: [PATCH 2/2] fs: stable_page_flags(): use folio_test_*() helpers
Date: Fri, 10 Jul 2026 11:52:19 +0800 [thread overview]
Message-ID: <67066146-e371-46cd-bcbe-9c28ba8e890b@huawei.com> (raw)
In-Reply-To: <20260702110614.2176986-3-tujinjiang@huawei.com>
在 2026/7/2 19:06, Jinjiang Tu 写道:
> stable_page_flags() currently accesses folio->flags.f directly. Since
> commit 476d87d6a061 ("fs: stable_page_flags(): use snapshot_page()"), we
> can replace these raw flag accesses with the existing folio_test_*()
> helpers, thereby cleaning up the open‑coded flag handling.
>
> For KPF_IDLE, set_ps_flags() already handles both 64‑bit and 32‑bit
> cases, so the duplicate code in stable_page_flags() that deals with
> CONFIG_PAGE_IDLE_FLAG for the 64‑bit case is removed.
>
> The flag bits that has no folio_test_*() helpers are left unchanged,
> including PG_owner_priv_1, PG_arch_*.
>
> No functional change is intended.
I update commit message to explain the history and motivation. The updated
commit message is as follows:
Since commit 304daa8132a9 ("maps4: add /proc/kpageflags interface"),
/proc/kpageflags directly operates on page->flags to determine page status.
Later, commit 177975495914 ("proc: export more page flags in
/proc/kpageflags") started using page helper functions when exposing new
flags, leading to a mix of both approaches.
For tail pages, the original code did not return corresponding status.
commit 0a71649cb724 ("/proc/kpageflags: return KPF_SLAB for slab tail
pages") and commit 832fc1de01ae ("/proc/kpageflags: return KPF_BUDDY for
"tail" buddy pages") made tail slab/buddy pages also return corresponding
status. Then commit dee3d0bef2b0 ("proc: rewrite stable_page_flags()")
made all tail pages return the same status as their head page, except for
hwpoison and mapped flags. It also cached the folio's flags and operate on
the flags directly to avoid concurrency issues if using folio_test_*()
helpers. At this point, folio helpers and direct flag operations are mixed
together in stable_page_flags().
Since commit 476d87d6a061 ("fs: stable_page_flags(): use snapshot_page()"),
the folio has already been snapshotted, we can now safely switch to
folio_test_*() helpers instead of directly operating on flags, which is
more readable and consistent with the rest of the kernel.
For KPF_IDLE, set_ps_flags() already handles both 64-bit and 32-bit cases,
so the duplicate code in stable_page_flags() that deals with
CONFIG_PAGE_IDLE_FLAG for the 64-bit case is removed.
The flag bits that have no folio_test_*() helpers are left unchanged,
including PG_owner_priv_1, PG_arch_*.
No functional change is intended.
> Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
> ---
> fs/proc/page.c | 94 ++++++++++++++++++++++++++------------------------
> 1 file changed, 49 insertions(+), 45 deletions(-)
>
> diff --git a/fs/proc/page.c b/fs/proc/page.c
> index 2717dbb0431b..0dbd46fa84ea 100644
> --- a/fs/proc/page.c
> +++ b/fs/proc/page.c
> @@ -148,8 +148,6 @@ u64 stable_page_flags(const struct page *page)
> const struct folio *folio;
> struct page_snapshot ps;
> unsigned long k;
> - unsigned long mapping;
> - bool is_anon;
> u64 u = 0;
>
> /*
> @@ -163,17 +161,14 @@ u64 stable_page_flags(const struct page *page)
> folio = &ps.folio_snapshot;
>
> k = folio->flags.f;
> - mapping = (unsigned long)folio->mapping;
> - is_anon = mapping & FOLIO_MAPPING_ANON;
> -
> /*
> * pseudo flags for the well known (anonymous) memory mapped pages
> */
> if (folio_mapped(folio))
> u |= BIT_ULL(KPF_MMAP);
> - if (is_anon) {
> + if (folio_test_anon(folio)) {
> u |= BIT_ULL(KPF_ANON);
> - if ((mapping & FOLIO_MAPPING_FLAGS) == FOLIO_MAPPING_KSM)
> + if (folio_test_ksm(folio))
> u |= BIT_ULL(KPF_KSM);
> }
>
> @@ -181,10 +176,12 @@ u64 stable_page_flags(const struct page *page)
> * compound pages: export both head/tail info
> * they together define a compound page's start/end pos and order
> */
> - if (ps.idx == 0)
> - u |= kpf_copy_bit(k, KPF_COMPOUND_HEAD, PG_head);
> - else
> + if (ps.idx == 0) {
> + if (folio_test_head(folio))
> + u |= BIT_ULL(KPF_COMPOUND_HEAD);
> + } else {
> u |= BIT_ULL(KPF_COMPOUND_TAIL);
> + }
> if (folio_test_hugetlb(folio))
> u |= BIT_ULL(KPF_HUGE);
> else if (folio_test_large(folio) &&
> @@ -201,6 +198,9 @@ u64 stable_page_flags(const struct page *page)
> if (ps.flags & PAGE_SNAPSHOT_PG_BUDDY)
> u |= BIT_ULL(KPF_BUDDY);
>
> + if (ps.flags & PAGE_SNAPSHOT_PG_IDLE)
> + u |= BIT_ULL(KPF_IDLE);
> +
> if (folio_test_offline(folio))
> u |= BIT_ULL(KPF_OFFLINE);
> if (folio_test_pgtable(folio))
> @@ -208,42 +208,46 @@ u64 stable_page_flags(const struct page *page)
> if (folio_test_slab(folio))
> u |= BIT_ULL(KPF_SLAB);
>
> -#if defined(CONFIG_PAGE_IDLE_FLAG) && defined(CONFIG_64BIT)
> - u |= kpf_copy_bit(k, KPF_IDLE, PG_idle);
> -#else
> - if (ps.flags & PAGE_SNAPSHOT_PG_IDLE)
> - u |= BIT_ULL(KPF_IDLE);
> -#endif
> -
> - u |= kpf_copy_bit(k, KPF_LOCKED, PG_locked);
> - u |= kpf_copy_bit(k, KPF_DIRTY, PG_dirty);
> - u |= kpf_copy_bit(k, KPF_UPTODATE, PG_uptodate);
> - u |= kpf_copy_bit(k, KPF_WRITEBACK, PG_writeback);
> -
> - u |= kpf_copy_bit(k, KPF_LRU, PG_lru);
> - u |= kpf_copy_bit(k, KPF_REFERENCED, PG_referenced);
> - u |= kpf_copy_bit(k, KPF_ACTIVE, PG_active);
> - u |= kpf_copy_bit(k, KPF_RECLAIM, PG_reclaim);
> -
> -#define SWAPCACHE ((1 << PG_swapbacked) | (1 << PG_swapcache))
> - if ((k & SWAPCACHE) == SWAPCACHE)
> - u |= 1 << KPF_SWAPCACHE;
> - u |= kpf_copy_bit(k, KPF_SWAPBACKED, PG_swapbacked);
> -
> - u |= kpf_copy_bit(k, KPF_UNEVICTABLE, PG_unevictable);
> - u |= kpf_copy_bit(k, KPF_MLOCKED, PG_mlocked);
> -
> -#ifdef CONFIG_MEMORY_FAILURE
> - if (u & (1 << KPF_HUGE))
> - u |= kpf_copy_bit(k, KPF_HWPOISON, PG_hwpoison);
> - else
> - u |= kpf_copy_bit(ps.page_snapshot.flags.f, KPF_HWPOISON, PG_hwpoison);
> -#endif
> + if (folio_test_locked(folio))
> + u |= BIT_ULL(KPF_LOCKED);
> + if (folio_test_dirty(folio))
> + u |= BIT_ULL(KPF_DIRTY);
> + if (folio_test_uptodate(folio))
> + u |= BIT_ULL(KPF_UPTODATE);
> + if (folio_test_writeback(folio))
> + u |= BIT_ULL(KPF_WRITEBACK);
> +
> + if (folio_test_lru(folio))
> + u |= BIT_ULL(KPF_LRU);
> + if (folio_test_referenced(folio))
> + u |= BIT_ULL(KPF_REFERENCED);
> + if (folio_test_active(folio))
> + u |= BIT_ULL(KPF_ACTIVE);
> + if (folio_test_reclaim(folio))
> + u |= BIT_ULL(KPF_RECLAIM);
> +
> + if (folio_test_swapcache(folio))
> + u |= BIT_ULL(KPF_SWAPCACHE);
> + if (folio_test_swapbacked(folio))
> + u |= BIT_ULL(KPF_SWAPBACKED);
> + if (folio_test_unevictable(folio))
> + u |= BIT_ULL(KPF_UNEVICTABLE);
> + if (folio_test_mlocked(folio))
> + u |= BIT_ULL(KPF_MLOCKED);
> +
> + if ((folio_test_hugetlb(folio) && folio_test_hwpoison(folio))
> + || PageHWPoison(&ps.page_snapshot))
> + u |= BIT_ULL(KPF_HWPOISON);
> +
> + if (folio_test_reserved(folio))
> + u |= BIT_ULL(KPF_RESERVED);
> + if (folio_test_owner_2(folio))
> + u |= BIT_ULL(KPF_OWNER_2);
> + if (folio_test_private(folio))
> + u |= BIT_ULL(KPF_PRIVATE);
> + if (folio_test_private_2(folio))
> + u |= BIT_ULL(KPF_PRIVATE_2);
>
> - u |= kpf_copy_bit(k, KPF_RESERVED, PG_reserved);
> - u |= kpf_copy_bit(k, KPF_OWNER_2, PG_owner_2);
> - u |= kpf_copy_bit(k, KPF_PRIVATE, PG_private);
> - u |= kpf_copy_bit(k, KPF_PRIVATE_2, PG_private_2);
> u |= kpf_copy_bit(k, KPF_OWNER_PRIVATE, PG_owner_priv_1);
> u |= kpf_copy_bit(k, KPF_ARCH, PG_arch_1);
> #ifdef CONFIG_ARCH_USES_PG_ARCH_2
next prev parent reply other threads:[~2026-07-10 3:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260702110614.2176986-1-tujinjiang@huawei.com>
[not found] ` <61157b05-b22a-4bcf-942b-05225837b57b@kernel.org>
2026-07-03 3:00 ` [PATCH 0/2] fs: stable_page_flags(): use folio_test_*() helpers Jinjiang Tu
[not found] ` <20260702110614.2176986-3-tujinjiang@huawei.com>
2026-07-10 3:52 ` Jinjiang Tu [this message]
2026-07-10 11:29 ` [PATCH 2/2] " David Hildenbrand (Arm)
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=67066146-e371-46cd-bcbe-9c28ba8e890b@huawei.com \
--to=tujinjiang@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=david@kernel.org \
--cc=linmiaohe@huawei.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luizcap@redhat.com \
--cc=sunnanyong@huawei.com \
--cc=svetly.todorov@memverge.com \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.org \
--cc=xu.xin16@zte.com.cn \
--cc=ziy@nvidia.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