Commit dafcb73e authored by Zlatko Calusic's avatar Zlatko Calusic Committed by Linus Torvalds

mm: avoid calling pgdat_balanced() needlessly

Now that balance_pgdat() is slightly tidied up, thanks to more capable
pgdat_balanced(), it's become obvious that pgdat_balanced() is called to
check the status, then break the loop if pgdat is balanced, just to be
immediately called again.  The second call is completely unnecessary, of
course.

The patch introduces pgdat_is_balanced boolean, which helps resolve the
above suboptimal behavior, with the added benefit of slightly better
documenting one other place in the function where we jump and skip lots
of code.
Signed-off-by: default avatarZlatko Calusic <zlatko.calusic@iskon.hr>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Hugh Dickins <hughd@google.com>
Cc: Minchan Kim <minchan.kim@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7103f16d
...@@ -2616,6 +2616,7 @@ static bool prepare_kswapd_sleep(pg_data_t *pgdat, int order, long remaining, ...@@ -2616,6 +2616,7 @@ static bool prepare_kswapd_sleep(pg_data_t *pgdat, int order, long remaining,
static unsigned long balance_pgdat(pg_data_t *pgdat, int order, static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
int *classzone_idx) int *classzone_idx)
{ {
bool pgdat_is_balanced = false;
struct zone *unbalanced_zone; struct zone *unbalanced_zone;
int i; int i;
int end_zone = 0; /* Inclusive. 0 = ZONE_DMA */ int end_zone = 0; /* Inclusive. 0 = ZONE_DMA */
...@@ -2690,8 +2691,11 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order, ...@@ -2690,8 +2691,11 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
zone_clear_flag(zone, ZONE_CONGESTED); zone_clear_flag(zone, ZONE_CONGESTED);
} }
} }
if (i < 0)
if (i < 0) {
pgdat_is_balanced = true;
goto out; goto out;
}
for (i = 0; i <= end_zone; i++) { for (i = 0; i <= end_zone; i++) {
struct zone *zone = pgdat->node_zones + i; struct zone *zone = pgdat->node_zones + i;
...@@ -2818,8 +2822,11 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order, ...@@ -2818,8 +2822,11 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
pfmemalloc_watermark_ok(pgdat)) pfmemalloc_watermark_ok(pgdat))
wake_up(&pgdat->pfmemalloc_wait); wake_up(&pgdat->pfmemalloc_wait);
if (pgdat_balanced(pgdat, order, *classzone_idx)) if (pgdat_balanced(pgdat, order, *classzone_idx)) {
pgdat_is_balanced = true;
break; /* kswapd: all done */ break; /* kswapd: all done */
}
/* /*
* OK, kswapd is getting into trouble. Take a nap, then take * OK, kswapd is getting into trouble. Take a nap, then take
* another pass across the zones. * another pass across the zones.
...@@ -2840,9 +2847,9 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order, ...@@ -2840,9 +2847,9 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
if (sc.nr_reclaimed >= SWAP_CLUSTER_MAX) if (sc.nr_reclaimed >= SWAP_CLUSTER_MAX)
break; break;
} while (--sc.priority >= 0); } while (--sc.priority >= 0);
out:
if (!pgdat_balanced(pgdat, order, *classzone_idx)) { out:
if (!pgdat_is_balanced) {
cond_resched(); cond_resched();
try_to_freeze(); try_to_freeze();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment