Skip to contentSkip to conversation

mm/compaction: fix missed direct_compaction setting for non-direct compaction

PATCH In review Yafang Shao 2 participants 5 messages Mar 29, 2019

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

PATCH 1/1 mm/compaction: fix missed direct_compaction setting for non-direct compaction

direct_compaction is not initialized for kcompactd or manually triggered compaction (via /proc or /sys).
That may cause unexpected behavior in __compact_finished(), so we should set direct_compaction to false explicitly for these compactions.

Cc Vlastimil Babka <[email protected]>
---
 mm/compaction.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/compaction.c +3 -2
index 98f99f4..ba2b711 100644
@@ -2400,13 +2400,12 @@ static void compact_node(int nid)
 		.total_free_scanned = 0,
 		.mode = MIGRATE_SYNC,
 		.ignore_skip_hint = true,
+		.direct_compaction = false,
 		.whole_zone = true,
 		.gfp_mask = GFP_KERNEL,
 	};
 
-
 	for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) {
-
 		zone = &pgdat->node_zones[zoneid];
 		if (!populated_zone(zone))
 			continue;
@@ -2522,8 +2521,10 @@ static void kcompactd_do_work(pg_data_t *pgdat)
 		.classzone_idx = pgdat->kcompactd_classzone_idx,
 		.mode = MIGRATE_SYNC_LIGHT,
 		.ignore_skip_hint = false,
+		.direct_compaction = false,
 		.gfp_mask = GFP_KERNEL,
 	};
+
 	trace_mm_compaction_kcompactd_wake(pgdat->node_id, cc.order,
 							cc.classzone_idx);
 	count_compact_event(KCOMPACTD_WAKE);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 2 lines · Yafang Shao

direct_compaction is not initialized for kcompactd or manually triggered compaction (via /proc or /sys).

It doesn't need to, this style of initialization does guarantee that any field not explicitly mentioned is initialized to 0/NULL/false... and this pattern is used all over the kernel.

Quoted 2 lines

That may cause unexpected behavior in __compact_finished(), so we should set direct_compaction to false explicitly for these compactions.

It's not necessary.

Quoted 37 lines
Cc Vlastimil Babka <[email protected]>
---
 mm/compaction.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/compaction.c +3 -2
index 98f99f4..ba2b711 100644
@@ -2400,13 +2400,12 @@ static void compact_node(int nid)
 		.total_free_scanned = 0,
 		.mode = MIGRATE_SYNC,
 		.ignore_skip_hint = true,
+		.direct_compaction = false,
 		.whole_zone = true,
 		.gfp_mask = GFP_KERNEL,
 	};
 
-
 	for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) {
-
 		zone = &pgdat->node_zones[zoneid];
 		if (!populated_zone(zone))
 			continue;
@@ -2522,8 +2521,10 @@ static void kcompactd_do_work(pg_data_t *pgdat)
 		.classzone_idx = pgdat->kcompactd_classzone_idx,
 		.mode = MIGRATE_SYNC_LIGHT,
 		.ignore_skip_hint = false,
+		.direct_compaction = false,
 		.gfp_mask = GFP_KERNEL,
 	};
+
 	trace_mm_compaction_kcompactd_wake(pgdat->node_id, cc.order,
 							cc.classzone_idx);
 	count_compact_event(KCOMPACTD_WAKE);
#2 lore raw
Quoted 9 lines · Vlastimil Babka
Quoted 2 lines · Yafang Shao

direct_compaction is not initialized for kcompactd or manually triggered compaction (via /proc or /sys).

It doesn't need to, this style of initialization does guarantee that any field not explicitly mentioned is initialized to 0/NULL/false... and this pattern is used all over the kernel.

Hmm.
You mean the gcc will set the local variable to 0 ? Are there any reference to this behavior ?

Thanks
Yafang

Quoted 43 lines
Quoted 2 lines

That may cause unexpected behavior in __compact_finished(), so we should set direct_compaction to false explicitly for these compactions.

It's not necessary.

Quoted 37 lines
Cc Vlastimil Babka <[email protected]>
---
 mm/compaction.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/compaction.c +3 -2
index 98f99f4..ba2b711 100644
@@ -2400,13 +2400,12 @@ static void compact_node(int nid)
              .total_free_scanned = 0,
              .mode = MIGRATE_SYNC,
              .ignore_skip_hint = true,
+             .direct_compaction = false,
              .whole_zone = true,
              .gfp_mask = GFP_KERNEL,
      };
 
-
      for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) {
-
              zone = &pgdat->node_zones[zoneid];
              if (!populated_zone(zone))
                      continue;
@@ -2522,8 +2521,10 @@ static void kcompactd_do_work(pg_data_t *pgdat)
              .classzone_idx = pgdat->kcompactd_classzone_idx,
              .mode = MIGRATE_SYNC_LIGHT,
              .ignore_skip_hint = false,
+             .direct_compaction = false,
              .gfp_mask = GFP_KERNEL,
      };
+
      trace_mm_compaction_kcompactd_wake(pgdat->node_id, cc.order,
                                                      cc.classzone_idx);
      count_compact_event(KCOMPACTD_WAKE);
#3 lore raw
Quoted 6 lines · Yafang Shao
Quoted 5 lines · Vlastimil Babka
Quoted 2 lines · Yafang Shao

direct_compaction is not initialized for kcompactd or manually triggered compaction (via /proc or /sys).

Quoted 7 lines
Quoted 4 lines

It doesn't need to, this style of initialization does guarantee that any field not explicitly mentioned is initialized to 0/NULL/false... and this pattern is used all over the kernel.

Hmm.
You mean the gcc will set the local variable to 0 ?

Not local variable, but fields omitted in this "designated initializers" scenario.

Quoted 1 line

Are there any reference to this behavior ?

https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

"Omitted fields are implicitly initialized the same as for objects that have static storage duration. "
and static objects are implicitly 0

#4 lore raw
Quoted 19 lines · Vlastimil Babka
Quoted 6 lines · Yafang Shao
Quoted 5 lines · Vlastimil Babka
Quoted 2 lines · Yafang Shao

direct_compaction is not initialized for kcompactd or manually triggered compaction (via /proc or /sys).

Quoted 7 lines
Quoted 4 lines

It doesn't need to, this style of initialization does guarantee that any field not explicitly mentioned is initialized to 0/NULL/false... and this pattern is used all over the kernel.

Hmm.
You mean the gcc will set the local variable to 0 ?

Not local variable, but fields omitted in this "designated initializers" scenario.

Quoted 8 lines
Quoted 1 line

Are there any reference to this behavior ?

https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

"Omitted fields are implicitly initialized the same as for objects that have static storage duration. "
and static objects are implicitly 0

Got it!
Many thanks for your help.

Thanks
Yafang