Commit a94b5252 authored by Yafang Shao's avatar Yafang Shao Committed by Linus Torvalds

mm/compaction.c: clear total_{migrate,free}_scanned before scanning a new zone

total_{migrate,free}_scanned will be added to COMPACTMIGRATE_SCANNED and
COMPACTFREE_SCANNED in compact_zone().  We should clear them before
scanning a new zone.  In the proc triggered compaction, we forgot clearing
them.

[laoar.shao@gmail.com: introduce a helper compact_zone_counters_init()]
  Link: http://lkml.kernel.org/r/1563869295-25748-1-git-send-email-laoar.shao@gmail.com
[akpm@linux-foundation.org: expand compact_zone_counters_init() into its single callsite, per mhocko]
[vbabka@suse.cz: squash compact_zone() list_head init as well]
  Link: http://lkml.kernel.org/r/1fb6f7da-f776-9e42-22f8-bbb79b030b98@suse.cz
[akpm@linux-foundation.org: kcompactd_do_work(): avoid unnecessary initialization of cc.zone]
Link: http://lkml.kernel.org/r/1563789275-9639-1-git-send-email-laoar.shao@gmail.com
Fixes: 7f354a54 ("mm, compaction: add vmstats for kcompactd work")
Signed-off-by: default avatarYafang Shao <laoar.shao@gmail.com>
Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
Reviewed-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: David Rientjes <rientjes@google.com>
Cc: Yafang Shao <shaoyafang@didiglobal.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Michal Hocko <mhocko@suse.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 63398413
...@@ -2078,6 +2078,17 @@ compact_zone(struct compact_control *cc, struct capture_control *capc) ...@@ -2078,6 +2078,17 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
const bool sync = cc->mode != MIGRATE_ASYNC; const bool sync = cc->mode != MIGRATE_ASYNC;
bool update_cached; bool update_cached;
/*
* These counters track activities during zone compaction. Initialize
* them before compacting a new zone.
*/
cc->total_migrate_scanned = 0;
cc->total_free_scanned = 0;
cc->nr_migratepages = 0;
cc->nr_freepages = 0;
INIT_LIST_HEAD(&cc->freepages);
INIT_LIST_HEAD(&cc->migratepages);
cc->migratetype = gfpflags_to_migratetype(cc->gfp_mask); cc->migratetype = gfpflags_to_migratetype(cc->gfp_mask);
ret = compaction_suitable(cc->zone, cc->order, cc->alloc_flags, ret = compaction_suitable(cc->zone, cc->order, cc->alloc_flags,
cc->classzone_idx); cc->classzone_idx);
...@@ -2281,10 +2292,6 @@ static enum compact_result compact_zone_order(struct zone *zone, int order, ...@@ -2281,10 +2292,6 @@ static enum compact_result compact_zone_order(struct zone *zone, int order,
{ {
enum compact_result ret; enum compact_result ret;
struct compact_control cc = { struct compact_control cc = {
.nr_freepages = 0,
.nr_migratepages = 0,
.total_migrate_scanned = 0,
.total_free_scanned = 0,
.order = order, .order = order,
.search_order = order, .search_order = order,
.gfp_mask = gfp_mask, .gfp_mask = gfp_mask,
...@@ -2305,8 +2312,6 @@ static enum compact_result compact_zone_order(struct zone *zone, int order, ...@@ -2305,8 +2312,6 @@ static enum compact_result compact_zone_order(struct zone *zone, int order,
if (capture) if (capture)
current->capture_control = &capc; current->capture_control = &capc;
INIT_LIST_HEAD(&cc.freepages);
INIT_LIST_HEAD(&cc.migratepages);
ret = compact_zone(&cc, &capc); ret = compact_zone(&cc, &capc);
...@@ -2408,8 +2413,6 @@ static void compact_node(int nid) ...@@ -2408,8 +2413,6 @@ static void compact_node(int nid)
struct zone *zone; struct zone *zone;
struct compact_control cc = { struct compact_control cc = {
.order = -1, .order = -1,
.total_migrate_scanned = 0,
.total_free_scanned = 0,
.mode = MIGRATE_SYNC, .mode = MIGRATE_SYNC,
.ignore_skip_hint = true, .ignore_skip_hint = true,
.whole_zone = true, .whole_zone = true,
...@@ -2423,11 +2426,7 @@ static void compact_node(int nid) ...@@ -2423,11 +2426,7 @@ static void compact_node(int nid)
if (!populated_zone(zone)) if (!populated_zone(zone))
continue; continue;
cc.nr_freepages = 0;
cc.nr_migratepages = 0;
cc.zone = zone; cc.zone = zone;
INIT_LIST_HEAD(&cc.freepages);
INIT_LIST_HEAD(&cc.migratepages);
compact_zone(&cc, NULL); compact_zone(&cc, NULL);
...@@ -2529,8 +2528,6 @@ static void kcompactd_do_work(pg_data_t *pgdat) ...@@ -2529,8 +2528,6 @@ static void kcompactd_do_work(pg_data_t *pgdat)
struct compact_control cc = { struct compact_control cc = {
.order = pgdat->kcompactd_max_order, .order = pgdat->kcompactd_max_order,
.search_order = pgdat->kcompactd_max_order, .search_order = pgdat->kcompactd_max_order,
.total_migrate_scanned = 0,
.total_free_scanned = 0,
.classzone_idx = pgdat->kcompactd_classzone_idx, .classzone_idx = pgdat->kcompactd_classzone_idx,
.mode = MIGRATE_SYNC_LIGHT, .mode = MIGRATE_SYNC_LIGHT,
.ignore_skip_hint = false, .ignore_skip_hint = false,
...@@ -2554,16 +2551,10 @@ static void kcompactd_do_work(pg_data_t *pgdat) ...@@ -2554,16 +2551,10 @@ static void kcompactd_do_work(pg_data_t *pgdat)
COMPACT_CONTINUE) COMPACT_CONTINUE)
continue; continue;
cc.nr_freepages = 0;
cc.nr_migratepages = 0;
cc.total_migrate_scanned = 0;
cc.total_free_scanned = 0;
cc.zone = zone;
INIT_LIST_HEAD(&cc.freepages);
INIT_LIST_HEAD(&cc.migratepages);
if (kthread_should_stop()) if (kthread_should_stop())
return; return;
cc.zone = zone;
status = compact_zone(&cc, NULL); status = compact_zone(&cc, NULL);
if (status == COMPACT_SUCCESS) { if (status == COMPACT_SUCCESS) {
......
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