Skip to content

Commit 18788cf

Browse files
author
Matthew Wilcox (Oracle)
committed
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) <[email protected]>
1 parent 421f1ab commit 18788cf

File tree

2 files changed

+31
-47
lines changed

2 files changed

+31
-47
lines changed

include/linux/huge_mm.h

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -250,30 +250,6 @@ static inline spinlock_t *pud_trans_huge_lock(pud_t *pud,
250250
return NULL;
251251
}
252252

253-
/**
254-
* thp_order - Order of a transparent huge page.
255-
* @page: Head page of a transparent huge page.
256-
*/
257-
static inline unsigned int thp_order(struct page *page)
258-
{
259-
VM_BUG_ON_PGFLAGS(PageTail(page), page);
260-
if (PageHead(page))
261-
return HPAGE_PMD_ORDER;
262-
return 0;
263-
}
264-
265-
/**
266-
* thp_nr_pages - The number of regular pages in this huge page.
267-
* @page: The head page of a huge page.
268-
*/
269-
static inline int thp_nr_pages(struct page *page)
270-
{
271-
VM_BUG_ON_PGFLAGS(PageTail(page), page);
272-
if (PageHead(page))
273-
return HPAGE_PMD_NR;
274-
return 1;
275-
}
276-
277253
/**
278254
* folio_test_pmd_mappable - Can we map this folio with a PMD?
279255
* @folio: The folio to test
@@ -336,18 +312,6 @@ static inline struct list_head *page_deferred_list(struct page *page)
336312
#define HPAGE_PUD_MASK ({ BUILD_BUG(); 0; })
337313
#define HPAGE_PUD_SIZE ({ BUILD_BUG(); 0; })
338314

339-
static inline unsigned int thp_order(struct page *page)
340-
{
341-
VM_BUG_ON_PGFLAGS(PageTail(page), page);
342-
return 0;
343-
}
344-
345-
static inline int thp_nr_pages(struct page *page)
346-
{
347-
VM_BUG_ON_PGFLAGS(PageTail(page), page);
348-
return 1;
349-
}
350-
351315
static inline bool folio_test_pmd_mappable(struct folio *folio)
352316
{
353317
return false;
@@ -489,15 +453,4 @@ static inline int split_folio_to_list(struct folio *folio,
489453
return split_huge_page_to_list(&folio->page, list);
490454
}
491455

492-
/**
493-
* thp_size - Size of a transparent huge page.
494-
* @page: Head page of a transparent huge page.
495-
*
496-
* Return: Number of bytes in this page.
497-
*/
498-
static inline unsigned long thp_size(struct page *page)
499-
{
500-
return PAGE_SIZE << thp_order(page);
501-
}
502-
503456
#endif /* _LINUX_HUGE_MM_H */

include/linux/mm.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,37 @@ static inline unsigned int page_shift(struct page *page)
939939
return PAGE_SHIFT + compound_order(page);
940940
}
941941

942+
/**
943+
* thp_order - Order of a transparent huge page.
944+
* @page: Head page of a transparent huge page.
945+
*/
946+
static inline unsigned int thp_order(struct page *page)
947+
{
948+
VM_BUG_ON_PGFLAGS(PageTail(page), page);
949+
return compound_order(page);
950+
}
951+
952+
/**
953+
* thp_nr_pages - The number of regular pages in this huge page.
954+
* @page: The head page of a huge page.
955+
*/
956+
static inline int thp_nr_pages(struct page *page)
957+
{
958+
VM_BUG_ON_PGFLAGS(PageTail(page), page);
959+
return compound_nr(page);
960+
}
961+
962+
/**
963+
* thp_size - Size of a transparent huge page.
964+
* @page: Head page of a transparent huge page.
965+
*
966+
* Return: Number of bytes in this page.
967+
*/
968+
static inline unsigned long thp_size(struct page *page)
969+
{
970+
return PAGE_SIZE << thp_order(page);
971+
}
972+
942973
void free_compound_page(struct page *page);
943974

944975
#ifdef CONFIG_MMU

0 commit comments

Comments
 (0)