Skip to content

Commit 04a42e7

Browse files
sidkumar99akpm00
authored andcommitted
mm: move folio_set_compound_order() to mm/internal.h
folio_set_compound_order() is moved to an mm-internal location so external folio users cannot misuse this function. Change the name of the function to folio_set_order() and use WARN_ON_ONCE() rather than BUG_ON. Also, handle the case if a non-large folio is passed and add clarifying comments to the function. Link: https://lore.kernel.org/lkml/[email protected]/T/ Link: https://lkml.kernel.org/r/[email protected] Fixes: 9fd3305 ("mm: add folio dtor and order setter functions") Signed-off-by: Sidhartha Kumar <[email protected]> Suggested-by: Mike Kravetz <[email protected]> Suggested-by: Muchun Song <[email protected]> Suggested-by: Matthew Wilcox <[email protected]> Suggested-by: John Hubbard <[email protected]> Reviewed-by: John Hubbard <[email protected]> Reviewed-by: Muchun Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1301f93 commit 04a42e7

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

include/linux/mm.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,22 +1019,6 @@ static inline void set_compound_order(struct page *page, unsigned int order)
10191019
#endif
10201020
}
10211021

1022-
/*
1023-
* folio_set_compound_order is generally passed a non-zero order to
1024-
* initialize a large folio. However, hugetlb code abuses this by
1025-
* passing in zero when 'dissolving' a large folio.
1026-
*/
1027-
static inline void folio_set_compound_order(struct folio *folio,
1028-
unsigned int order)
1029-
{
1030-
VM_BUG_ON_FOLIO(!folio_test_large(folio), folio);
1031-
1032-
folio->_folio_order = order;
1033-
#ifdef CONFIG_64BIT
1034-
folio->_folio_nr_pages = order ? 1U << order : 0;
1035-
#endif
1036-
}
1037-
10381022
/* Returns the number of pages in this potentially compound page. */
10391023
static inline unsigned long compound_nr(struct page *page)
10401024
{

mm/hugetlb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ static void __destroy_compound_gigantic_folio(struct folio *folio,
14921492
set_page_refcounted(p);
14931493
}
14941494

1495-
folio_set_compound_order(folio, 0);
1495+
folio_set_order(folio, 0);
14961496
__folio_clear_head(folio);
14971497
}
14981498

@@ -1956,7 +1956,7 @@ static bool __prep_compound_gigantic_folio(struct folio *folio,
19561956
__folio_clear_reserved(folio);
19571957
__folio_set_head(folio);
19581958
/* we rely on prep_new_hugetlb_folio to set the destructor */
1959-
folio_set_compound_order(folio, order);
1959+
folio_set_order(folio, order);
19601960
for (i = 0; i < nr_pages; i++) {
19611961
p = folio_page(folio, i);
19621962

@@ -2020,7 +2020,7 @@ static bool __prep_compound_gigantic_folio(struct folio *folio,
20202020
p = folio_page(folio, j);
20212021
__ClearPageReserved(p);
20222022
}
2023-
folio_set_compound_order(folio, 0);
2023+
folio_set_order(folio, 0);
20242024
__folio_clear_head(folio);
20252025
return false;
20262026
}

mm/internal.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,25 @@ extern void *memmap_alloc(phys_addr_t size, phys_addr_t align,
378378
int split_free_page(struct page *free_page,
379379
unsigned int order, unsigned long split_pfn_offset);
380380

381+
/*
382+
* This will have no effect, other than possibly generating a warning, if the
383+
* caller passes in a non-large folio.
384+
*/
385+
static inline void folio_set_order(struct folio *folio, unsigned int order)
386+
{
387+
if (WARN_ON_ONCE(!folio_test_large(folio)))
388+
return;
389+
390+
folio->_folio_order = order;
391+
#ifdef CONFIG_64BIT
392+
/*
393+
* When hugetlb dissolves a folio, we need to clear the tail
394+
* page, rather than setting nr_pages to 1.
395+
*/
396+
folio->_folio_nr_pages = order ? 1U << order : 0;
397+
#endif
398+
}
399+
381400
#if defined CONFIG_COMPACTION || defined CONFIG_CMA
382401

383402
/*

0 commit comments

Comments
 (0)