Skip to contentSkip to conversation

reintroduce compaction feedback for OOM decisions

PATCH Applied Vlastimil Babka 4 participants 24 messages Sep 6, 2016 – Sep 23, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover reintroduce compaction feedback for OOM decisions

After several people reported OOM's for order-2 allocations in 4.7 due to Michal Hocko's OOM rework, he reverted the part that considered compaction feedback [1] in the decisions to retry reclaim/compaction. This was to provide a fix quickly for 4.8 rc and 4.7 stable series, while mmotm had an almost complete solution that instead improved compaction reliability.

This series completes the mmotm solution and reintroduces the compaction feedback into OOM decisions. The first two patches restore the state of mmotm before the temporary solution was merged, the last patch should be the missing piece for reliability. The third patch restricts the hardened compaction to non-costly orders, since costly orders don't result in OOMs in the first place.

Some preliminary testing suggested that this approach should work, but I would like to ask all who experienced the regression to please retest this. You will need to apply this series on top of tag mmotm-2016-08-31-16-06 from the mmotm git tree [2]. Thanks in advance!

[1] http://marc.info/?i=20160822093249.GA14916%40dhcp22.suse.cz%3E
[2] git://git.kernel.org/pub/scm/linux/kernel/git/mhocko/mm.git

Vlastimil Babka (4):
Revert "mm, oom: prevent premature OOM killer invocation for high
order request"
mm, compaction: more reliably increase direct compaction priority mm, compaction: restrict full priority to non-costly orders mm, compaction: make full priority ignore pageblock suitability

 include/linux/compaction.h |  1 +
 mm/compaction.c            | 11 ++++++---
 mm/internal.h              |  1 +
 mm/page_alloc.c            | 58 ++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 66 insertions(+), 5 deletions(-)
Signature · 7 lines
2.9.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 1/4 Revert "mm, oom: prevent premature OOM killer invocation for high order request"

Commit 6b4e3181d7bd ("mm, oom: prevent premature OOM killer invocation for high order request") was intended as a quick fix of OOM regressions for 4.8 and stable 4.7.x kernels. For a better long-term solution, we still want to consider compaction feedback, which should be possible after some more improvements in the following patches.

This reverts commit 6b4e3181d7bd5ca5ab6f45929e4a5ffa7ab4ab7f.

Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc David Rientjes <[email protected]>
Cc Rik van Riel <[email protected]>
---
 mm/page_alloc.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)
mm/page_alloc.c +49 -2
index ee3997859f14..1df7694f4ec7 100644
@@ -3158,6 +3158,54 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
 	return NULL;
 }
 
+static inline bool
+should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
+		     enum compact_result compact_result,
+		     enum compact_priority *compact_priority,
+		     int compaction_retries)
+{
+	int max_retries = MAX_COMPACT_RETRIES;
+
+	if (!order)
+		return false;
+
+	/*
+	 * compaction considers all the zone as desperately out of memory
+	 * so it doesn't really make much sense to retry except when the
+	 * failure could be caused by insufficient priority
+	 */
+	if (compaction_failed(compact_result)) {
+		if (*compact_priority > MIN_COMPACT_PRIORITY) {
+			(*compact_priority)--;
+			return true;
+		}
+		return false;
+	}
+
+	/*
+	 * make sure the compaction wasn't deferred or didn't bail out early
+	 * due to locks contention before we declare that we should give up.
+	 * But do not retry if the given zonelist is not suitable for
+	 * compaction.
+	 */
+	if (compaction_withdrawn(compact_result))
+		return compaction_zonelist_suitable(ac, order, alloc_flags);
+
+	/*
+	 * !costly requests are much more important than __GFP_REPEAT
+	 * costly ones because they are de facto nofail and invoke OOM
+	 * killer to move on while costly can fail and users are ready
+	 * to cope with that. 1/4 retries is rather arbitrary but we
+	 * would need much more detailed feedback from compaction to
+	 * make a better decision.
+	 */
+	if (order > PAGE_ALLOC_COSTLY_ORDER)
+		max_retries /= 4;
+	if (compaction_retries <= max_retries)
+		return true;
+
+	return false;
+}
 #else
 static inline struct page *
 __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
@@ -3168,8 +3216,6 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
 	return NULL;
 }
 
-#endif /* CONFIG_COMPACTION */
-
 static inline bool
 should_compact_retry(struct alloc_context *ac, unsigned int order, int alloc_flags,
 		     enum compact_result compact_result,
@@ -3196,6 +3242,7 @@ should_compact_retry(struct alloc_context *ac, unsigned int order, int alloc_fla
 	}
 	return false;
 }
+#endif /* CONFIG_COMPACTION */
 
 /* Perform direct synchronous page reclaim */
 static int
Signature · 7 lines
2.9.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] Revert "mm, oom: prevent premature OOM killer invocation for high order request"

Quoted 6 lines · Vlastimil Babka

Commit 6b4e3181d7bd ("mm, oom: prevent premature OOM killer invocation for high order request") was intended as a quick fix of OOM regressions for 4.8 and stable 4.7.x kernels. For a better long-term solution, we still want to consider compaction feedback, which should be possible after some more improvements in the following patches.

Quoted 8 lines

This reverts commit 6b4e3181d7bd5ca5ab6f45929e4a5ffa7ab4ab7f.

Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc David Rientjes <[email protected]>
Cc Rik van Riel <[email protected]>
Quoted 82 lines
---
 mm/page_alloc.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)
mm/page_alloc.c +49 -2
index ee3997859f14..1df7694f4ec7 100644
@@ -3158,6 +3158,54 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
 	return NULL;
 }
 
