[PATCH v3] kpageflags: respect folio head-page flag placement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




---
Page flags are now stored per-folio. Change kpageflags to report these
per-folio flags where appropriate.

Most folio flags are set on the head page, i.e. *folio_flag(page, 0).

Only three are set on the second page -- PG_has_hwpoisoned, PG_large_rmappable,
and PG_hugetlb. kpageflags doesn't report the first two, and the PG_hugetlb
check is handled by calls to PageHuge/PageTransCompound(), so no code changes
are required for these flags.

mm/memory-failure.c applies PG_HWPoison via SetPageHWPoison(page).
This call falls through to the SetPage##uname macro in
include/linux/page-flags.h, which sets the corresponding PG_##lname bit
on the given page struct. Therefore KPF_HWPOISON must come from page->flags.

arch/xtensa/mm/cache.c tests and sets the PG_arch1 bit in both
folio->flags and page->flags. So both sources are OR'd into KPF_ARCH.

As for arch2 and arch3, Kefeng Wang reported that they appear only as
arm64-specific aliases: namely, PG_mte_tagged and PG_mte_lock. 
Both are applied to page->flags via set_bit() in arch/arm64/include/asm/mte.h.
So those must come from page->flags, too.

Signed-off-by: Svetly Todorov <svetly.todorov@xxxxxxxxxxxx>
Suggested-by: Matthew Wilcox <willy@xxxxxxxxxxxxx>
Suggested-by: Gregory Price <gregory.price@xxxxxxxxxxxx>
Suggested-by: Kefeng Wang <wangkefeng.wang@xxxxxxxxxx>
Link: https://lore.kernel.org/all/20231030180005.2046-1-gregory.price@xxxxxxxxxxxx/
Link: https://80x24.org/lore/linux-mm/20231110033324.2455523-4-wangkefeng.wang@xxxxxxxxxx/
Link: https://80x24.org/lore/linux-mm/438ba640-c205-4034-886e-6a7231f3d210@xxxxxxxxxx/
---
 fs/proc/page.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/proc/page.c b/fs/proc/page.c
index 195b077c0fac..290470819fa2 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -110,6 +110,7 @@ static inline u64 kpf_copy_bit(u64 kflags, int ubit, int kbit)
 u64 stable_page_flags(struct page *page)
 {
 	u64 k;
+	u64 p;
 	u64 u;
 
 	/*
@@ -119,7 +120,8 @@ u64 stable_page_flags(struct page *page)
 	if (!page)
 		return 1 << KPF_NOPAGE;
 
-	k = page->flags;
+	k = *folio_flags(page, 0);
+	p = page->flags;
 	u = 0;
 
 	/*
@@ -205,7 +207,7 @@ u64 stable_page_flags(struct page *page)
 	u |= kpf_copy_bit(k, KPF_MLOCKED,	PG_mlocked);
 
 #ifdef CONFIG_MEMORY_FAILURE
-	u |= kpf_copy_bit(k, KPF_HWPOISON,	PG_hwpoison);
+	u |= kpf_copy_bit(p, KPF_HWPOISON,	PG_hwpoison);
 #endif
 
 #ifdef CONFIG_ARCH_USES_PG_UNCACHED
@@ -216,11 +218,14 @@ u64 stable_page_flags(struct page *page)
 	u |= kpf_copy_bit(k, KPF_MAPPEDTODISK,	PG_mappedtodisk);
 	u |= kpf_copy_bit(k, KPF_PRIVATE,	PG_private);
 	u |= kpf_copy_bit(k, KPF_PRIVATE_2,	PG_private_2);
+	u |= kpf_copy_bit(p, KPF_PRIVATE,	PG_private);
+	u |= kpf_copy_bit(p, 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);
+	u |= kpf_copy_bit(p, KPF_ARCH,		PG_arch_1);
 #ifdef CONFIG_ARCH_USES_PG_ARCH_X
-	u |= kpf_copy_bit(k, KPF_ARCH_2,	PG_arch_2);
-	u |= kpf_copy_bit(k, KPF_ARCH_3,	PG_arch_3);
+	u |= kpf_copy_bit(p, KPF_ARCH_2,	PG_arch_2);
+	u |= kpf_copy_bit(p, KPF_ARCH_3,	PG_arch_3);
 #endif
 
 	return u;

---
base-commit: e8f897f4afef0031fe618a8e94127a0934896aba
change-id: 20240319-kpageflags-svetly-9faa11b17022

Best regards,
-- 
Svetly Todorov <svetly.todorov@xxxxxxxxxxxx>





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux