Skip to contentSkip to conversation

hugetlb: Fix dynamic pool resize failure case

PATCH In review Adam Litke 2 participants 2 messages Oct 12, 2007

Subsystems (2)
lore
Share & tools
lore

Adam Litke

author
#0 lore raw

PATCH 1/1 hugetlb: Fix dynamic pool resize failure case

Changes since V1
Added a comment explaining the free logic in gather_surplus_pages.

When gather_surplus_pages() fails to allocate enough huge pages to satisfy the requested reservation, it frees what it did allocate back to the buddy allocator. put_page() should be called instead of update_and_free_page() to ensure that pool counters are updated as appropriate and the page's refcount is decremented.

Andrew: This should apply cleanly to my patches in the -mm tree.

---

 mm/hugetlb.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
mm/hugetlb.c +11 -2
index 9b3dfac..ce66c72 100644
@@ -281,8 +281,17 @@ free:
 		list_del(&page->lru);
 		if ((--needed) >= 0)
 			enqueue_huge_page(page);
-		else
-			update_and_free_page(page);
+		else {
+			/*
+			 * Decrement the refcount and free the page using its
+			 * destructor.  This must be done with hugetlb_lock
+			 * unlocked which is safe because free_huge_page takes
+			 * hugetlb_lock before deciding how to free the page.
+			 */
+			spin_unlock(&hugetlb_lock);
+			put_page(page);
+			spin_lock(&hugetlb_lock);
+		}
 	}
 
 	return ret;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Adam Litke

Changes since V1
Added a comment explaining the free logic in gather_surplus_pages.

When gather_surplus_pages() fails to allocate enough huge pages to satisfy the requested reservation, it frees what it did allocate back to the buddy allocator. put_page() should be called instead of update_and_free_page() to ensure that pool counters are updated as appropriate and the page's refcount is decremented.

The comment looks good. It's much more obvious what it's doing now and certainly answers all the questions I asked before.

I do think we need to consider some of the wider implications before the series that this applies on top of goes to mainline, but this patch by itself is just fine with me.

-- Dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>