+static inline bool
+should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
+		     enum compact_result compact_result,
+		     enum compact_priority *compact_priority,
+		     int compaction_retries)
+{
+	int max_retries = MAX_COMPACT_RETRIES;
+
+	if (!order)
+		return false;
+
+	/*
+	 * compaction considers all the zone as desperately out of memory
+	 * so it doesn't really make much sense to retry except when the
+	 * failure could be caused by insufficient priority
+	 */
+	if (compaction_failed(compact_result)) {
+		if (*compact_priority > MIN_COMPACT_PRIORITY) {
+			(*compact_priority)--;
+			return true;
+		}
+		return false;
+	}
+
+	/*
+	 * make sure the compaction wasn't deferred or didn't bail out early
+	 * due to locks contention before we declare that we should give up.
+	 * But do not retry if the given zonelist is not suitable for
+	 * compaction.
+	 */
+	if (compaction_withdrawn(compact_result))
+		return compaction_zonelist_suitable(ac, order, alloc_flags);
+
+	/*
+	 * !costly requests are much more important than __GFP_REPEAT
+	 * costly ones because they are de facto nofail and invoke OOM
+	 * killer to move on while costly can fail and users are ready
+	 * to cope with that. 1/4 retries is rather arbitrary but we
+	 * would need much more detailed feedback from compaction to
+	 * make a better decision.
+	 */
+	if (order > PAGE_ALLOC_COSTLY_ORDER)
+		max_retries /= 4;
+	if (compaction_retries <= max_retries)
+		return true;
+
+	return false;
+}
 #else
 static inline struct page *
 __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
@@ -3168,8 +3216,6 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
 	return NULL;
 }
 
-#endif /* CONFIG_COMPACTION */
-
 static inline bool
 should_compact_retry(struct alloc_context *ac, unsigned int order, int alloc_flags,
 		     enum compact_result compact_result,
@@ -3196,6 +3242,7 @@ should_compact_retry(struct alloc_context *ac, unsigned int order, int alloc_fla
 	}
 	return false;
 }
+#endif /* CONFIG_COMPACTION */
 
 /* Perform direct synchronous page reclaim */
 static int
Signature · 1 line
2.9.3
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

PATCH 2/4 mm, compaction: more reliably increase direct compaction priority

In reply to Vlastimil Babka

During reclaim/compaction loop, compaction priority can be increased by the should_compact_retry() function, but the current code is not optimal. Priority is only increased when compaction_failed() is true, which means that compaction has scanned the whole zone. This may not happen even after multiple attempts with a lower priority due to parallel activity, so we might needlessly struggle on the lower priorities and possibly run out of compaction retry attempts in the process.

After this patch we are guaranteed at least one attempt at the highest compaction priority even if we exhaust all retries at the lower priorities.

Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc David Rientjes <[email protected]>
Cc Rik van Riel <[email protected]>
---
 mm/page_alloc.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
mm/page_alloc.c +11 -7
index 1df7694f4ec7..f8bed910e3cf 100644
@@ -3174,13 +3174,8 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 	 * so it doesn't really make much sense to retry except when the
 	 * failure could be caused by insufficient priority
 	 */
-	if (compaction_failed(compact_result)) {
-		if (*compact_priority > MIN_COMPACT_PRIORITY) {
-			(*compact_priority)--;
-			return true;
-		}
-		return false;
-	}
+	if (compaction_failed(compact_result))
+		goto check_priority;
 
 	/*
 	 * make sure the compaction wasn't deferred or didn't bail out early
@@ -3204,6 +3199,15 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 	if (compaction_retries <= max_retries)
 		return true;
 
+	/*
+	 * Make sure there is at least one attempt at the highest priority
+	 * if we exhausted all retries at the lower priorities
+	 */
+check_priority:
+	if (*compact_priority > MIN_COMPACT_PRIORITY) {
+		(*compact_priority)--;
+		return true;
+	}
 	return false;
 }
 #else
Signature · 7 lines
2.9.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] mm, compaction: more reliably increase direct compaction priority

On Tue 06-09-16 15:52:56, Vlastimil Babka wrote:
[...]

mm/page_alloc.c should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, · line 3209

Quoted 12 lines
mm/page_alloc.c +8 -0
@@ -3204,6 +3199,15 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 	if (compaction_retries <= max_retries)
 		return true;
 
+	/*
+	 * Make sure there is at least one attempt at the highest priority
+	 * if we exhausted all retries at the lower priorities
+	 */
+check_priority:
+	if (*compact_priority > MIN_COMPACT_PRIORITY) {
+		(*compact_priority)--;
+		return true;

Don't we want to reset compaction_retries here? Otherwise we can consume all retries on the lower priorities.

Other than that it looks good to me. With that you can add

Quoted 4 lines
mm/page_alloc.c +1 -0
+	}
 	return false;
 }
 #else
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw

Re: [PATCH 2/4] mm, compaction: more reliably increase direct compaction priority

Quoted 6 lines · Michal Hocko

On Tue 06-09-16 15:52:56, Vlastimil Babka wrote:
[...]

Quoted 4 lines
(quoted diff) +0 -0
@@ -3204,6 +3199,15 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 	if (compaction_retries <= max_retries)
 		return true;
 
Quoted 11 lines

Review should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, · line 3209

Quoted 8 lines
(quoted diff) +8 -0
+	/*
+	 * Make sure there is at least one attempt at the highest priority
+	 * if we exhausted all retries at the lower priorities
+	 */
+check_priority:
+	if (*compact_priority > MIN_COMPACT_PRIORITY) {
+		(*compact_priority)--;
+		return true;

Don't we want to reset compaction_retries here? Otherwise we can consume all retries on the lower priorities.

Good point, patch-fix below.

Quoted 2 lines

Other than that it looks good to me. With that you can add

Thanks!

Quoted 5 lines

Review should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, · line 3213

Quoted 4 lines
(quoted diff) +1 -0
+	}
 	return false;
 }
 #else

----8<----

Acked-by
#6 lore raw

Re: [PATCH 2/4] mm, compaction: more reliably increase direct compaction priority

Quoted 8 lines · Vlastimil Babka
Quoted 1 line

From 465e1bd61b7a6d6901a44f09b1a76514dbc220fa Mon Sep 17 00:00:00 2001

From: Vlastimil Babka <[email protected]>
Date: Thu, 22 Sep 2016 13:54:32 +0200
Subject: [PATCH] mm, compaction: more reliably increase direct compaction
priority-fix

When increasing the compaction priority, also reset retries. Otherwise we can consume all retries on the lower priorities.

OK, this is an improvement. I am just thinking that we might want to pull

	if (order && compaction_made_progress(compact_result))
		compaction_retries++;

into should_compact_retry as well. I've had it there originally because it was in line with no_progress_loops but now that we have compaction priorities it would fit into retry logic better. As a plus it would count only those compaction rounds where we we didn't have to rely on the compaction retry logic. What do you think?

