[PATCH v14 134/138] mm: Support arbitrary THP sizes
From: Matthew Wilcox (Oracle)
Date: Thu Jul 15 2021 - 01:27:00 EST
Use the compound size of the page instead of assuming PTE or PMD size.
Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
---
include/linux/huge_mm.h | 8 ++------
include/linux/mm.h | 42 ++++++++++++++++++++---------------------
2 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index f280f33ff223..b70318fe7863 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -257,9 +257,7 @@ static inline spinlock_t *pud_trans_huge_lock(pud_t *pud,
static inline unsigned int thp_order(struct page *page)
{
VM_BUG_ON_PGFLAGS(PageTail(page), page);
- if (PageHead(page))
- return HPAGE_PMD_ORDER;
- return 0;
+ return compound_order(page);
}
/**
@@ -269,9 +267,7 @@ static inline unsigned int thp_order(struct page *page)
static inline int thp_nr_pages(struct page *page)
{
VM_BUG_ON_PGFLAGS(PageTail(page), page);
- if (PageHead(page))
- return HPAGE_PMD_NR;
- return 1;
+ return compound_nr(page);
}
struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr,
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 99f5f736be64..df1f4c4976df 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -715,6 +715,27 @@ int vma_is_stack_for_current(struct vm_area_struct *vma);
struct mmu_gather;
struct inode;
+static inline unsigned int compound_order(struct page *page)
+{
+ if (!PageHead(page))
+ return 0;
+ return page[1].compound_order;
+}
+
+/* Returns the number of pages in this potentially compound page. */
+static inline unsigned long compound_nr(struct page *page)
+{
+ if (!PageHead(page))
+ return 1;
+ return page[1].compound_nr;
+}
+
+static inline void set_compound_order(struct page *page, unsigned int order)
+{
+ page[1].compound_order = order;
+ page[1].compound_nr = 1U << order;
+}
+
#include <linux/huge_mm.h>
/*
@@ -937,13 +958,6 @@ static inline void destroy_compound_page(struct page *page)
compound_page_dtors[page[1].compound_dtor](page);
}
-static inline unsigned int compound_order(struct page *page)
-{
- if (!PageHead(page))
- return 0;
- return page[1].compound_order;
-}
-
/**
* folio_order - The allocation order of a folio.
* @folio: The folio.
@@ -981,20 +995,6 @@ static inline int compound_pincount(struct page *page)
return head_compound_pincount(page);
}
-static inline void set_compound_order(struct page *page, unsigned int order)
-{
- page[1].compound_order = order;
- page[1].compound_nr = 1U << order;
-}
-
-/* Returns the number of pages in this potentially compound page. */
-static inline unsigned long compound_nr(struct page *page)
-{
- if (!PageHead(page))
- return 1;
- return page[1].compound_nr;
-}
-
/* Returns the number of bytes in this potentially compound page. */
static inline unsigned long page_size(struct page *page)
{
--
2.30.2