Skip to content

Commit 9fd3305

Browse files
sidkumar99akpm00
authored andcommitted
mm: add folio dtor and order setter functions
Patch series "convert core hugetlb functions to folios", v5. ============== OVERVIEW =========================== Now that many hugetlb helper functions that deal with hugetlb specific flags[1] and hugetlb cgroups[2] are converted to folios, higher level allocation, prep, and freeing functions within hugetlb can also be converted to operate in folios. Patch 1 of this series implements the wrapper functions around setting the compound destructor and compound order for a folio. Besides the user added in patch 1, patch 2 and patch 9 also use these helper functions. Patches 2-10 convert the higher level hugetlb functions to folios. ============== TESTING =========================== LTP: Ran 10 back to back rounds of the LTP hugetlb test suite. Gigantic Huge Pages: Test allocation and freeing via hugeadm commands: hugeadm --pool-pages-min 1GB:10 hugeadm --pool-pages-min 1GB:0 Demote: Demote 1 1GB hugepages to 512 2MB hugepages echo 1 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages echo 1 > /sys/kernel/mm/hugepages/hugepages-1048576kB/demote cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages # 512 cat /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages # 0 [1] https://lore.kernel.org/lkml/[email protected]/ [2] https://lore.kernel.org/linux-mm/[email protected]/ This patch (of 10): Add folio equivalents for set_compound_order() and set_compound_page_dtor(). Also remove extra new-lines introduced by mm/hugetlb: convert move_hugetlb_state() to folios and mm/hugetlb_cgroup: convert hugetlb_cgroup_uncharge_page() to folios. [[email protected]: clarify folio_set_compound_order() zero support] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sidhartha Kumar <[email protected]> Suggested-by: Mike Kravetz <[email protected]> Suggested-by: Muchun Song <[email protected]> Reviewed-by: Mike Kravetz <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: John Hubbard <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Miaohe Lin <[email protected]> Cc: Mina Almasry <[email protected]> Cc: Tarun Sahu <[email protected]> Cc: Rasmus Villemoes <[email protected]> Cc: Wei Chen <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 6e1ca48 commit 9fd3305

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

include/linux/mm.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,13 @@ static inline void set_compound_page_dtor(struct page *page,
997997
page[1].compound_dtor = compound_dtor;
998998
}
999999

1000+
static inline void folio_set_compound_dtor(struct folio *folio,
1001+
enum compound_dtor_id compound_dtor)
1002+
{
1003+
VM_BUG_ON_FOLIO(compound_dtor >= NR_COMPOUND_DTORS, folio);
1004+
folio->_folio_dtor = compound_dtor;
1005+
}
1006+
10001007
void destroy_large_folio(struct folio *folio);
10011008

10021009
static inline int head_compound_pincount(struct page *head)
@@ -1012,6 +1019,22 @@ static inline void set_compound_order(struct page *page, unsigned int order)
10121019
#endif
10131020
}
10141021

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+
10151038
/* Returns the number of pages in this potentially compound page. */
10161039
static inline unsigned long compound_nr(struct page *page)
10171040
{

mm/hugetlb.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ static void __prep_new_hugetlb_folio(struct hstate *h, struct folio *folio)
17801780
{
17811781
hugetlb_vmemmap_optimize(h, &folio->page);
17821782
INIT_LIST_HEAD(&folio->lru);
1783-
folio->_folio_dtor = HUGETLB_PAGE_DTOR;
1783+
folio_set_compound_dtor(folio, HUGETLB_PAGE_DTOR);
17841784
hugetlb_set_folio_subpool(folio, NULL);
17851785
set_hugetlb_cgroup(folio, NULL);
17861786
set_hugetlb_cgroup_rsvd(folio, NULL);
@@ -2938,7 +2938,6 @@ struct page *alloc_huge_page(struct vm_area_struct *vma,
29382938
* a reservation exists for the allocation.
29392939
*/
29402940
page = dequeue_huge_page_vma(h, vma, addr, avoid_reserve, gbl_chg);
2941-
29422941
if (!page) {
29432942
spin_unlock_irq(&hugetlb_lock);
29442943
page = alloc_buddy_huge_page_with_mpol(h, vma, addr);
@@ -7343,7 +7342,6 @@ void move_hugetlb_state(struct folio *old_folio, struct folio *new_folio, int re
73437342
int old_nid = folio_nid(old_folio);
73447343
int new_nid = folio_nid(new_folio);
73457344

7346-
73477345
folio_set_hugetlb_temporary(old_folio);
73487346
folio_clear_hugetlb_temporary(new_folio);
73497347

0 commit comments

Comments
 (0)