Quoted 2 lines

Anyway

Quoted 59 lines
---
 mm/page_alloc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
mm/page_alloc.c +7 -6
index f8bed910e3cf..82fdb690ac62 100644
@@ -3162,7 +3162,7 @@ static inline bool
 should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 		     enum compact_result compact_result,
 		     enum compact_priority *compact_priority,
-		     int compaction_retries)
+		     int *compaction_retries)
 {
 	int max_retries = MAX_COMPACT_RETRIES;
 
@@ -3196,16 +3196,17 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 	 */
 	if (order > PAGE_ALLOC_COSTLY_ORDER)
 		max_retries /= 4;
-	if (compaction_retries <= max_retries)
+	if (*compaction_retries <= max_retries)
 		return true;
 
 	/*
-	 * Make sure there is at least one attempt at the highest priority
-	 * if we exhausted all retries at the lower priorities
+	 * Make sure there are attempts at the highest priority if we exhausted
+	 * all retries or failed at the lower priorities.
 	 */
 check_priority:
 	if (*compact_priority > MIN_COMPACT_PRIORITY) {
 		(*compact_priority)--;
+		*compaction_retries = 0;
 		return true;
 	}
 	return false;
@@ -3224,7 +3225,7 @@ static inline bool
 should_compact_retry(struct alloc_context *ac, unsigned int order, int alloc_flags,
 		     enum compact_result compact_result,
 		     enum compact_priority *compact_priority,
-		     int compaction_retries)
+		     int *compaction_retries)
 {
 	struct zone *zone;
 	struct zoneref *z;
@@ -3663,7 +3664,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 	if (did_some_progress > 0 &&
 			should_compact_retry(ac, order, alloc_flags,
 				compact_result, &compact_priority,
-				compaction_retries))
+				&compaction_retries))
 		goto retry;
 
 	/* Reclaim has failed us, start killing things */
Signature · 1 line
2.10.0
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw

Re: [PATCH 2/4] mm, compaction: more reliably increase direct compaction priority

Quoted 12 lines · Michal Hocko
Quoted 8 lines · Vlastimil Babka
Quoted 1 line

From 465e1bd61b7a6d6901a44f09b1a76514dbc220fa Mon Sep 17 00:00:00 2001

From: Vlastimil Babka <[email protected]>
Date: Thu, 22 Sep 2016 13:54:32 +0200
Subject: [PATCH] mm, compaction: more reliably increase direct compaction
priority-fix

When increasing the compaction priority, also reset retries. Otherwise we can consume all retries on the lower priorities.

OK, this is an improvement. I am just thinking that we might want to pull

Quoted 7 lines
	if (order && compaction_made_progress(compact_result))
		compaction_retries++;

into should_compact_retry as well. I've had it there originally because it was in line with no_progress_loops but now that we have compaction priorities it would fit into retry logic better. As a plus it would count only those compaction rounds where we we didn't have to rely on

did that should be

Quoted 71 lines

the compaction retry logic. What do you think?

Quoted 2 lines

Anyway

Quoted 59 lines
---
 mm/page_alloc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
mm/page_alloc.c +7 -6
index f8bed910e3cf..82fdb690ac62 100644
@@ -3162,7 +3162,7 @@ static inline bool
 should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 		     enum compact_result compact_result,
 		     enum compact_priority *compact_priority,
-		     int compaction_retries)
+		     int *compaction_retries)
 {
 	int max_retries = MAX_COMPACT_RETRIES;
 
@@ -3196,16 +3196,17 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 	 */
 	if (order > PAGE_ALLOC_COSTLY_ORDER)
 		max_retries /= 4;
-	if (compaction_retries <= max_retries)
+	if (*compaction_retries <= max_retries)
 		return true;
 
 	/*
-	 * Make sure there is at least one attempt at the highest priority
-	 * if we exhausted all retries at the lower priorities
+	 * Make sure there are attempts at the highest priority if we exhausted
+	 * all retries or failed at the lower priorities.
 	 */
 check_priority:
 	if (*compact_priority > MIN_COMPACT_PRIORITY) {
 		(*compact_priority)--;
+		*compaction_retries = 0;
 		return true;
 	}
 	return false;
@@ -3224,7 +3225,7 @@ static inline bool
 should_compact_retry(struct alloc_context *ac, unsigned int order, int alloc_flags,
 		     enum compact_result compact_result,
 		     enum compact_priority *compact_priority,
-		     int compaction_retries)
+		     int *compaction_retries)
 {
 	struct zone *zone;
 	struct zoneref *z;
@@ -3663,7 +3664,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 	if (did_some_progress > 0 &&
 			should_compact_retry(ac, order, alloc_flags,
 				compact_result, &compact_priority,
-				compaction_retries))
+				&compaction_retries))
 		goto retry;
 
 	/* Reclaim has failed us, start killing things */
Signature · 1 line
2.10.0
Signature · 2 lines
Michal Hocko
SUSE Labs
Signature · 2 lines
Michal Hocko
SUSE Labs
author Acked-by Michal Hocko
#8 lore raw

Re: [PATCH 2/4] mm, compaction: more reliably increase direct compaction priority

Quoted 16 lines · Michal Hocko
Quoted 15 lines · Michal Hocko
Quoted 8 lines · Vlastimil Babka
Quoted 1 line

From 465e1bd61b7a6d6901a44f09b1a76514dbc220fa Mon Sep 17 00:00:00 2001

From: Vlastimil Babka <[email protected]>
Date: Thu, 22 Sep 2016 13:54:32 +0200
Subject: [PATCH] mm, compaction: more reliably increase direct compaction
priority-fix

When increasing the compaction priority, also reset retries. Otherwise we can consume all retries on the lower priorities.

OK, this is an improvement. I am just thinking that we might want to pull

	if (order && compaction_made_progress(compact_result))
		compaction_retries++;
Quoted 7 lines
Quoted 4 lines

into should_compact_retry as well. I've had it there originally because it was in line with no_progress_loops but now that we have compaction priorities it would fit into retry logic better. As a plus it would count only those compaction rounds where we we didn't have to rely on

did that should be

Quoted 1 line

the compaction retry logic. What do you think?

Makes sense.

