Skip to content

Commit 4c8763e

Browse files
ranxiaokaiakpm00
authored andcommitted
kpageflags: detect isolated KPF_THP folios
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. [[email protected]: directly use is_zero_folio(), per David] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ran Xiaokai <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Andrei Vagin <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Muhammad Usama Anjum <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Svetly Todorov <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Zi Yan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 00f5810 commit 4c8763e

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

Documentation/admin-guide/mm/pagemap.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Short descriptions to the page flags
118118
21 - KSM
119119
Identical memory pages dynamically shared between one or more processes.
120120
22 - THP
121-
Contiguous pages which construct transparent hugepages.
121+
Contiguous pages which construct THP of any size and mapped by any granularity.
122122
23 - OFFLINE
123123
The page is logically offline.
124124
24 - ZERO_PAGE
@@ -231,7 +231,7 @@ Following flags about pages are currently supported:
231231
- ``PAGE_IS_PRESENT`` - Page is present in the memory
232232
- ``PAGE_IS_SWAPPED`` - Page is in swapped
233233
- ``PAGE_IS_PFNZERO`` - Page has zero PFN
234-
- ``PAGE_IS_HUGE`` - Page is THP or Hugetlb backed
234+
- ``PAGE_IS_HUGE`` - Page is PMD-mapped THP or Hugetlb backed
235235
- ``PAGE_IS_SOFT_DIRTY`` - Page is soft-dirty
236236

237237
The ``struct pm_scan_arg`` is used as the argument of the IOCTL.

fs/proc/page.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,16 @@ u64 stable_page_flags(const struct page *page)
147147
u |= 1 << KPF_COMPOUND_TAIL;
148148
if (folio_test_hugetlb(folio))
149149
u |= 1 << KPF_HUGE;
150-
/*
151-
* We need to check PageLRU/PageAnon
152-
* to make sure a given page is a thp, not a non-huge compound page.
153-
*/
154-
else if (folio_test_large(folio)) {
155-
if ((k & (1 << PG_lru)) || is_anon)
156-
u |= 1 << KPF_THP;
157-
else if (is_huge_zero_folio(folio)) {
158-
u |= 1 << KPF_ZERO_PAGE;
159-
u |= 1 << KPF_THP;
160-
}
161-
} else if (is_zero_pfn(page_to_pfn(page)))
150+
else if (folio_test_large(folio) &&
151+
folio_test_large_rmappable(folio)) {
152+
/* Note: we indicate any THPs here, not just PMD-sized ones */
153+
u |= 1 << KPF_THP;
154+
} else if (is_huge_zero_folio(folio)) {
162155
u |= 1 << KPF_ZERO_PAGE;
156+
u |= 1 << KPF_THP;
157+
} else if (is_zero_folio(folio)) {
158+
u |= 1 << KPF_ZERO_PAGE;
159+
}
163160

164161
/*
165162
* Caveats on high order pages: PG_buddy and PG_slab will only be set

0 commit comments

Comments
 (0)