* [PATCH v2 0/3] Small hugetlb cleanups
@ 2023-08-24 14:13 Matthew Wilcox (Oracle)
2023-08-24 14:13 ` [PATCH v2 1/3] hugetlb: Use a folio in free_hpage_workfn() Matthew Wilcox (Oracle)
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-08-24 14:13 UTC (permalink / raw)
To: Mike Kravetz; +Cc: Matthew Wilcox (Oracle), Muchun Song, linux-mm
Some trivial folio conveersions
v2:
- collect R-b tags
- Rename remove_pool_huge_page to remove_pool_hugetlb_folio
- Fix uninitialised pointer usage reported by lkp@intel.com
Matthew Wilcox (Oracle) (3):
hugetlb: Use a folio in free_hpage_workfn()
hugetlb: Remove a few calls to page_folio()
hugetlb: Convert remove_pool_huge_page() to
remove_pool_hugetlb_folio()
mm/hugetlb.c | 65 +++++++++++++++++++++++++---------------------------
1 file changed, 31 insertions(+), 34 deletions(-)
--
2.40.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] hugetlb: Use a folio in free_hpage_workfn()
2023-08-24 14:13 [PATCH v2 0/3] Small hugetlb cleanups Matthew Wilcox (Oracle)
@ 2023-08-24 14:13 ` Matthew Wilcox (Oracle)
2023-08-24 14:13 ` [PATCH v2 2/3] hugetlb: Remove a few calls to page_folio() Matthew Wilcox (Oracle)
2023-08-24 14:13 ` [PATCH v2 3/3] hugetlb: Convert remove_pool_huge_page() to remove_pool_hugetlb_folio() Matthew Wilcox (Oracle)
2 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-08-24 14:13 UTC (permalink / raw)
To: Mike Kravetz
Cc: Matthew Wilcox (Oracle),
Muchun Song, linux-mm, Muchun Song, Sidhartha Kumar
update_and_free_hugetlb_folio puts the memory on hpage_freelist as a folio
so we can take it off the list as a folio.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
mm/hugetlb.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index a82c3104337e..d1c856628bac 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1786,22 +1786,22 @@ static void free_hpage_workfn(struct work_struct *work)
node = llist_del_all(&hpage_freelist);
while (node) {
- struct page *page;
+ struct folio *folio;
struct hstate *h;
- page = container_of((struct address_space **)node,
- struct page, mapping);
+ folio = container_of((struct address_space **)node,
+ struct folio, mapping);
node = node->next;
- page->mapping = NULL;
+ folio->mapping = NULL;
/*
* The VM_BUG_ON_FOLIO(!folio_test_hugetlb(folio), folio) in
* folio_hstate() is going to trigger because a previous call to
* remove_hugetlb_folio() will clear the hugetlb bit, so do
* not use folio_hstate() directly.
*/
- h = size_to_hstate(page_size(page));
+ h = size_to_hstate(folio_size(folio));
- __update_and_free_hugetlb_folio(h, page_folio(page));
+ __update_and_free_hugetlb_folio(h, folio);
cond_resched();
}
--
2.40.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] hugetlb: Remove a few calls to page_folio()
2023-08-24 14:13 [PATCH v2 0/3] Small hugetlb cleanups Matthew Wilcox (Oracle)
2023-08-24 14:13 ` [PATCH v2 1/3] hugetlb: Use a folio in free_hpage_workfn() Matthew Wilcox (Oracle)
@ 2023-08-24 14:13 ` Matthew Wilcox (Oracle)
2023-08-24 14:13 ` [PATCH v2 3/3] hugetlb: Convert remove_pool_huge_page() to remove_pool_hugetlb_folio() Matthew Wilcox (Oracle)
2 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-08-24 14:13 UTC (permalink / raw)
To: Mike Kravetz
Cc: Matthew Wilcox (Oracle),
Muchun Song, linux-mm, Muchun Song, Sidhartha Kumar
Anything found on a linked list threaded through ->lru is guaranteed to
be a folio as the compound_head found in a tail page overlaps the ->lru
member of struct page. So we can pull folios directly off these lists
no matter whether pages or folios were added to the list.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
mm/hugetlb.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index d1c856628bac..8f548a274e3c 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1835,11 +1835,9 @@ static void update_and_free_hugetlb_folio(struct hstate *h, struct folio *folio,
static void update_and_free_pages_bulk(struct hstate *h, struct list_head *list)
{
- struct page *page, *t_page;
- struct folio *folio;
+ struct folio *folio, *t_folio;
- list_for_each_entry_safe(page, t_page, list, lru) {
- folio = page_folio(page);
+ list_for_each_entry_safe(folio, t_folio, list, lru) {
update_and_free_hugetlb_folio(h, folio, false);
cond_resched();
}
@@ -2228,8 +2226,7 @@ static struct page *remove_pool_huge_page(struct hstate *h,
bool acct_surplus)
{
int nr_nodes, node;
- struct page *page = NULL;
- struct folio *folio;
+ struct folio *folio = NULL;
lockdep_assert_held(&hugetlb_lock);
for_each_node_mask_to_free(h, nr_nodes, node, nodes_allowed) {
@@ -2239,15 +2236,14 @@ static struct page *remove_pool_huge_page(struct hstate *h,
*/
if ((!acct_surplus || h->surplus_huge_pages_node[node]) &&
!list_empty(&h->hugepage_freelists[node])) {
- page = list_entry(h->hugepage_freelists[node].next,
- struct page, lru);
- folio = page_folio(page);
+ folio = list_entry(h->hugepage_freelists[node].next,
+ struct folio, lru);
remove_hugetlb_folio(h, folio, acct_surplus);
break;
}
}
- return page;
+ return &folio->page;
}
/*
@@ -3363,15 +3359,15 @@ static void try_to_free_low(struct hstate *h, unsigned long count,
* Collect pages to be freed on a list, and free after dropping lock
*/
for_each_node_mask(i, *nodes_allowed) {
- struct page *page, *next;
+ struct folio *folio, *next;
struct list_head *freel = &h->hugepage_freelists[i];
- list_for_each_entry_safe(page, next, freel, lru) {
+ list_for_each_entry_safe(folio, next, freel, lru) {
if (count >= h->nr_huge_pages)
goto out;
- if (PageHighMem(page))
+ if (folio_test_highmem(folio))
continue;
- remove_hugetlb_folio(h, page_folio(page), false);
- list_add(&page->lru, &page_list);
+ remove_hugetlb_folio(h, folio, false);
+ list_add(&folio->lru, &page_list);
}
}
--
2.40.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] hugetlb: Convert remove_pool_huge_page() to remove_pool_hugetlb_folio()
2023-08-24 14:13 [PATCH v2 0/3] Small hugetlb cleanups Matthew Wilcox (Oracle)
2023-08-24 14:13 ` [PATCH v2 1/3] hugetlb: Use a folio in free_hpage_workfn() Matthew Wilcox (Oracle)
2023-08-24 14:13 ` [PATCH v2 2/3] hugetlb: Remove a few calls to page_folio() Matthew Wilcox (Oracle)
@ 2023-08-24 14:13 ` Matthew Wilcox (Oracle)
2023-08-25 3:04 ` Muchun Song
2 siblings, 1 reply; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-08-24 14:13 UTC (permalink / raw)
To: Mike Kravetz
Cc: Matthew Wilcox (Oracle), Muchun Song, linux-mm, Sidhartha Kumar
Convert the callers to expect a folio and remove the unnecesary conversion
back to a struct page.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
mm/hugetlb.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 8f548a274e3c..35dcc7f9b52a 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1441,7 +1441,7 @@ static int hstate_next_node_to_alloc(struct hstate *h,
}
/*
- * helper for remove_pool_huge_page() - return the previously saved
+ * helper for remove_pool_hugetlb_folio() - return the previously saved
* node ["this node"] from which to free a huge page. Advance the
* next node id whether or not we find a free huge page to free so
* that the next attempt to free addresses the next node.
@@ -2221,9 +2221,8 @@ static int alloc_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed,
* an additional call to free the page to low level allocators.
* Called with hugetlb_lock locked.
*/
-static struct page *remove_pool_huge_page(struct hstate *h,
- nodemask_t *nodes_allowed,
- bool acct_surplus)
+static struct folio *remove_pool_hugetlb_folio(struct hstate *h,
+ nodemask_t *nodes_allowed, bool acct_surplus)
{
int nr_nodes, node;
struct folio *folio = NULL;
@@ -2243,7 +2242,7 @@ static struct page *remove_pool_huge_page(struct hstate *h,
}
}
- return &folio->page;
+ return folio;
}
/*
@@ -2597,7 +2596,6 @@ static void return_unused_surplus_pages(struct hstate *h,
unsigned long unused_resv_pages)
{
unsigned long nr_pages;
- struct page *page;
LIST_HEAD(page_list);
lockdep_assert_held(&hugetlb_lock);
@@ -2618,15 +2616,17 @@ static void return_unused_surplus_pages(struct hstate *h,
* evenly across all nodes with memory. Iterate across these nodes
* until we can no longer free unreserved surplus pages. This occurs
* when the nodes with surplus pages have no free pages.
- * remove_pool_huge_page() will balance the freed pages across the
+ * remove_pool_hugetlb_folio() will balance the freed pages across the
* on-line nodes with memory and will handle the hstate accounting.
*/
while (nr_pages--) {
- page = remove_pool_huge_page(h, &node_states[N_MEMORY], 1);
- if (!page)
+ struct folio *folio;
+
+ folio = remove_pool_hugetlb_folio(h, &node_states[N_MEMORY], 1);
+ if (!folio)
goto out;
- list_add(&page->lru, &page_list);
+ list_add(&folio->lru, &page_list);
}
out:
@@ -3421,7 +3421,6 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
nodemask_t *nodes_allowed)
{
unsigned long min_count, ret;
- struct page *page;
LIST_HEAD(page_list);
NODEMASK_ALLOC(nodemask_t, node_alloc_noretry, GFP_KERNEL);
@@ -3541,11 +3540,13 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
* Collect pages to be removed on list without dropping lock
*/
while (min_count < persistent_huge_pages(h)) {
- page = remove_pool_huge_page(h, nodes_allowed, 0);
- if (!page)
+ struct folio *folio;
+
+ folio = remove_pool_hugetlb_folio(h, nodes_allowed, 0);
+ if (!folio)
break;
- list_add(&page->lru, &page_list);
+ list_add(&folio->lru, &page_list);
}
/* free the pages after dropping lock */
spin_unlock_irq(&hugetlb_lock);
--
2.40.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 3/3] hugetlb: Convert remove_pool_huge_page() to remove_pool_hugetlb_folio()
2023-08-24 14:13 ` [PATCH v2 3/3] hugetlb: Convert remove_pool_huge_page() to remove_pool_hugetlb_folio() Matthew Wilcox (Oracle)
@ 2023-08-25 3:04 ` Muchun Song
0 siblings, 0 replies; 5+ messages in thread
From: Muchun Song @ 2023-08-25 3:04 UTC (permalink / raw)
To: Matthew Wilcox (Oracle); +Cc: Mike Kravetz, Linux-MM, Sidhartha Kumar
> On Aug 24, 2023, at 22:13, Matthew Wilcox (Oracle) <willy@infradead.org> wrote:
>
> Convert the callers to expect a folio and remove the unnecesary conversion
> back to a struct page.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
> Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-08-25 3:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-24 14:13 [PATCH v2 0/3] Small hugetlb cleanups Matthew Wilcox (Oracle)
2023-08-24 14:13 ` [PATCH v2 1/3] hugetlb: Use a folio in free_hpage_workfn() Matthew Wilcox (Oracle)
2023-08-24 14:13 ` [PATCH v2 2/3] hugetlb: Remove a few calls to page_folio() Matthew Wilcox (Oracle)
2023-08-24 14:13 ` [PATCH v2 3/3] hugetlb: Convert remove_pool_huge_page() to remove_pool_hugetlb_folio() Matthew Wilcox (Oracle)
2023-08-25 3:04 ` Muchun Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox