* [PATCH v2 0/3] cleanup for stable_page_flags()
@ 2026-07-20 3:30 Jinjiang Tu
2026-07-20 3:30 ` [PATCH v2 1/3] fs: stable_page_flags(): use BIT_ULL() for KPF flags Jinjiang Tu
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Jinjiang Tu @ 2026-07-20 3:30 UTC (permalink / raw)
To: akpm, ziy, david, luizcap, willy, linmiaohe, svetly.todorov,
xu.xin16, chengming.zhou, linux-fsdevel, linux-mm
Cc: wangkefeng.wang, sunnanyong, tujinjiang
This series cleans up stable_page_flags(), see the details in the commit
message.
Changes since v1:
* add missing "1 << KPF_*" covertions for patch 1
* collect Acked-by for patch 1
* only convert folio-specific flags to folio_test_*() helpers
* move KPF_IDLE cleanup to a separate patch
Jinjiang Tu (3):
fs: stable_page_flags(): use BIT_ULL() for KPF flags
fs: stable_page_flags(): use folio_test_*() helpers
fs: stable_page_flags(): simplify KPF_IDLE handling
fs/proc/page.c | 56 +++++++++++++++++++++-----------------------------
1 file changed, 23 insertions(+), 33 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/3] fs: stable_page_flags(): use BIT_ULL() for KPF flags
2026-07-20 3:30 [PATCH v2 0/3] cleanup for stable_page_flags() Jinjiang Tu
@ 2026-07-20 3:30 ` Jinjiang Tu
2026-07-20 3:30 ` [PATCH v2 2/3] fs: stable_page_flags(): use folio_test_*() helpers Jinjiang Tu
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Jinjiang Tu @ 2026-07-20 3:30 UTC (permalink / raw)
To: akpm, ziy, david, luizcap, willy, linmiaohe, svetly.todorov,
xu.xin16, chengming.zhou, linux-fsdevel, linux-mm
Cc: wangkefeng.wang, sunnanyong, tujinjiang
The stable_page_flags() function currently sets page flag bits using
"1 << KPF_xxx" for various KPF_* definitions. KPF_* may be larger than 32,
which will trigger -Wshift-count-overflow warning. All KPF_* values
currently used in "1 << KPF_xxx" are smaller than 33, so no warning is
triggered with current code.
Replace all occurrences of "1 << KPF_*" with the BIT_ULL() macro to
ensure all shifts are performed on a 64-bit unsigned type. This makes
the code robust, and safe for future extension.
No functional change is intended.
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Acked-by: Zi Yan <ziy@nvidia.com>
Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
---
fs/proc/page.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/fs/proc/page.c b/fs/proc/page.c
index 7d9387143435..ee39b321f1c6 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -157,7 +157,7 @@ u64 stable_page_flags(const struct page *page)
* it differentiates a memory hole from a page with no flags
*/
if (!page)
- return 1 << KPF_NOPAGE;
+ return BIT_ULL(KPF_NOPAGE);
snapshot_page(&ps, page);
folio = &ps.folio_snapshot;
@@ -170,11 +170,11 @@ u64 stable_page_flags(const struct page *page)
* pseudo flags for the well known (anonymous) memory mapped pages
*/
if (folio_mapped(folio))
- u |= 1 << KPF_MMAP;
+ u |= BIT_ULL(KPF_MMAP);
if (is_anon) {
- u |= 1 << KPF_ANON;
+ u |= BIT_ULL(KPF_ANON);
if ((mapping & FOLIO_MAPPING_FLAGS) == FOLIO_MAPPING_KSM)
- u |= 1 << KPF_KSM;
+ u |= BIT_ULL(KPF_KSM);
}
/*
@@ -184,35 +184,35 @@ u64 stable_page_flags(const struct page *page)
if (ps.idx == 0)
u |= kpf_copy_bit(k, KPF_COMPOUND_HEAD, PG_head);
else
- u |= 1 << KPF_COMPOUND_TAIL;
+ u |= BIT_ULL(KPF_COMPOUND_TAIL);
if (folio_test_hugetlb(folio))
- u |= 1 << KPF_HUGE;
+ u |= BIT_ULL(KPF_HUGE);
else if (folio_test_large(folio) &&
folio_test_large_rmappable(folio)) {
/* Note: we indicate any THPs here, not just PMD-sized ones */
- u |= 1 << KPF_THP;
+ u |= BIT_ULL(KPF_THP);
} else if (is_huge_zero_pfn(ps.pfn)) {
- u |= 1 << KPF_ZERO_PAGE;
- u |= 1 << KPF_THP;
+ u |= BIT_ULL(KPF_ZERO_PAGE);
+ u |= BIT_ULL(KPF_THP);
} else if (is_zero_pfn(ps.pfn)) {
- u |= 1 << KPF_ZERO_PAGE;
+ u |= BIT_ULL(KPF_ZERO_PAGE);
}
if (ps.flags & PAGE_SNAPSHOT_PG_BUDDY)
- u |= 1 << KPF_BUDDY;
+ u |= BIT_ULL(KPF_BUDDY);
if (folio_test_offline(folio))
- u |= 1 << KPF_OFFLINE;
+ u |= BIT_ULL(KPF_OFFLINE);
if (folio_test_pgtable(folio))
- u |= 1 << KPF_PGTABLE;
+ u |= BIT_ULL(KPF_PGTABLE);
if (folio_test_slab(folio))
- u |= 1 << KPF_SLAB;
+ 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 |= 1 << KPF_IDLE;
+ u |= BIT_ULL(KPF_IDLE);
#endif
u |= kpf_copy_bit(k, KPF_LOCKED, PG_locked);
@@ -227,14 +227,14 @@ u64 stable_page_flags(const struct page *page)
#define SWAPCACHE ((1 << PG_swapbacked) | (1 << PG_swapcache))
if ((k & SWAPCACHE) == SWAPCACHE)
- u |= 1 << KPF_SWAPCACHE;
+ u |= BIT_ULL(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))
+ if (u & BIT_ULL(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);
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/3] fs: stable_page_flags(): use folio_test_*() helpers
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
2026-07-20 9:30 ` 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 5:30 ` [PATCH v2 0/3] cleanup for stable_page_flags() Andrew Morton
3 siblings, 1 reply; 7+ messages in thread
From: Jinjiang Tu @ 2026-07-20 3:30 UTC (permalink / raw)
To: akpm, ziy, david, luizcap, willy, linmiaohe, svetly.todorov,
xu.xin16, chengming.zhou, linux-fsdevel, linux-mm
Cc: wangkefeng.wang, sunnanyong, tujinjiang
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/3] fs: stable_page_flags(): simplify KPF_IDLE handling
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 ` [PATCH v2 2/3] fs: stable_page_flags(): use folio_test_*() helpers Jinjiang Tu
@ 2026-07-20 3:30 ` 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
3 siblings, 1 reply; 7+ messages in thread
From: Jinjiang Tu @ 2026-07-20 3:30 UTC (permalink / raw)
To: akpm, ziy, david, luizcap, willy, linmiaohe, svetly.todorov,
xu.xin16, chengming.zhou, linux-fsdevel, linux-mm
Cc: wangkefeng.wang, sunnanyong, tujinjiang
For KPF_IDLE, folio_test_idle() check in set_ps_flags() already handles
all config cases, so remove the duplicate code in stable_page_flags() that
deals with CONFIG_PAGE_IDLE_FLAG for the 64‑bit case.
No functional change is intended.
Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
---
fs/proc/page.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/fs/proc/page.c b/fs/proc/page.c
index b3c1d7a7604d..260772b20bd9 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -196,6 +196,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))
@@ -203,13 +206,6 @@ 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);
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/3] cleanup for stable_page_flags()
2026-07-20 3:30 [PATCH v2 0/3] cleanup for stable_page_flags() Jinjiang Tu
` (2 preceding siblings ...)
2026-07-20 3:30 ` [PATCH v2 3/3] fs: stable_page_flags(): simplify KPF_IDLE handling Jinjiang Tu
@ 2026-07-20 5:30 ` Andrew Morton
3 siblings, 0 replies; 7+ messages in thread
From: Andrew Morton @ 2026-07-20 5:30 UTC (permalink / raw)
To: Jinjiang Tu
Cc: ziy, david, luizcap, willy, linmiaohe, svetly.todorov, xu.xin16,
chengming.zhou, linux-fsdevel, linux-mm, wangkefeng.wang,
sunnanyong, Luiz Capitulino
On Mon, 20 Jul 2026 11:30:18 +0800 Jinjiang Tu <tujinjiang@huawei.com> wrote:
> This series cleans up stable_page_flags(), see the details in the commit
> message.
Thanks, I'll await further review input on this series.
AI review might have found a couple of pre-existing issues. Arguably
both are around the page-snapshotting code:
https://sashiko.dev/#/patchset/20260720033021.4091944-1-tujinjiang@huawei.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/3] fs: stable_page_flags(): use folio_test_*() helpers
2026-07-20 3:30 ` [PATCH v2 2/3] fs: stable_page_flags(): use folio_test_*() helpers Jinjiang Tu
@ 2026-07-20 9:30 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 7+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-20 9:30 UTC (permalink / raw)
To: Jinjiang Tu, akpm, ziy, luizcap, willy, linmiaohe, svetly.todorov,
xu.xin16, chengming.zhou, linux-fsdevel, linux-mm
Cc: wangkefeng.wang, sunnanyong
On 7/20/26 04:30, Jinjiang Tu wrote:
> 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>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 3/3] fs: stable_page_flags(): simplify KPF_IDLE handling
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)
0 siblings, 0 replies; 7+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-20 9:32 UTC (permalink / raw)
To: Jinjiang Tu, akpm, ziy, luizcap, willy, linmiaohe, svetly.todorov,
xu.xin16, chengming.zhou, linux-fsdevel, linux-mm
Cc: wangkefeng.wang, sunnanyong
On 7/20/26 04:30, Jinjiang Tu wrote:
> For KPF_IDLE, folio_test_idle() check in set_ps_flags() already handles
> all config cases, so remove the duplicate code in stable_page_flags() that
> deals with CONFIG_PAGE_IDLE_FLAG for the 64‑bit case.
>
> No functional change is intended.
>
> Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-07-20 9:32 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2 2/3] fs: stable_page_flags(): use folio_test_*() helpers Jinjiang Tu
2026-07-20 9:30 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox