[PATCH v9 07/11] mm/hugetlb: Flush work when dissolving hugetlb page
From: Muchun Song
Date: Sun Dec 13 2020 - 10:50:33 EST
We should flush work when dissolving a hugetlb page to make sure that
the hugetlb page is freed to the buddy.
Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
---
mm/hugetlb.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 29de425f879a..b0847b2ce01d 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1326,6 +1326,12 @@ static void update_hpage_vmemmap_workfn(struct work_struct *work)
}
static DECLARE_WORK(hpage_update_work, update_hpage_vmemmap_workfn);
+static inline void flush_hpage_update_work(struct hstate *h)
+{
+ if (free_vmemmap_pages_per_hpage(h))
+ flush_work(&hpage_update_work);
+}
+
static inline void __update_and_free_page(struct hstate *h, struct page *page)
{
/* No need to allocate vmemmap pages */
@@ -1861,6 +1867,7 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed,
int dissolve_free_huge_page(struct page *page)
{
int rc = -EBUSY;
+ struct hstate *h = NULL;
/* Not to disrupt normal path by vainly holding hugetlb_lock */
if (!PageHuge(page))
@@ -1874,8 +1881,9 @@ int dissolve_free_huge_page(struct page *page)
if (!page_count(page)) {
struct page *head = compound_head(page);
- struct hstate *h = page_hstate(head);
int nid = page_to_nid(head);
+
+ h = page_hstate(head);
if (h->free_huge_pages - h->resv_huge_pages == 0)
goto out;
@@ -1889,6 +1897,14 @@ int dissolve_free_huge_page(struct page *page)
}
out:
spin_unlock(&hugetlb_lock);
+
+ /*
+ * We should flush work before return to make sure that
+ * the HugeTLB page is freed to the buddy.
+ */
+ if (!rc && h)
+ flush_hpage_update_work(h);
+
return rc;
}
--
2.11.0