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>,
<tujinjiang@huawei.com>
Subject: [PATCH v2 2/3] fs: stable_page_flags(): use folio_test_*() helpers
Date: Mon, 20 Jul 2026 11:30:20 +0800 [thread overview]
Message-ID: <20260720033021.4091944-3-tujinjiang@huawei.com> (raw)
In-Reply-To: <20260720033021.4091944-1-tujinjiang@huawei.com>
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.
Since commit 476d87d6a061 ("fs: stable_page_flags(): use snapshot_page()"),
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. Only convert cfolio-specific flags (i.e., anon, ksm, swapcache)
to folio_test_*() helpers, which reduces redundant code. Keep others
unchanged due to they aren't folio-specific flags or coverting them doesn't
cleanup.
No functional change is intended.
Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
---
fs/proc/page.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/fs/proc/page.c b/fs/proc/page.c
index ee39b321f1c6..b3c1d7a7604d 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;
/*
@@ -161,19 +159,16 @@ u64 stable_page_flags(const struct page *page)
snapshot_page(&ps, 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);
}
@@ -225,11 +220,10 @@ u64 stable_page_flags(const struct page *page)
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)
+ if (folio_test_swapcache(folio))
u |= BIT_ULL(KPF_SWAPCACHE);
- u |= kpf_copy_bit(k, KPF_SWAPBACKED, PG_swapbacked);
+ 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);
--
2.43.0
next prev parent reply other threads:[~2026-07-20 3:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 3:30 [PATCH v2 0/3] cleanup for stable_page_flags() Jinjiang Tu
2026-07-20 3:30 ` [PATCH v2 1/3] fs: stable_page_flags(): use BIT_ULL() for KPF flags Jinjiang Tu
2026-07-20 3:30 ` Jinjiang Tu [this message]
2026-07-20 9:30 ` [PATCH v2 2/3] fs: stable_page_flags(): use folio_test_*() helpers David Hildenbrand (Arm)
2026-07-20 3:30 ` [PATCH v2 3/3] fs: stable_page_flags(): simplify KPF_IDLE handling Jinjiang Tu
2026-07-20 9:32 ` David Hildenbrand (Arm)
2026-07-20 5:30 ` [PATCH v2 0/3] cleanup for stable_page_flags() Andrew Morton
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=20260720033021.4091944-3-tujinjiang@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