Re: [RFC PATCH] mm/vmscan: fix high cpu usage of kswapd if there

From: Johannes Weiner
Date: Wed Feb 22 2017 - 15:54:58 EST

On Wed, Feb 22, 2017 at 03:16:57PM -0500, Johannes Weiner wrote:
> [...] And then it sounds pretty much like what the allocator/direct
> reclaim already does.

On a side note: Michal, I'm not sure I fully understand why we need
the backoff code in should_reclaim_retry(). If no_progress_loops is
growing steadily, then we quickly reach 16 and bail anyway. Layering
on top a backoff function that *might* cut out an iteration or two
earlier in the cold path of an OOM situation seems unnecessary.
Conversely, if there *are* intermittent reclaims, no_progress_loops
gets reset straight to 0, which then also makes the backoff function
jump back to square one. So in the only situation where backing off
would make sense - making some progress, but not enough - it's not
actually backing off. It seems to me it should be enough to bail after
either 16 iterations or when free + reclaimable < watermark.


diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index c470b8fe28cf..b0e9495c0530 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3396,11 +3396,10 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
* Checks whether it makes sense to retry the reclaim to make a forward progress
* for the given allocation request.
- * The reclaim feedback represented by did_some_progress (any progress during
- * the last reclaim round) and no_progress_loops (number of reclaim rounds without
- * any progress in a row) is considered as well as the reclaimable pages on the
- * applicable zone list (with a backoff mechanism which is a function of
- * no_progress_loops).
+ *
+ * We give up when we either have tried MAX_RECLAIM_RETRIES in a row
+ * without success, or when we couldn't even meet the watermark if we
+ * reclaimed all remaining pages on the LRU lists.
* Returns true if a retry is viable or false to enter the oom path.
@@ -3441,13 +3440,11 @@ 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 += zone_page_state_snapshot(zone, NR_FREE_PAGES);

- * Would the allocation succeed if we reclaimed the whole
- * available?
+ * Would the allocation succeed if we reclaimed all
+ * the reclaimable pages?
if (__zone_watermark_ok(zone, order, min_wmark_pages(zone),
ac_classzone_idx(ac), alloc_flags, available)) {