Skip to content

Commit ff0ceb9

Browse files
rientjesLinus Torvalds
authored andcommitted
oom: serialize out of memory calls
A final allocation attempt with a very high watermark needs to be attempted before invoking out_of_memory(). OOM killer serialization needs to occur before this final attempt, otherwise tasks attempting to OOM-lock all zones in its zonelist may spin and acquire the lock unnecessarily after the OOM condition has already been alleviated. If the final allocation does succeed, the zonelist is simply OOM-unlocked and __alloc_pages() returns the page. Otherwise, the OOM killer is invoked. If the task cannot acquire OOM-locks on all zones in its zonelist, it is put to sleep and the allocation is retried when it gets rescheduled. One of its zones is already marked as being in the OOM killer so it'll hopefully be getting some free memory soon, at least enough to satisfy a high watermark allocation attempt. This prevents needlessly killing a task when the OOM condition would have already been alleviated if it had simply been given enough time. Cc: Andrea Arcangeli <andrea@suse.de> Acked-by: Christoph Lameter <clameter@sgi.com> Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 098d7f1 commit ff0ceb9

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎mm/page_alloc.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,11 @@ __alloc_pages(gfp_t gfp_mask, unsigned int order,
15871587
if (page)
15881588
goto got_pg;
15891589
} else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) {
1590+
if (!try_set_zone_oom(zonelist)) {
1591+
schedule_timeout_uninterruptible(1);
1592+
goto restart;
1593+
}
1594+
15901595
/*
15911596
* Go through the zonelist yet one more time, keep
15921597
* very high watermark here, this is only to catch
@@ -1595,14 +1600,19 @@ __alloc_pages(gfp_t gfp_mask, unsigned int order,
15951600
*/
15961601
page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, order,
15971602
zonelist, ALLOC_WMARK_HIGH|ALLOC_CPUSET);
1598-
if (page)
1603+
if (page) {
1604+
clear_zonelist_oom(zonelist);
15991605
goto got_pg;
1606+
}
16001607

16011608
/* The OOM killer will not help higher order allocs so fail */
1602-
if (order > PAGE_ALLOC_COSTLY_ORDER)
1609+
if (order > PAGE_ALLOC_COSTLY_ORDER) {
1610+
clear_zonelist_oom(zonelist);
16031611
goto nopage;
1612+
}
16041613

16051614
out_of_memory(zonelist, gfp_mask, order);
1615+
clear_zonelist_oom(zonelist);
16061616
goto restart;
16071617
}
16081618

0 commit comments

Comments
 (0)