-----8<-----

#9 lore raw

Re: [PATCH 2/4] mm, compaction: more reliably increase direct compaction priority

In reply to Michal Hocko
Quoted 16 lines · Michal Hocko
Quoted 15 lines · Michal Hocko
Quoted 8 lines · Vlastimil Babka
Quoted 1 line

From 465e1bd61b7a6d6901a44f09b1a76514dbc220fa Mon Sep 17 00:00:00 2001

From: Vlastimil Babka <[email protected]>
Date: Thu, 22 Sep 2016 13:54:32 +0200
Subject: [PATCH] mm, compaction: more reliably increase direct compaction
priority-fix

When increasing the compaction priority, also reset retries. Otherwise we can consume all retries on the lower priorities.

OK, this is an improvement. I am just thinking that we might want to pull

	if (order && compaction_made_progress(compact_result))
		compaction_retries++;
Quoted 7 lines
Quoted 4 lines

into should_compact_retry as well. I've had it there originally because it was in line with no_progress_loops but now that we have compaction priorities it would fit into retry logic better. As a plus it would count only those compaction rounds where we we didn't have to rely on

did that should be

Quoted 1 line

the compaction retry logic. What do you think?

In that case I would also add this for consistency?

----8<----

Acked-by
#10 lore raw

Re: [PATCH 2/4] mm, compaction: more reliably increase direct compaction priority

Quoted 28 lines

----8<----
From a7921e57ba1189b9c08fc4879358a908c390e47c Mon Sep 17 00:00:00 2001
From: Vlastimil Babka <[email protected]>
Date: Thu, 22 Sep 2016 17:02:37 +0200
Subject: [PATCH] mm, page_alloc: pull no_progress_loops update to
should_reclaim_retry()

The should_reclaim_retry() makes decisions based on no_progress_loops, so it makes sense to also update the counter there. It will be also consistent with should_compact_retry() and compaction_retries. No functional change.

---
 mm/page_alloc.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
mm/page_alloc.c +1 -1
index 582820080601..a01359ab3ed6 100644
@@ -3401,16 +3401,26 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
 static inline bool
 should_reclaim_retry(gfp_t gfp_mask, unsigned order,
 		     struct alloc_context *ac, int alloc_flags,
-		     bool did_some_progress, int no_progress_loops)
+		     bool did_some_progress, int *no_progress_loops)
 {

mm/page_alloc.c bool gfp_pfmemalloc_allowed(gfp_t gfp_mask) · line 3415

Quoted 10 lines
mm/page_alloc.c +6 -0
 	struct zone *zone;
 	struct zoneref *z;
 
 	/*
+	 * Costly allocations might have made a progress but this doesn't mean
+	 * their order will become available due to high fragmentation so
+	 * always increment the no progress counter for them
+	 */
+	if (did_some_progress && order <= PAGE_ALLOC_COSTLY_ORDER)
+		no_progress_loops = 0;

s/no/*no/

mm/page_alloc.c bool gfp_pfmemalloc_allowed(gfp_t gfp_mask) · line 3417

Quoted 2 lines
mm/page_alloc.c +2 -0
+	else
+		no_progress_loops++;

s/no_progress_loops/(*no_progress_loops)/

With that feel free to add

Quoted 40 lines
mm/page_alloc.c +5 -14
+
+	/*
 	 * Make sure we converge to OOM if we cannot make any progress
 	 * several times in the row.
 	 */
-	if (no_progress_loops > MAX_RECLAIM_RETRIES)
+	if (*no_progress_loops > MAX_RECLAIM_RETRIES)
 		return false;
 
 	/*
@@ -3425,7 +3435,7 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order,
 		unsigned long reclaimable;
 
 		available = reclaimable = zone_reclaimable_pages(zone);
-		available -= DIV_ROUND_UP(no_progress_loops * available,
+		available -= DIV_ROUND_UP((*no_progress_loops) * available,
 					  MAX_RECLAIM_RETRIES);
 		available += zone_page_state_snapshot(zone, NR_FREE_PAGES);
 
@@ -3641,18 +3651,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 	if (order > PAGE_ALLOC_COSTLY_ORDER && !(gfp_mask & __GFP_REPEAT))
 		goto nopage;
 
-	/*
-	 * Costly allocations might have made a progress but this doesn't mean
-	 * their order will become available due to high fragmentation so
-	 * always increment the no progress counter for them
-	 */
-	if (did_some_progress && order <= PAGE_ALLOC_COSTLY_ORDER)
-		no_progress_loops = 0;
-	else
-		no_progress_loops++;
-
 	if (should_reclaim_retry(gfp_mask, order, ac, alloc_flags,
-				 did_some_progress > 0, no_progress_loops))
+				 did_some_progress > 0, &no_progress_loops))
 		goto retry;
 
 	/*
--
Quoted 1 line

2.10.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author Acked-by Hillf Danton
#11 lore raw

Re: [PATCH 2/4] mm, compaction: more reliably increase direct compaction priority

Quoted 40 lines · Hillf Danton
Quoted 28 lines

----8<----
From a7921e57ba1189b9c08fc4879358a908c390e47c Mon Sep 17 00:00:00 2001
From: Vlastimil Babka <[email protected]>
Date: Thu, 22 Sep 2016 17:02:37 +0200
Subject: [PATCH] mm, page_alloc: pull no_progress_loops update to
should_reclaim_retry()

The should_reclaim_retry() makes decisions based on no_progress_loops, so it makes sense to also update the counter there. It will be also consistent with should_compact_retry() and compaction_retries. No functional change.

---
 mm/page_alloc.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
mm/page_alloc.c +1 -1
index 582820080601..a01359ab3ed6 100644
@@ -3401,16 +3401,26 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
 static inline bool
 should_reclaim_retry(gfp_t gfp_mask, unsigned order,
 		     struct alloc_context *ac, int alloc_flags,
-		     bool did_some_progress, int no_progress_loops)
+		     bool did_some_progress, int *no_progress_loops)
 {

mm/page_alloc.c bool gfp_pfmemalloc_allowed(gfp_t gfp_mask) · line 3415

Quoted 10 lines
mm/page_alloc.c +6 -0
 	struct zone *zone;
 	struct zoneref *z;
 
 	/*
+	 * Costly allocations might have made a progress but this doesn't mean
+	 * their order will become available due to high fragmentation so
+	 * always increment the no progress counter for them
+	 */
+	if (did_some_progress && order <= PAGE_ALLOC_COSTLY_ORDER)
+		no_progress_loops = 0;

