* [PATCH] kpageflags: detect isolated KPF_THP folios
@ 2024-07-05 10:43 ran xiaokai
2024-07-05 14:03 ` David Hildenbrand
0 siblings, 1 reply; 2+ messages in thread
From: ran xiaokai @ 2024-07-05 10:43 UTC (permalink / raw)
To: akpm, david, corbet, usama.anjum, avagin
Cc: linux-mm, vbabka, svetly.todorov, ran.xiaokai, ryan.roberts, ziy,
linux-kernel, linux-fsdevel
From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
When folio is isolated, the PG_lru bit is cleared. So the PG_lru
check in stable_page_flags() will miss this kind of isolated folios.
Use folio_test_large_rmappable() instead to also include isolated folios.
Since pagecache supports large folios and the introduction of mTHP,
the semantics of KPF_THP have been expanded, now it indicates
not only PMD-sized THP. Update related documentation to clearly state
that KPF_THP indicates multiple order THPs.
v1:
https://lore.kernel.org/lkml/20240626024924.1155558-3-ranxiaokai627@163.com/
Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
---
Documentation/admin-guide/mm/pagemap.rst | 4 ++--
fs/proc/page.c | 21 +++++++++------------
2 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst
index f5f065c67615..0a8a4decdb72 100644
--- a/Documentation/admin-guide/mm/pagemap.rst
+++ b/Documentation/admin-guide/mm/pagemap.rst
@@ -118,7 +118,7 @@ Short descriptions to the page flags
21 - KSM
Identical memory pages dynamically shared between one or more processes.
22 - THP
- Contiguous pages which construct transparent hugepages.
+ Contiguous pages which construct THP of any size and mapped by any granularity.
23 - OFFLINE
The page is logically offline.
24 - ZERO_PAGE
@@ -252,7 +252,7 @@ Following flags about pages are currently supported:
- ``PAGE_IS_PRESENT`` - Page is present in the memory
- ``PAGE_IS_SWAPPED`` - Page is in swapped
- ``PAGE_IS_PFNZERO`` - Page has zero PFN
-- ``PAGE_IS_HUGE`` - Page is THP or Hugetlb backed
+- ``PAGE_IS_HUGE`` - Page is PMD-mapped THP or Hugetlb backed
- ``PAGE_IS_SOFT_DIRTY`` - Page is soft-dirty
The ``struct pm_scan_arg`` is used as the argument of the IOCTL.
diff --git a/fs/proc/page.c b/fs/proc/page.c
index 2fb64bdb64eb..76f2a412aa93 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -148,19 +148,16 @@ u64 stable_page_flags(const struct page *page)
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)) {
- u |= 1 << KPF_ZERO_PAGE;
- u |= 1 << KPF_THP;
- }
- } else if (is_zero_pfn(page_to_pfn(page)))
+ 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;
+ } else 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;
+ }
/*
* Caveats on high order pages: PG_buddy and PG_slab will only be set
--
2.15.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] kpageflags: detect isolated KPF_THP folios
2024-07-05 10:43 [PATCH] kpageflags: detect isolated KPF_THP folios ran xiaokai
@ 2024-07-05 14:03 ` David Hildenbrand
0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2024-07-05 14:03 UTC (permalink / raw)
To: ran xiaokai, akpm, corbet, usama.anjum, avagin
Cc: linux-mm, vbabka, svetly.todorov, ran.xiaokai, ryan.roberts, ziy,
linux-kernel, linux-fsdevel, yangge1116
> - } else if (is_zero_pfn(page_to_pfn(page)))
> + 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;
> + } else if (is_huge_zero_folio(folio)) {
> u |= 1 << KPF_ZERO_PAGE;
> + u |= 1 << KPF_THP;
> + } else if (is_zero_pfn(page_to_pfn(page))) {
We should also directly switch to "is_zero_folio(folio)" here
> + u |= 1 << KPF_ZERO_PAGE;
> + }
>
> /*
> * Caveats on high order pages: PG_buddy and PG_slab will only be set
Especially relevant in context of:
https://lkml.kernel.org/r/1720075944-27201-1-git-send-email-yangge1116@126.com
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-07-05 14:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-05 10:43 [PATCH] kpageflags: detect isolated KPF_THP folios ran xiaokai
2024-07-05 14:03 ` David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).