[PATCH] [10/18] Factor out new huge page preparation code into separate function

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Andi Kleen
Date: Sunday, March 16, 2008 - 6:58 pm

Needed to avoid code duplication in follow up patches.

This happens to fix a minor bug. When alloc_bootmem_node returns
a fallback node on a different node than passed the old code
would have put it into the free lists of the wrong node.
Now it would end up in the freelist of the correct node.

Signed-off-by: Andi Kleen <ak@suse.de>

---
 mm/hugetlb.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

Index: linux/mm/hugetlb.c
===================================================================
--- linux.orig/mm/hugetlb.c
+++ linux/mm/hugetlb.c
@@ -200,6 +200,17 @@ static int adjust_pool_surplus(struct hs
 	return ret;
 }
 
+static void huge_new_page(struct hstate *h, struct page *page)
+{
+	unsigned nid = pfn_to_nid(page_to_pfn(page));
+	set_compound_page_dtor(page, free_huge_page);
+	spin_lock(&hugetlb_lock);
+	h->nr_huge_pages++;
+	h->nr_huge_pages_node[nid]++;
+	spin_unlock(&hugetlb_lock);
+	put_page(page); /* free it into the hugepage allocator */
+}
+
 static struct page *alloc_fresh_huge_page_node(struct hstate *h, int nid)
 {
 	struct page *page;
@@ -207,14 +218,8 @@ static struct page *alloc_fresh_huge_pag
 	page = alloc_pages_node(nid,
 		htlb_alloc_mask|__GFP_COMP|__GFP_THISNODE|__GFP_NOWARN,
 			huge_page_order(h));
-	if (page) {
-		set_compound_page_dtor(page, free_huge_page);
-		spin_lock(&hugetlb_lock);
-		h->nr_huge_pages++;
-		h->nr_huge_pages_node[nid]++;
-		spin_unlock(&hugetlb_lock);
-		put_page(page); /* free it into the hugepage allocator */
-	}
+	if (page)
+		huge_new_page(h, page);
 
 	return page;
 }
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] [0/18] GB pages hugetlb support, Andi Kleen, (Sun Mar 16, 6:58 pm)
[PATCH] [8/18] Add a __alloc_bootmem_node_nopanic, Andi Kleen, (Sun Mar 16, 6:58 pm)
[PATCH] [10/18] Factor out new huge page preparation code ..., Andi Kleen, (Sun Mar 16, 6:58 pm)
[PATCH] [14/18] Clean up hugetlb boot time printk, Andi Kleen, (Sun Mar 16, 6:58 pm)
[PATCH] [16/18] Add huge pud support to hugetlbfs, Andi Kleen, (Sun Mar 16, 6:58 pm)
[PATCH] [17/18] Add huge pud support to mm/memory.c, Andi Kleen, (Sun Mar 16, 6:58 pm)
Re: [PATCH] [0/18] GB pages hugetlb support, Paul Jackson, (Sun Mar 16, 8:11 pm)
Re: [PATCH] [0/18] GB pages hugetlb support, Paul Jackson, (Sun Mar 16, 10:35 pm)
Re: [PATCH] [0/18] GB pages hugetlb support, Andi Kleen, (Sun Mar 16, 11:58 pm)
Re: [PATCH] [0/18] GB pages hugetlb support, Paul Jackson, (Mon Mar 17, 12:00 am)
Re: [PATCH] [0/18] GB pages hugetlb support, Andi Kleen, (Mon Mar 17, 12:00 am)
Re: [PATCH] [0/18] GB pages hugetlb support, Andi Kleen, (Mon Mar 17, 12:29 am)
Re: [PATCH] [0/18] GB pages hugetlb support, Paul Jackson, (Mon Mar 17, 2:26 am)
Re: [PATCH] [0/18] GB pages hugetlb support, Adam Litke, (Mon Mar 17, 8:05 am)
Re: [PATCH] [0/18] GB pages hugetlb support, Andi Kleen, (Mon Mar 17, 8:33 am)
Re: [PATCH] [0/18] GB pages hugetlb support, Adam Litke, (Mon Mar 17, 8:59 am)