s/no/*no/

Quoted 4 lines

mm/page_alloc.c bool gfp_pfmemalloc_allowed(gfp_t gfp_mask) · line 3417

Quoted 2 lines
mm/page_alloc.c +2 -0
+	else
+		no_progress_loops++;

s/no_progress_loops/(*no_progress_loops)/

Crap, thanks. I'm asking our gcc guy about possible warnings for this, and some past mistake I've seen which would be *no_progress_loops++.

Quoted 2 lines

With that feel free to add

Thanks!

----8<----

Acked-by
#12 lore raw

Re: [PATCH 2/4] mm, compaction: more reliably increase direct compaction priority

On Fri 23-09-16 08:55:33, Vlastimil Babka wrote:
[...]

Quoted 6 lines
Quoted 1 line

From 1623d5bd441160569ffad3808aeeec852048e558 Mon Sep 17 00:00:00 2001

From: Vlastimil Babka <[email protected]>
Date: Thu, 22 Sep 2016 17:02:37 +0200
Subject: [PATCH] mm, page_alloc: pull no_progress_loops update to
should_reclaim_retry()

Quoted 7 lines

The should_reclaim_retry() makes decisions based on no_progress_loops, so it makes sense to also update the counter there. It will be also consistent with should_compact_retry() and compaction_retries. No functional change.

[[email protected]: fix missing pointer dereferences]

OK, this looks reasonable to me. Could you post both patches in a separate thread please? They shouldn't be really needed to mitigate the pre-mature oom killer issues. Feel free to add

Thanks!

Quoted 75 lines
---
 mm/page_alloc.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
mm/page_alloc.c +14 -14
index 582820080601..6039ff40452c 100644
@@ -3401,16 +3401,26 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
 static inline bool
 should_reclaim_retry(gfp_t gfp_mask, unsigned order,
 		     struct alloc_context *ac, int alloc_flags,
-		     bool did_some_progress, int no_progress_loops)
+		     bool did_some_progress, int *no_progress_loops)
 {
 	struct zone *zone;
 	struct zoneref *z;
 
 	/*
+	 * Costly allocations might have made a progress but this doesn't mean
+	 * their order will become available due to high fragmentation so
+	 * always increment the no progress counter for them
+	 */
+	if (did_some_progress && order <= PAGE_ALLOC_COSTLY_ORDER)
+		*no_progress_loops = 0;
+	else
+		(*no_progress_loops)++;
+
+	/*
 	 * Make sure we converge to OOM if we cannot make any progress
 	 * several times in the row.
 	 */
-	if (no_progress_loops > MAX_RECLAIM_RETRIES)
+	if (*no_progress_loops > MAX_RECLAIM_RETRIES)
 		return false;
 
 	/*
@@ -3425,7 +3435,7 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order,
 		unsigned long reclaimable;
 
 		available = reclaimable = zone_reclaimable_pages(zone);
-		available -= DIV_ROUND_UP(no_progress_loops * available,
+		available -= DIV_ROUND_UP((*no_progress_loops) * available,
 					  MAX_RECLAIM_RETRIES);
 		available += zone_page_state_snapshot(zone, NR_FREE_PAGES);
 
@@ -3641,18 +3651,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 	if (order > PAGE_ALLOC_COSTLY_ORDER && !(gfp_mask & __GFP_REPEAT))
 		goto nopage;
 
-	/*
-	 * Costly allocations might have made a progress but this doesn't mean
-	 * their order will become available due to high fragmentation so
-	 * always increment the no progress counter for them
-	 */
-	if (did_some_progress && order <= PAGE_ALLOC_COSTLY_ORDER)
-		no_progress_loops = 0;
-	else
-		no_progress_loops++;
-
 	if (should_reclaim_retry(gfp_mask, order, ac, alloc_flags,
-				 did_some_progress > 0, no_progress_loops))
+				 did_some_progress > 0, &no_progress_loops))
 		goto retry;
 
 	/*
Signature · 8 lines
2.10.0


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#13 lore raw

Re: [PATCH 2/4] mm, compaction: more reliably increase direct compaction priority

Quoted 12 lines · Michal Hocko

On Fri 23-09-16 08:55:33, Vlastimil Babka wrote:
[...]

Quoted 10 lines
Quoted 1 line

From 1623d5bd441160569ffad3808aeeec852048e558 Mon Sep 17 00:00:00 2001

From: Vlastimil Babka <[email protected]>
Date: Thu, 22 Sep 2016 17:02:37 +0200
Subject: [PATCH] mm, page_alloc: pull no_progress_loops update to
should_reclaim_retry()

The should_reclaim_retry() makes decisions based on no_progress_loops, so it makes sense to also update the counter there. It will be also consistent with should_compact_retry() and compaction_retries. No functional change.

Quoted 5 lines
Quoted 3 lines
[[email protected]: fix missing pointer dereferences]

OK, this looks reasonable to me. Could you post both patches in a

Both? I would argue that [1] might be relevant because it resets the number of retries. Only the should_reclaim_retry() cleanup is not stricly needed.

[1] http://lkml.kernel.org/r/<[email protected]>

Quoted 76 lines

separate thread please? They shouldn't be really needed to mitigate the pre-mature oom killer issues. Feel free to add

Thanks!

Quoted 70 lines
---
 mm/page_alloc.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
mm/page_alloc.c +14 -14
index 582820080601..6039ff40452c 100644
@@ -3401,16 +3401,26 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
 static inline bool
 should_reclaim_retry(gfp_t gfp_mask, unsigned order,
 		     struct alloc_context *ac, int alloc_flags,
-		     bool did_some_progress, int no_progress_loops)
+		     bool did_some_progress, int *no_progress_loops)
 {
 	struct zone *zone;
 	struct zoneref *z;
 
 	/*
+	 * Costly allocations might have made a progress but this doesn't mean
+	 * their order will become available due to high fragmentation so
+	 * always increment the no progress counter for them
+	 */
+	if (did_some_progress && order <= PAGE_ALLOC_COSTLY_ORDER)
+		*no_progress_loops = 0;
+	else
+		(*no_progress_loops)++;
+
+	/*
 	 * Make sure we converge to OOM if we cannot make any progress
 	 * several times in the row.
 	 */
