Subject: mm: page allocator: Drain per-cpu lists after direct reclaim allocation fails From: Mel Gorman When under significant memory pressure, a process enters direct reclaim and immediately afterwards tries to allocate a page. If it fails and no further progress is made, it's possible the system will go OOM. However, one systems with large amounts of memory, it's possible that a significant number of pages are on per-cpu lists and inaccessible to the calling process. This leads to a process entering direct reclaim more often than it should increasing the pressure on the system and compounding the problem. This patch notes that if direct reclaim is making progress but allocatioons are still failing that the system is already under heavy pressure. In this case, it drains the per-cpu lists and tries the allocation a second time before continuing. Signed-off-by: Mel Gorman Signed-off-by: Andrea Arcangeli --- diff --git a/mm/page_alloc.c b/mm/page_alloc.c --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1842,6 +1842,7 @@ __alloc_pages_direct_reclaim(gfp_t gfp_m struct page *page = NULL; struct reclaim_state reclaim_state; struct task_struct *p = current; + bool drained = false; cond_resched(); @@ -1863,11 +1864,25 @@ __alloc_pages_direct_reclaim(gfp_t gfp_m if (order != 0) drain_all_pages(); - if (likely(*did_some_progress)) - page = get_page_from_freelist(gfp_mask, nodemask, order, + if (unlikely(!(*did_some_progress))) + return NULL; + +retry: + page = get_page_from_freelist(gfp_mask, nodemask, order, zonelist, high_zoneidx, alloc_flags, preferred_zone, migratetype); + + /* + * If an allocation failed after direct reclaim, it could be because + * pages are pinned on the per-cpu lists. Drain them and try again + */ + if (!page && !drained) { + drain_all_pages(); + drained = true; + goto retry; + } + return page; }