Skip to content

Commit 3d92c29

Browse files
laoargregkh
authored andcommitted
mm/compaction.c: clear total_{migrate,free}_scanned before scanning a new zone
commit a94b525 upstream. 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. [[email protected]: introduce a helper compact_zone_counters_init()] Link: http://lkml.kernel.org/r/[email protected] [[email protected]: expand compact_zone_counters_init() into its single callsite, per mhocko] [[email protected]: squash compact_zone() list_head init as well] Link: http://lkml.kernel.org/r/[email protected] [[email protected]: kcompactd_do_work(): avoid unnecessary initialization of cc.zone] Link: http://lkml.kernel.org/r/[email protected] Fixes: 7f354a5 ("mm, compaction: add vmstats for kcompactd work") Signed-off-by: Yafang Shao <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Cc: David Rientjes <[email protected]> Cc: Yafang Shao <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b8ce9ad commit 3d92c29

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

mm/compaction.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,6 +2078,17 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
20782078
const bool sync = cc->mode != MIGRATE_ASYNC;
20792079
bool update_cached;
20802080

2081+
/*
2082+
* These counters track activities during zone compaction. Initialize
2083+
* them before compacting a new zone.
2084+
*/
2085+
cc->total_migrate_scanned = 0;
2086+
cc->total_free_scanned = 0;
2087+
cc->nr_migratepages = 0;
2088+
cc->nr_freepages = 0;
2089+
INIT_LIST_HEAD(&cc->freepages);
2090+
INIT_LIST_HEAD(&cc->migratepages);
2091+
20812092
cc->migratetype = gfpflags_to_migratetype(cc->gfp_mask);
20822093
ret = compaction_suitable(cc->zone, cc->order, cc->alloc_flags,
20832094
cc->classzone_idx);
@@ -2281,10 +2292,6 @@ static enum compact_result compact_zone_order(struct zone *zone, int order,
22812292
{
22822293
enum compact_result ret;
22832294
struct compact_control cc = {
2284-
.nr_freepages = 0,
2285-
.nr_migratepages = 0,
2286-
.total_migrate_scanned = 0,
2287-
.total_free_scanned = 0,
22882295
.order = order,
22892296
.search_order = order,
22902297
.gfp_mask = gfp_mask,
@@ -2305,8 +2312,6 @@ static enum compact_result compact_zone_order(struct zone *zone, int order,
23052312

23062313
if (capture)
23072314
current->capture_control = &capc;
2308-
INIT_LIST_HEAD(&cc.freepages);
2309-
INIT_LIST_HEAD(&cc.migratepages);
23102315

23112316
ret = compact_zone(&cc, &capc);
23122317

@@ -2408,8 +2413,6 @@ static void compact_node(int nid)
24082413
struct zone *zone;
24092414
struct compact_control cc = {
24102415
.order = -1,
2411-
.total_migrate_scanned = 0,
2412-
.total_free_scanned = 0,
24132416
.mode = MIGRATE_SYNC,
24142417
.ignore_skip_hint = true,
24152418
.whole_zone = true,
@@ -2423,11 +2426,7 @@ static void compact_node(int nid)
24232426
if (!populated_zone(zone))
24242427
continue;
24252428

2426-
cc.nr_freepages = 0;
2427-
cc.nr_migratepages = 0;
24282429
cc.zone = zone;
2429-
INIT_LIST_HEAD(&cc.freepages);
2430-
INIT_LIST_HEAD(&cc.migratepages);
24312430

24322431
compact_zone(&cc, NULL);
24332432

@@ -2529,8 +2528,6 @@ static void kcompactd_do_work(pg_data_t *pgdat)
25292528
struct compact_control cc = {
25302529
.order = pgdat->kcompactd_max_order,
25312530
.search_order = pgdat->kcompactd_max_order,
2532-
.total_migrate_scanned = 0,
2533-
.total_free_scanned = 0,
25342531
.classzone_idx = pgdat->kcompactd_classzone_idx,
25352532
.mode = MIGRATE_SYNC_LIGHT,
25362533
.ignore_skip_hint = false,
@@ -2554,16 +2551,10 @@ static void kcompactd_do_work(pg_data_t *pgdat)
25542551
COMPACT_CONTINUE)
25552552
continue;
25562553

2557-
cc.nr_freepages = 0;
2558-
cc.nr_migratepages = 0;
2559-
cc.total_migrate_scanned = 0;
2560-
cc.total_free_scanned = 0;
2561-
cc.zone = zone;
2562-
INIT_LIST_HEAD(&cc.freepages);
2563-
INIT_LIST_HEAD(&cc.migratepages);
2564-
25652554
if (kthread_should_stop())
25662555
return;
2556+
2557+
cc.zone = zone;
25672558
status = compact_zone(&cc, NULL);
25682559

25692560
if (status == COMPACT_SUCCESS) {

0 commit comments

Comments
 (0)