[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240626024924.1155558-3-ranxiaokai627@163.com>
Date: Wed, 26 Jun 2024 02:49:24 +0000
From: ran xiaokai <ranxiaokai627@....com>
To: akpm@...ux-foundation.org,
willy@...radead.org
Cc: vbabka@...e.cz,
svetly.todorov@...verge.com,
ran.xiaokai@....com.cn,
baohua@...nel.org,
ryan.roberts@....com,
peterx@...hat.com,
ziy@...dia.com,
linux-kernel@...r.kernel.org,
linux-mm@...ck.org,
linux-fsdevel@...r.kernel.org
Subject: [PATCH 2/2] kpageflags: fix wrong KPF_THP on non-pmd-mappable compound pages
From: Ran Xiaokai <ran.xiaokai@....com.cn>
KPF_COMPOUND_HEAD and KPF_COMPOUND_TAIL are set on "common" compound
pages, which means of any order, but KPF_THP should only be set
when the folio is a 2M pmd mappable THP. Since commit 19eaf44954df
("mm: thp: support allocation of anonymous multi-size THP"),
multiple orders of folios can be allocated and mapped to userspace,
so the folio_test_large() check is not sufficient here,
replace it with folio_test_pmd_mappable() to fix this.
Also kpageflags is not only for userspace memory but for all valid pfn
pages,including slab pages or drivers used pages, so the PG_lru and
is_anon check are unnecessary here.
Signed-off-by: Ran Xiaokai <ran.xiaokai@....com.cn>
---
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 2fb64bdb64eb..3e7b70449c2f 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -146,19 +146,13 @@ u64 stable_page_flags(const struct page *page)
u |= kpf_copy_bit(k, KPF_COMPOUND_HEAD, PG_head);
else
u |= 1 << KPF_COMPOUND_TAIL;
+
if (folio_test_hugetlb(folio))
u |= 1 << KPF_HUGE;
- /*
- * We need to check PageLRU/PageAnon
- * to make sure a given page is a thp, not a non-huge compound page.
- */
- else if (folio_test_large(folio)) {
- if ((k & (1 << PG_lru)) || is_anon)
- u |= 1 << KPF_THP;
- else if (is_huge_zero_folio(folio)) {
+ else if (folio_test_pmd_mappable(folio)) {
+ u |= 1 << KPF_THP;
+ if (is_huge_zero_folio(folio))
u |= 1 << KPF_ZERO_PAGE;
- u |= 1 << KPF_THP;
- }
} else if (is_zero_pfn(page_to_pfn(page)))
u |= 1 << KPF_ZERO_PAGE;
--
2.15.2
Powered by blists - more mailing lists