Commit 420256ef02660af0acf28c12fe4b7d514ca88a4d

Authored by Xiao Guangrong
Committed by Linus Torvalds
1 parent d516904bd2

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 <xiaoguangrong@linux.vnet.ibm.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 7 additions and 12 deletions Side-by-side Diff

... ... @@ -1873,15 +1873,12 @@
1873 1873 *hpage = ERR_PTR(-ENOMEM);
1874 1874 return;
1875 1875 }
  1876 + *hpage = new_page;
1876 1877 count_vm_event(THP_COLLAPSE_ALLOC);
1877 1878 #endif
1878 1879  
1879   - if (unlikely(mem_cgroup_newpage_charge(new_page, mm, GFP_KERNEL))) {
1880   -#ifdef CONFIG_NUMA
1881   - put_page(new_page);
1882   -#endif
  1880 + if (unlikely(mem_cgroup_newpage_charge(new_page, mm, GFP_KERNEL)))
1883 1881 return;
1884   - }
1885 1882  
1886 1883 /*
1887 1884 * Prevent all access to pagetables with the exception of
1888 1885  
... ... @@ -1982,9 +1979,8 @@
1982 1979 prepare_pmd_huge_pte(pgtable, mm);
1983 1980 spin_unlock(&mm->page_table_lock);
1984 1981  
1985   -#ifndef CONFIG_NUMA
1986 1982 *hpage = NULL;
1987   -#endif
  1983 +
1988 1984 khugepaged_pages_collapsed++;
1989 1985 out_up_write:
1990 1986 up_write(&mm->mmap_sem);
... ... @@ -1992,9 +1988,6 @@
1992 1988  
1993 1989 out:
1994 1990 mem_cgroup_uncharge_page(new_page);
1995   -#ifdef CONFIG_NUMA
1996   - put_page(new_page);
1997   -#endif
1998 1991 goto out_up_write;
1999 1992 }
2000 1993  
... ... @@ -2260,8 +2253,6 @@
2260 2253 barrier(); /* write khugepaged_pages_to_scan to local stack */
2261 2254  
2262 2255 while (progress < pages) {
2263   - cond_resched();
2264   -
2265 2256 #ifndef CONFIG_NUMA
2266 2257 if (!hpage)
2267 2258 hpage = khugepaged_alloc_hugepage(&wait);
2268 2259  
... ... @@ -2274,8 +2265,12 @@
2274 2265 break;
2275 2266 wait = false;
2276 2267 khugepaged_alloc_sleep();
  2268 + } else if (hpage) {
  2269 + put_page(hpage);
  2270 + hpage = NULL;
2277 2271 }
2278 2272 #endif
  2273 + cond_resched();
2279 2274  
2280 2275 if (unlikely(kthread_should_stop() || freezing(current)))
2281 2276 break;