]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
kpageflags: detect isolated KPF_THP folios
authorRan Xiaokai <ran.xiaokai@zte.com.cn>
Fri, 5 Jul 2024 10:43:43 +0000 (10:43 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 12 Jul 2024 22:52:21 +0000 (15:52 -0700)
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.

[ran.xiaokai@zte.com.cn: directly use is_zero_folio(), per David]
Link: https://lkml.kernel.org/r/20240708062601.165215-1-ranxiaokai627@163.com
Link: https://lkml.kernel.org/r/20240705104343.112680-1-ranxiaokai627@163.com
Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Andrei Vagin <avagin@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Svetly Todorov <svetly.todorov@memverge.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Documentation/admin-guide/mm/pagemap.rst
fs/proc/page.c

index f2817a8015962e5b88b59269b33c6bb1ed512f7c..caba0f52dd36c6e668260802c06cd9f11c36d275 100644 (file)
@@ -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
@@ -231,7 +231,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.
index e8440db8cfbf9a716ab7c8a590c840c8b1b5378f..b7a5c84b58199e2a7d8f8dd97716641ffa1ffc65 100644 (file)
@@ -147,19 +147,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_folio(folio)) {
+               u |= 1 << KPF_ZERO_PAGE;
+       }
 
        /*
         * Caveats on high order pages: PG_buddy and PG_slab will only be set