-	if (no_progress_loops > MAX_RECLAIM_RETRIES)
+	if (*no_progress_loops > MAX_RECLAIM_RETRIES)
 		return false;
 
 	/*
@@ -3425,7 +3435,7 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order,
 		unsigned long reclaimable;
 
 		available = reclaimable = zone_reclaimable_pages(zone);
-		available -= DIV_ROUND_UP(no_progress_loops * available,
+		available -= DIV_ROUND_UP((*no_progress_loops) * available,
 					  MAX_RECLAIM_RETRIES);
 		available += zone_page_state_snapshot(zone, NR_FREE_PAGES);
 
@@ -3641,18 +3651,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 	if (order > PAGE_ALLOC_COSTLY_ORDER && !(gfp_mask & __GFP_REPEAT))
 		goto nopage;
 
-	/*
-	 * Costly allocations might have made a progress but this doesn't mean
-	 * their order will become available due to high fragmentation so
-	 * always increment the no progress counter for them
-	 */
-	if (did_some_progress && order <= PAGE_ALLOC_COSTLY_ORDER)
-		no_progress_loops = 0;
-	else
-		no_progress_loops++;
-
 	if (should_reclaim_retry(gfp_mask, order, ac, alloc_flags,
-				 did_some_progress > 0, no_progress_loops))
+				 did_some_progress > 0, &no_progress_loops))
 		goto retry;
 
 	/*
Signature · 1 line
2.10.0
Quoted 6 lines
Quoted 5 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw

Re: [PATCH 2/4] mm, compaction: more reliably increase direct compaction priority

Quoted 17 lines · Vlastimil Babka
Quoted 16 lines · Michal Hocko

On Fri 23-09-16 08:55:33, Vlastimil Babka wrote:
[...]

Quoted 13 lines
Quoted 1 line

From 1623d5bd441160569ffad3808aeeec852048e558 Mon Sep 17 00:00:00 2001

From: Vlastimil Babka <[email protected]>
Date: Thu, 22 Sep 2016 17:02:37 +0200
Subject: [PATCH] mm, page_alloc: pull no_progress_loops update to
should_reclaim_retry()

The should_reclaim_retry() makes decisions based on no_progress_loops, so it makes sense to also update the counter there. It will be also consistent with should_compact_retry() and compaction_retries. No functional change.

[[email protected]: fix missing pointer dereferences]
Quoted 5 lines
Quoted 1 line

OK, this looks reasonable to me. Could you post both patches in a

Both? I would argue that [1] might be relevant because it resets the number of retries. Only the should_reclaim_retry() cleanup is not stricly needed.

Even if it is needed which I am not really sure about it would be easier to track than in the middle of another thread.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#15 lore raw

PATCH 3/4 mm, compaction: restrict full priority to non-costly orders

In reply to Vlastimil Babka

The new ultimate compaction priority disables some heuristics, which may result in excessive cost. This is fine for non-costly orders where we want to try hard before resulting for OOM, but might be disruptive for costly orders which do not trigger OOM and should generally have some fallback. Thus, we disable the full priority for costly orders.

Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc David Rientjes <[email protected]>
Cc Rik van Riel <[email protected]>
---
 include/linux/compaction.h | 1 +
 mm/page_alloc.c            | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)
include/linux/compaction.h +1 -0
index 585d55cb0dc0..0d8415820fc3 100644
@@ -9,6 +9,7 @@ enum compact_priority {
 	COMPACT_PRIO_SYNC_FULL,
 	MIN_COMPACT_PRIORITY = COMPACT_PRIO_SYNC_FULL,
 	COMPACT_PRIO_SYNC_LIGHT,
+	MIN_COMPACT_COSTLY_PRIORITY = COMPACT_PRIO_SYNC_LIGHT,
 	DEF_COMPACT_PRIORITY = COMPACT_PRIO_SYNC_LIGHT,
 	COMPACT_PRIO_ASYNC,
 	INIT_COMPACT_PRIORITY = COMPACT_PRIO_ASYNC
mm/page_alloc.c +4 -1
index f8bed910e3cf..ff60a2837c58 100644
@@ -3165,6 +3165,7 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 		     int compaction_retries)
 {
 	int max_retries = MAX_COMPACT_RETRIES;
+	int min_priority;
 
 	if (!order)
 		return false;
@@ -3204,7 +3205,9 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 	 * if we exhausted all retries at the lower priorities
 	 */
 check_priority:
-	if (*compact_priority > MIN_COMPACT_PRIORITY) {
+	min_priority = (order > PAGE_ALLOC_COSTLY_ORDER) ?
+			MIN_COMPACT_COSTLY_PRIORITY : MIN_COMPACT_PRIORITY;
+	if (*compact_priority > min_priority) {
 		(*compact_priority)--;
 		return true;
 	}
Signature · 7 lines
2.9.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 3/4
#16 lore raw

Re: [PATCH 3/4] mm, compaction: restrict full priority to non-costly orders

Quoted 6 lines · Vlastimil Babka

The new ultimate compaction priority disables some heuristics, which may result in excessive cost. This is fine for non-costly orders where we want to try hard before resulting for OOM, but might be disruptive for costly orders which do not trigger OOM and should generally have some fallback. Thus, we disable the full priority for costly orders.

Quoted 7 lines
Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc David Rientjes <[email protected]>
Cc Rik van Riel <[email protected]>
Quoted 42 lines
---
 include/linux/compaction.h | 1 +
 mm/page_alloc.c            | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)
