Skip to content

Commit 6b4e318

Browse files
Michal Hockotorvalds
authored andcommitted
mm, oom: prevent premature OOM killer invocation for high order request
There have been several reports about pre-mature OOM killer invocation in 4.7 kernel when order-2 allocation request (for the kernel stack) invoked OOM killer even during basic workloads (light IO or even kernel compile on some filesystems). In all reported cases the memory is fragmented and there are no order-2+ pages available. There is usually a large amount of slab memory (usually dentries/inodes) and further debugging has shown that there are way too many unmovable blocks which are skipped during the compaction. Multiple reporters have confirmed that the current linux-next which includes [1] and [2] helped and OOMs are not reproducible anymore. A simpler fix for the late rc and stable is to simply ignore the compaction feedback and retry as long as there is a reclaim progress and we are not getting OOM for order-0 pages. We already do that for CONFING_COMPACTION=n so let's reuse the same code when compaction is enabled as well. [1] http://lkml.kernel.org/r/[email protected] [2] http://lkml.kernel.org/r/[email protected] Fixes: 0a0337e ("mm, oom: rework oom detection") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Michal Hocko <[email protected]> Tested-by: Olaf Hering <[email protected]> Tested-by: Ralf-Peter Rohbeck <[email protected]> Cc: Markus Trippelsdorf <[email protected]> Cc: Arkadiusz Miskiewicz <[email protected]> Cc: Ralf-Peter Rohbeck <[email protected]> Cc: Jiri Slaby <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Tetsuo Handa <[email protected]> Cc: David Rientjes <[email protected]> Cc: <[email protected]> [4.7.x] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 071e31e commit 6b4e318

File tree

1 file changed

+2
-49
lines changed

1 file changed

+2
-49
lines changed

mm/page_alloc.c

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,54 +3137,6 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
31373137
return NULL;
31383138
}
31393139

3140-
static inline bool
3141-
should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
3142-
enum compact_result compact_result,
3143-
enum compact_priority *compact_priority,
3144-
int compaction_retries)
3145-
{
3146-
int max_retries = MAX_COMPACT_RETRIES;
3147-
3148-
if (!order)
3149-
return false;
3150-
3151-
/*
3152-
* compaction considers all the zone as desperately out of memory
3153-
* so it doesn't really make much sense to retry except when the
3154-
* failure could be caused by insufficient priority
3155-
*/
3156-
if (compaction_failed(compact_result)) {
3157-
if (*compact_priority > MIN_COMPACT_PRIORITY) {
3158-
(*compact_priority)--;
3159-
return true;
3160-
}
3161-
return false;
3162-
}
3163-
3164-
/*
3165-
* make sure the compaction wasn't deferred or didn't bail out early
3166-
* due to locks contention before we declare that we should give up.
3167-
* But do not retry if the given zonelist is not suitable for
3168-
* compaction.
3169-
*/
3170-
if (compaction_withdrawn(compact_result))
3171-
return compaction_zonelist_suitable(ac, order, alloc_flags);
3172-
3173-
/*
3174-
* !costly requests are much more important than __GFP_REPEAT
3175-
* costly ones because they are de facto nofail and invoke OOM
3176-
* killer to move on while costly can fail and users are ready
3177-
* to cope with that. 1/4 retries is rather arbitrary but we
3178-
* would need much more detailed feedback from compaction to
3179-
* make a better decision.
3180-
*/
3181-
if (order > PAGE_ALLOC_COSTLY_ORDER)
3182-
max_retries /= 4;
3183-
if (compaction_retries <= max_retries)
3184-
return true;
3185-
3186-
return false;
3187-
}
31883140
#else
31893141
static inline struct page *
31903142
__alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
@@ -3195,6 +3147,8 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
31953147
return NULL;
31963148
}
31973149

3150+
#endif /* CONFIG_COMPACTION */
3151+
31983152
static inline bool
31993153
should_compact_retry(struct alloc_context *ac, unsigned int order, int alloc_flags,
32003154
enum compact_result compact_result,
@@ -3221,7 +3175,6 @@ should_compact_retry(struct alloc_context *ac, unsigned int order, int alloc_fla
32213175
}
32223176
return false;
32233177
}
3224-
#endif /* CONFIG_COMPACTION */
32253178

32263179
/* Perform direct synchronous page reclaim */
32273180
static int

0 commit comments

Comments
 (0)