summaryrefslogtreecommitdiff
path: root/include/linux/mm.h
diff options
context:
space:
mode:
authorMatthew Wilcox (Oracle) <willy@infradead.org>2020-05-29 20:54:38 -0400
committerMatthew Wilcox (Oracle) <willy@infradead.org>2022-03-21 13:01:36 -0400
commit18788cfa236967741b83db1035ab24539e2a21bb (patch)
tree32f1f28b2ed72969ca41269eab067bd4cac577b8 /include/linux/mm.h
parent421f1ab48452af48b64e205de1caca3d1ba415f4 (diff)
downloadlwn-18788cfa236967741b83db1035ab24539e2a21bb.tar.gz
lwn-18788cfa236967741b83db1035ab24539e2a21bb.zip
mm: Support arbitrary THP sizes
For code which has not yet been converted from THP to folios, use the compound size of the page instead of assuming PTE or PMD size. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Diffstat (limited to 'include/linux/mm.h')
-rw-r--r--include/linux/mm.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h
index a879c583f665..c1966ad34142 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -939,6 +939,37 @@ static inline unsigned int page_shift(struct page *page)
return PAGE_SHIFT + compound_order(page);
}
+/**
+ * thp_order - Order of a transparent huge page.
+ * @page: Head page of a transparent huge page.
+ */
+static inline unsigned int thp_order(struct page *page)
+{
+ VM_BUG_ON_PGFLAGS(PageTail(page), page);
+ return compound_order(page);
+}
+
+/**
+ * thp_nr_pages - The number of regular pages in this huge page.
+ * @page: The head page of a huge page.
+ */
+static inline int thp_nr_pages(struct page *page)
+{
+ VM_BUG_ON_PGFLAGS(PageTail(page), page);
+ return compound_nr(page);
+}
+
+/**
+ * thp_size - Size of a transparent huge page.
+ * @page: Head page of a transparent huge page.
+ *
+ * Return: Number of bytes in this page.
+ */
+static inline unsigned long thp_size(struct page *page)
+{
+ return PAGE_SIZE << thp_order(page);
+}
+
void free_compound_page(struct page *page);
#ifdef CONFIG_MMU