On Tue Jun 25, 2024 at 10:49 PM EDT, ran xiaokai wrote: > From: Ran Xiaokai <ran.xiaokai@xxxxxxxxxx> > > 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. But THP is userspace memory. slab pages or driver pages cannot be THP. > > Signed-off-by: Ran Xiaokai <ran.xiaokai@xxxxxxxxxx> > --- > 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; > + Unnecessary new line. > 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; lru and anon check should stay. > + 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; > -- Best Regards, Yan, Zi
Attachment:
signature.asc
Description: PGP signature