From 9026e3891790139d1c779f7c6cb00c5c77e5dea1 Mon Sep 17 00:00:00 2001 From: Xiao Guangrong Date: Fri, 21 Sep 2012 10:57:26 +1000 Subject: [PATCH] thp: release page in page pre-alloc path If NUMA is enabled, we can release the page in the page pre-alloc operation, then the CONFIG_NUMA dependent code can be reduced Signed-off-by: Xiao Guangrong Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: David Rientjes Signed-off-by: Andrew Morton --- mm/huge_memory.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 08d70d75ea08..637347dedf12 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1874,15 +1874,12 @@ static void collapse_huge_page(struct mm_struct *mm, *hpage = ERR_PTR(-ENOMEM); return; } + *hpage = new_page; count_vm_event(THP_COLLAPSE_ALLOC); #endif - if (unlikely(mem_cgroup_newpage_charge(new_page, mm, GFP_KERNEL))) { -#ifdef CONFIG_NUMA - put_page(new_page); -#endif + if (unlikely(mem_cgroup_newpage_charge(new_page, mm, GFP_KERNEL))) return; - } /* * Prevent all access to pagetables with the exception of @@ -1983,9 +1980,8 @@ static void collapse_huge_page(struct mm_struct *mm, prepare_pmd_huge_pte(pgtable, mm); spin_unlock(&mm->page_table_lock); -#ifndef CONFIG_NUMA *hpage = NULL; -#endif + khugepaged_pages_collapsed++; out_up_write: up_write(&mm->mmap_sem); @@ -1993,9 +1989,6 @@ out_up_write: out: mem_cgroup_uncharge_page(new_page); -#ifdef CONFIG_NUMA - put_page(new_page); -#endif goto out_up_write; } @@ -2261,8 +2254,6 @@ static void khugepaged_do_scan(void) barrier(); /* write khugepaged_pages_to_scan to local stack */ while (progress < pages) { - cond_resched(); - #ifndef CONFIG_NUMA if (!hpage) hpage = khugepaged_alloc_hugepage(&wait); @@ -2275,8 +2266,12 @@ static void khugepaged_do_scan(void) break; wait = false; khugepaged_alloc_sleep(); + } else if (hpage) { + put_page(hpage); + hpage = NULL; } #endif + cond_resched(); if (unlikely(kthread_should_stop() || freezing(current))) break; -- 2.39.5