include/linux/compaction.h +1 -0
index 585d55cb0dc0..0d8415820fc3 100644
@@ -9,6 +9,7 @@ enum compact_priority {
 	COMPACT_PRIO_SYNC_FULL,
 	MIN_COMPACT_PRIORITY = COMPACT_PRIO_SYNC_FULL,
 	COMPACT_PRIO_SYNC_LIGHT,
+	MIN_COMPACT_COSTLY_PRIORITY = COMPACT_PRIO_SYNC_LIGHT,
 	DEF_COMPACT_PRIORITY = COMPACT_PRIO_SYNC_LIGHT,
 	COMPACT_PRIO_ASYNC,
 	INIT_COMPACT_PRIORITY = COMPACT_PRIO_ASYNC
mm/page_alloc.c +4 -1
index f8bed910e3cf..ff60a2837c58 100644
@@ -3165,6 +3165,7 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 		     int compaction_retries)
 {
 	int max_retries = MAX_COMPACT_RETRIES;
+	int min_priority;
 
 	if (!order)
 		return false;
@@ -3204,7 +3205,9 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 	 * if we exhausted all retries at the lower priorities
 	 */
 check_priority:
-	if (*compact_priority > MIN_COMPACT_PRIORITY) {
+	min_priority = (order > PAGE_ALLOC_COSTLY_ORDER) ?
+			MIN_COMPACT_COSTLY_PRIORITY : MIN_COMPACT_PRIORITY;
+	if (*compact_priority > min_priority) {
 		(*compact_priority)--;
 		return true;
 	}
Signature · 1 line
2.9.3
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#17 lore raw

PATCH 4/4 mm, compaction: make full priority ignore pageblock suitability

In reply to Vlastimil Babka

Several people have reported premature OOMs for order-2 allocations (stack) due to OOM rework in 4.7. In the scenario (parallel kernel build and dd writing to two drives) many pageblocks get marked as Unmovable and compaction free scanner struggles to isolate free pages. Joonsoo Kim pointed out that the free scanner skips pageblocks that are not movable to prevent filling them and forcing non-movable allocations to fallback to other pageblocks. Such heuristic makes sense to help prevent long-term fragmentation, but premature OOMs are relatively more urgent problem. As a compromise, this patch disables the heuristic only for the ultimate compaction priority.

---
 mm/compaction.c | 11 ++++++++---
 mm/internal.h   |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)
mm/compaction.c +8 -3
index 29f6c49dc9c2..86d4d0bbfc7c 100644
@@ -997,8 +997,12 @@ isolate_migratepages_range(struct compact_control *cc, unsigned long start_pfn,
 #ifdef CONFIG_COMPACTION
 
 /* Returns true if the page is within a block suitable for migration to */
-static bool suitable_migration_target(struct page *page)
+static bool suitable_migration_target(struct compact_control *cc,
+							struct page *page)
 {
+	if (cc->ignore_block_suitable)
+		return true;
+
 	/* If the page is a large free page, then disallow migration */
 	if (PageBuddy(page)) {
 		/*
@@ -1083,7 +1087,7 @@ static void isolate_freepages(struct compact_control *cc)
 			continue;
 
 		/* Check the block is suitable for migration */
-		if (!suitable_migration_target(page))
+		if (!suitable_migration_target(cc, page))
 			continue;
 
 		/* If isolation recently failed, do not retry */
@@ -1656,7 +1660,8 @@ static enum compact_result compact_zone_order(struct zone *zone, int order,
 		.classzone_idx = classzone_idx,
 		.direct_compaction = true,
 		.whole_zone = (prio == MIN_COMPACT_PRIORITY),
-		.ignore_skip_hint = (prio == MIN_COMPACT_PRIORITY)
+		.ignore_skip_hint = (prio == MIN_COMPACT_PRIORITY),
+		.ignore_block_suitable = (prio == MIN_COMPACT_PRIORITY)
 	};
 	INIT_LIST_HEAD(&cc.freepages);
 	INIT_LIST_HEAD(&cc.migratepages);
mm/internal.h +1 -0
index 5214bf8e3171..537ac9951f5f 100644
@@ -178,6 +178,7 @@ struct compact_control {
 	unsigned long last_migrated_pfn;/* Not yet flushed page being freed */
 	enum migrate_mode mode;		/* Async or sync migration mode */
 	bool ignore_skip_hint;		/* Scan blocks even if marked skip */
+	bool ignore_block_suitable;	/* Scan blocks considered unsuitable */
 	bool direct_compaction;		/* False from kcompactd or /proc/... */
 	bool whole_zone;		/* Whole zone should/has been scanned */
 	int order;			/* order a direct compactor needs */
Signature · 7 lines
2.9.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#18 lore raw
In reply to Vlastimil Babka
Quoted 13 lines · Vlastimil Babka

After several people reported OOM's for order-2 allocations in 4.7 due to Michal Hocko's OOM rework, he reverted the part that considered compaction feedback [1] in the decisions to retry reclaim/compaction. This was to provide a fix quickly for 4.8 rc and 4.7 stable series, while mmotm had an almost complete solution that instead improved compaction reliability.

This series completes the mmotm solution and reintroduces the compaction feedback into OOM decisions. The first two patches restore the state of mmotm before the temporary solution was merged, the last patch should be the missing piece for reliability. The third patch restricts the hardened compaction to non-costly orders, since costly orders don't result in OOMs in the first place.

Quoted 4 lines

Some preliminary testing suggested that this approach should work, but I would like to ask all who experienced the regression to please retest this. You will need to apply this series on top of tag mmotm-2016-08-31-16-06 from the mmotm git tree [2]. Thanks in advance!

My "rm -rf copyX; cp -al org copyX" test x10 in parallel worked without any OOM.

Signature · 7 lines
Arkadiusz Miśkiewicz, arekm / ( maven.pl | pld-linux.org )

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#19 lore raw
In reply to Vlastimil Babka
Quoted 12 lines · Vlastimil Babka

After several people reported OOM's for order-2 allocations in 4.7 due to Michal Hocko's OOM rework, he reverted the part that considered compaction feedback [1] in the decisions to retry reclaim/compaction. This was to provide a fix quickly for 4.8 rc and 4.7 stable series, while mmotm had an almost complete solution that instead improved compaction reliability.

This series completes the mmotm solution and reintroduces the compaction feedback into OOM decisions. The first two patches restore the state of mmotm before the temporary solution was merged, the last patch should be the missing piece for reliability. The third patch restricts the hardened compaction to non-costly orders, since costly orders don't result in OOMs in the first place.

Quoted 4 lines

Some preliminary testing suggested that this approach should work, but I would like to ask all who experienced the regression to please retest this. You will need to apply this series on top of tag mmotm-2016-08-31-16-06 from the mmotm git tree [2]. Thanks in advance!

We still do not ignore fragindex in the full priority. This part has always been quite unclear to me so I cannot really tell whether that makes any difference or not but just to be on the safe side I would preffer to have _all_ the shortcuts out of the way in the highest priority. It is true that this will cause COMPACT_NOT_SUITABLE_ZONE so keep retrying but still a complication to understand the workflow.

What do you think?

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#20 lore raw
Quoted 10 lines · Michal Hocko

On Tue 06-09-16 15:52:54, Vlastimil Babka wrote:

We still do not ignore fragindex in the full priority. This part has always been quite unclear to me so I cannot really tell whether that makes any difference or not but just to be on the safe side I would preffer to have _all_ the shortcuts out of the way in the highest priority. It is true that this will cause COMPACT_NOT_SUITABLE_ZONE so keep retrying but still a complication to understand the workflow.

What do you think?

I was thinking that this shouldn't be a problem on non-costly orders and default extfrag_threshold. But better be safe. Moreover I think the issue is much more dangerous for compact_zonelist_suitable() as explained below.

----8<----

#21 lore raw
Quoted 33 lines · Vlastimil Babka
Quoted 10 lines · Michal Hocko

On Tue 06-09-16 15:52:54, Vlastimil Babka wrote:

We still do not ignore fragindex in the full priority. This part has always been quite unclear to me so I cannot really tell whether that makes any difference or not but just to be on the safe side I would preffer to have _all_ the shortcuts out of the way in the highest priority. It is true that this will cause COMPACT_NOT_SUITABLE_ZONE so keep retrying but still a complication to understand the workflow.

What do you think?

I was thinking that this shouldn't be a problem on non-costly orders and default extfrag_threshold. But better be safe. Moreover I think the issue is much more dangerous for compact_zonelist_suitable() as explained below.

----8<----

Quoted 1 line

From 0e6cb251aa6e3b1be7deff315c0238c4d478f22e Mon Sep 17 00:00:00 2001

From: Vlastimil Babka <[email protected]>
Date: Thu, 22 Sep 2016 15:33:57 +0200
Subject: [PATCH] mm, compaction: ignore fragindex on highest direct compaction
priority

Fragmentation index check in compaction_suitable() should be the last heuristic that we allow on the highest compaction priority. Since that's a potential premature OOM, disable it too. Even more problematic is its usage from compaction_zonelist_suitable() -> __compaction_suitable() where we check the order-0 watermark against free plus available-for-reclaim pages, but the fragindex considers only truly free pages. Thus we can get a result close to 0 indicating failure do to lack of memory, and wrongly decide that compaction won't be suitable even after reclaim. The solution is to skip the fragindex check also in this context, regardless of priority.

Quoted 7 lines
---
 include/linux/compaction.h |  5 +++--
 mm/compaction.c            | 44 +++++++++++++++++++++++---------------------
 mm/internal.h              |  1 +
 mm/vmscan.c                |  6 ++++--
 4 files changed, 31 insertions(+), 25 deletions(-)

This is much more code churn than I expected. I was thiking about it some more and I am really wondering whether it actually make any sense to check the fragidx for !costly orders. Wouldn't it be much simpler to just put it out of the way for those regardless of the compaction priority. In other words does this check makes any measurable difference for !costly orders?

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#22 lore raw
Quoted 6 lines · Michal Hocko
Quoted 5 lines
 include/linux/compaction.h |  5 +++--
 mm/compaction.c            | 44 +++++++++++++++++++++++---------------------
 mm/internal.h              |  1 +
 mm/vmscan.c                |  6 ++++--
 4 files changed, 31 insertions(+), 25 deletions(-)
Quoted 6 lines

This is much more code churn than I expected. I was thiking about it some more and I am really wondering whether it actually make any sense to check the fragidx for !costly orders. Wouldn't it be much simpler to just put it out of the way for those regardless of the compaction priority. In other words does this check makes any measurable difference for !costly orders?

I've did some stress tests and sampling /sys/kernel/debug/extfrag/extfrag_index once per second. The lowest value I've got for order-2 was 0.705. The default threshold is 0.5, so this would still result in compaction considered as suitable.

But it's sampling so I might not got to the interesting moments, most of the time it was -1.000 which means the page should be just available. Also we would be changing behavior for the user-controlled vm.extfrag_threshold, so I'm not entirely sure about that.

I could probably reduce the churn so that compaction_suitable() doesn't need a new parameter. We could just skip compaction_suitable() check from compact_zone() on the highest priority, and go on even without sufficient free page gap?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#23 lore raw
Quoted 19 lines · Vlastimil Babka
Quoted 6 lines · Michal Hocko
Quoted 5 lines
 include/linux/compaction.h |  5 +++--
 mm/compaction.c            | 44 +++++++++++++++++++++++---------------------
 mm/internal.h              |  1 +
 mm/vmscan.c                |  6 ++++--
 4 files changed, 31 insertions(+), 25 deletions(-)
Quoted 6 lines

This is much more code churn than I expected. I was thiking about it some more and I am really wondering whether it actually make any sense to check the fragidx for !costly orders. Wouldn't it be much simpler to just put it out of the way for those regardless of the compaction priority. In other words does this check makes any measurable difference for !costly orders?

I've did some stress tests and sampling /sys/kernel/debug/extfrag/extfrag_index once per second. The lowest value I've got for order-2 was 0.705. The default threshold is 0.5, so this would still result in compaction considered as suitable.

Quoted 4 lines

But it's sampling so I might not got to the interesting moments, most of the time it was -1.000 which means the page should be just available. Also we would be changing behavior for the user-controlled vm.extfrag_threshold, so I'm not entirely sure about that.

Does anybody depend on that or even use it out there? I strongly suspect this is one of those dark corners people even do not know they exist...

Quoted 4 lines

I could probably reduce the churn so that compaction_suitable() doesn't need a new parameter. We could just skip compaction_suitable() check from compact_zone() on the highest priority, and go on even without sufficient free page gap?

Whatever makes the code easier to understand. Please do not take me wrong I do not want to push back on this too hard I just always love to get rid of an obscure heuristic which even might not matter. And as your testing suggests this might really be the case for !costly orders AFAIU.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>