Skip to contentSkip to conversation

mm: compaction: Limit the value of interface compact_memory

PATCH In review [email protected] 3 participants 5 messages Mar 6, 2023 – Mar 8, 2023

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

PATCH v2 2/2 mm: compaction: Limit the value of interface compact_memory

From: Minghao Chi <[email protected]>

Available only when CONFIG_COMPACTION is set. When 1 is written to the file, all zones are compacted such that free memory is available in contiguous blocks where possible.
But echo others-parameter > compact_memory, this function will be triggered by writing parameters to the interface.

Applied this patch,
sh/$ echo 1.1 > /proc/sys/vm/compact_memory
sh/$ sh: write error: Invalid argument
The start and end time of printing triggering compact_memory.

---
 mm/compaction.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
mm/compaction.c +11 -1
index 5a9501e0ae01..2c9ecc4b9d23 100644
@@ -2763,6 +2763,8 @@ int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
 	return 0;
 }
 
+/* The written value is actually unused, all memory is compacted */
+int sysctl_compact_memory;
 /*
  * This is the entry point for compacting all nodes via
  * /proc/sys/vm/compact_memory
@@ -2770,8 +2772,16 @@ int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
 int sysctl_compaction_handler(struct ctl_table *table, int write,
 			void *buffer, size_t *length, loff_t *ppos)
 {
-	if (write)
+	int ret;
+
+	ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
+	if (ret)
+		return ret;
+	if (write) {
+		pr_info("compact_nodes start\n");
 		compact_nodes();
+		pr_info("compact_nodes end\n");
+	}
 
 	return 0;
 }
Signature · 1 line
2.25.1
#1 lore raw
Quoted 37 lines · On 3/6/23 07:05, [email protected] wrote:

From: Minghao Chi <[email protected]>

Available only when CONFIG_COMPACTION is set. When 1 is written to the file, all zones are compacted such that free memory is available in contiguous blocks where possible.
But echo others-parameter > compact_memory, this function will be triggered by writing parameters to the interface.

Applied this patch,
sh/$ echo 1.1 > /proc/sys/vm/compact_memory
sh/$ sh: write error: Invalid argument
The start and end time of printing triggering compact_memory.

---
 mm/compaction.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
mm/compaction.c +2 -0
index 5a9501e0ae01..2c9ecc4b9d23 100644
@@ -2763,6 +2763,8 @@ int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
 	return 0;
 }
 
+/* The written value is actually unused, all memory is compacted */
+int sysctl_compact_memory;
 /*
  * This is the entry point for compacting all nodes via
  * /proc/sys/vm/compact_memory
@@ -2770,8 +2772,16 @@ int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
 int sysctl_compaction_handler(struct ctl_table *table, int write,
 			void *buffer, size_t *length, loff_t *ppos)
 {

mm/compaction.c int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write, · line 2783

Quoted 10 lines
mm/compaction.c +8 -1
-	if (write)
+	int ret;
+
+	ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
+	if (ret)
+		return ret;
+	if (write) {
+		pr_info("compact_nodes start\n");
 		compact_nodes();
+		pr_info("compact_nodes end\n");

I'm not sure we want to start spamming the dmesg. This would make sense if we wanted to deprecate the sysctl and start hunting for remaining callers to be fixed. Otherwise ftrace can be used to capture e.g. the time.

Quoted 4 lines
mm/compaction.c +1 -0
+	}
 
 	return 0;
 }
#2 lore raw
Quoted 46 lines · Vlastimil Babka
Quoted 43 lines · On 3/6/23 07:05, [email protected] wrote:

From: Minghao Chi <[email protected]>

Available only when CONFIG_COMPACTION is set. When 1 is written to the file, all zones are compacted such that free memory is available in contiguous blocks where possible.
But echo others-parameter > compact_memory, this function will be triggered by writing parameters to the interface.

Applied this patch,
sh/$ echo 1.1 > /proc/sys/vm/compact_memory
sh/$ sh: write error: Invalid argument
The start and end time of printing triggering compact_memory.

---
 mm/compaction.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
mm/compaction.c +7 -1
index 5a9501e0ae01..2c9ecc4b9d23 100644
@@ -2763,6 +2763,8 @@ int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
 	return 0;
 }
 
+/* The written value is actually unused, all memory is compacted */
+int sysctl_compact_memory;
 /*
  * This is the entry point for compacting all nodes via
  * /proc/sys/vm/compact_memory
@@ -2770,8 +2772,16 @@ int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
 int sysctl_compaction_handler(struct ctl_table *table, int write,
 			void *buffer, size_t *length, loff_t *ppos)
 {
-	if (write)
+	int ret;
+
+	ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
+	if (ret)
+		return ret;
Quoted 8 lines

mm/compaction.c int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write, · line 2783

Quoted 4 lines
mm/compaction.c +3 -0
+	if (write) {
+		pr_info("compact_nodes start\n");
 		compact_nodes();
+		pr_info("compact_nodes end\n");

I'm not sure we want to start spamming the dmesg. This would make sense if we wanted to deprecate the sysctl and start hunting for remaining callers to be fixed. Otherwise ftrace can be used to capture e.g. the time.

Without that print, I don't think a custom proc handler is needed too, right? So what would simplify the code.

Luis

#3 lore raw
Quoted 17 lines · Luis Chamberlain
Quoted 7 lines · Vlastimil Babka
Quoted 7 lines

{

mm/compaction.c +5 -1
-	if (write)
+	int ret;
+
+	ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
+	if (ret)
+		return ret;
Quoted 8 lines

mm/compaction.c int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write, · line 2783

Quoted 4 lines
mm/compaction.c +3 -0
+	if (write) {
+		pr_info("compact_nodes start\n");
 		compact_nodes();
+		pr_info("compact_nodes end\n");

I'm not sure we want to start spamming the dmesg. This would make sense if we wanted to deprecate the sysctl and start hunting for remaining callers to be fixed. Otherwise ftrace can be used to capture e.g. the time.

Quoted 2 lines

Without that print, I don't think a custom proc handler is needed too, right? So what would simplify the code.

But we'd still call compact_nodes(), so that's not possible without a custom handler, no?

Quoted 1 line

Luis

#4 lore raw
Quoted 18 lines · Vlastimil Babka
Quoted 17 lines · Luis Chamberlain
Quoted 15 lines · Vlastimil Babka

mm/compaction.c int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write, · line 2783

Quoted 11 lines

{

mm/compaction.c +8 -1
-	if (write)
+	int ret;
+
+	ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
+	if (ret)
+		return ret;
+	if (write) {
+		pr_info("compact_nodes start\n");
 		compact_nodes();
+		pr_info("compact_nodes end\n");

I'm not sure we want to start spamming the dmesg. This would make sense if we wanted to deprecate the sysctl and start hunting for remaining callers to be fixed. Otherwise ftrace can be used to capture e.g. the time.

Quoted 5 lines
Quoted 2 lines

Without that print, I don't think a custom proc handler is needed too, right? So what would simplify the code.

But we'd still call compact_nodes(), so that's not possible without a custom handler, no?

Ah right. It does beg the question if that form is common, so to define one. But that's just extra work not needed now.

Luis