[v1,3/5] mm, kpageflags: separate code path for hugetlb pages

Message ID 20231010142801.3780917-4-naoya.horiguchi@linux.dev
State New
Headers
Series mm, kpageflags: support folio and fix output for compound pages |

Commit Message

Naoya Horiguchi Oct. 10, 2023, 2:27 p.m. UTC
  From: Naoya Horiguchi <naoya.horiguchi@nec.com>

Hugetlb pages use some struct page's field of the first few tail pages for
internal use.  There's no point to parse and show the kpageflags info based
on tail pages, so return immediately when finding hugetlb tail pages.

Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
---
 fs/proc/page.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
  

Patch

diff --git a/fs/proc/page.c b/fs/proc/page.c
index 78f675f791c1..9b6ded8a2c90 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -135,23 +135,20 @@  u64 stable_page_flags(struct page *page)
 	if (PageKsm(page))
 		u |= 1 << KPF_KSM;
 
-	/*
-	 * compound pages: export both head/tail info
-	 * they together define a compound page's start/end pos and order
-	 */
-	if (PageHead(page))
-		u |= 1 << KPF_COMPOUND_HEAD;
-	if (PageTail(page))
-		u |= 1 << KPF_COMPOUND_TAIL;
-	if (PageHuge(page))
+	if (PageHuge(page)) {
 		u |= 1 << KPF_HUGE;
+		if (PageHead(page))
+			u |= 1 << KPF_COMPOUND_HEAD;
+		if (PageTail(page)) {
+			u |= 1 << KPF_COMPOUND_TAIL;
+			return u;
+		}
 	/*
-	 * PageTransCompound can be true for non-huge compound pages (slab
-	 * pages or pages allocated by drivers with __GFP_COMP) because it
-	 * just checks PG_head/PG_tail, so we need to check PageLRU/PageAnon
-	 * to make sure a given page is a thp, not a non-huge compound page.
+	 * PageTransCompound can be true for any types of compound pages,
+	 * because it just checks PG_head and PageTail, but at this point
+	 * PageSlab and PageHuge are already checked to be false.
 	 */
-	else if (PageTransCompound(page)) {
+	} else if (PageTransCompound(page)) {
 		struct page *head = compound_head(page);
 
 		/*