Skip to contentSkip to conversation

mm: compaction: move compaction sysctl to its own file

PATCH Superseded [email protected] 2 participants 2 messages Mar 21, 2023

Subsystems (4)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 mm: compaction: move compaction sysctl to its own file

From: Minghao Chi <[email protected]>

This moves all compaction sysctls to its own file.

---
 include/linux/compaction.h |  7 ----
 kernel/sysctl.c            | 58 -------------------------------
 mm/compaction.c            | 70 ++++++++++++++++++++++++++++++++++----
 3 files changed, 64 insertions(+), 71 deletions(-)
include/linux/compaction.h +0 -7
index 52a9ff65faee..a6e512cfb670 100644
@@ -81,13 +81,6 @@ static inline unsigned long compact_gap(unsigned int order)
 }
 
 #ifdef CONFIG_COMPACTION
-extern unsigned int sysctl_compaction_proactiveness;
-extern int sysctl_compaction_handler(struct ctl_table *table, int write,
-			void *buffer, size_t *length, loff_t *ppos);
-extern int compaction_proactiveness_sysctl_handler(struct ctl_table *table,
-		int write, void *buffer, size_t *length, loff_t *ppos);
-extern int sysctl_extfrag_threshold;
-extern int sysctl_compact_unevictable_allowed;
 
 extern unsigned int extfrag_for_order(struct zone *zone, unsigned int order);
 extern int fragmentation_index(struct zone *zone, unsigned int order);
kernel/sysctl.c +0 -58

70 lines not on this page · raw message

mm/compaction.c +64 -6

119 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw

kernel/sysctl.c

Quoted 35 lines · On 3/21/23 08:11, [email protected] wrote:

From: Minghao Chi <[email protected]>

This moves all compaction sysctls to its own file.

---
 include/linux/compaction.h |  7 ----
 kernel/sysctl.c            | 58 -------------------------------
 mm/compaction.c            | 70 ++++++++++++++++++++++++++++++++++----
 3 files changed, 64 insertions(+), 71 deletions(-)
include/linux/compaction.h +0 -7
index 52a9ff65faee..a6e512cfb670 100644
@@ -81,13 +81,6 @@ static inline unsigned long compact_gap(unsigned int order)
 }
 
 #ifdef CONFIG_COMPACTION
-extern unsigned int sysctl_compaction_proactiveness;
-extern int sysctl_compaction_handler(struct ctl_table *table, int write,
-			void *buffer, size_t *length, loff_t *ppos);
-extern int compaction_proactiveness_sysctl_handler(struct ctl_table *table,
-		int write, void *buffer, size_t *length, loff_t *ppos);
-extern int sysctl_extfrag_threshold;
-extern int sysctl_compact_unevictable_allowed;
 
 extern unsigned int extfrag_for_order(struct zone *zone, unsigned int order);
 extern int fragmentation_index(struct zone *zone, unsigned int order);
kernel/sysctl.c +0 -0
index ce0297acf97c..49a405447c77 100644

You should be able to remove the #include <linux/compaction.h> in this file now?

Quoted 77 lines
kernel/sysctl.c +0 -58
@@ -746,27 +746,6 @@ int proc_dointvec(struct ctl_table *table, int write, void *buffer,
 	return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
 }
 
-#ifdef CONFIG_COMPACTION
-static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
-		int write, void *buffer, size_t *lenp, loff_t *ppos)
-{
-	int ret, old;
-
-	if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
-		return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
-
-	old = *(int *)table->data;
-	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
-	if (ret)
-		return ret;
-	if (old != *(int *)table->data)
-		pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
-			     table->procname, current->comm,
-			     task_pid_nr(current));
-	return ret;
-}
-#endif
-
 /**
  * proc_douintvec - read a vector of unsigned integers
  * @table: the sysctl table
@@ -2157,43 +2136,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_FOUR,
 	},
-#ifdef CONFIG_COMPACTION
-	{
-		.procname	= "compact_memory",
-		.data		= NULL,
-		.maxlen		= sizeof(int),
-		.mode		= 0200,
-		.proc_handler	= sysctl_compaction_handler,
-	},
-	{
-		.procname	= "compaction_proactiveness",
-		.data		= &sysctl_compaction_proactiveness,
-		.maxlen		= sizeof(sysctl_compaction_proactiveness),
-		.mode		= 0644,
-		.proc_handler	= compaction_proactiveness_sysctl_handler,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE_HUNDRED,
-	},
-	{
-		.procname	= "extfrag_threshold",
-		.data		= &sysctl_extfrag_threshold,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE_THOUSAND,
-	},
-	{
-		.procname	= "compact_unevictable_allowed",
-		.data		= &sysctl_compact_unevictable_allowed,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax_warn_RT_change,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
-	},
-
-#endif /* CONFIG_COMPACTION */
 	{
 		.procname	= "min_free_kbytes",
 		.data		= &min_free_kbytes,
mm/compaction.c +0 -0
index e689d66cedf4..f56b3dc4563b 100644

mm/compaction.c typedef enum { · line 1731

Quoted 5 lines
mm/compaction.c +1 -1
@@ -1728,7 +1728,7 @@ typedef enum {
  * Allow userspace to control policy on scanning the unevictable LRU for
  * compactable pages.
  */
-int sysctl_compact_unevictable_allowed __read_mostly = CONFIG_COMPACT_UNEVICTABLE_DEFAULT;
+static int sysctl_compact_unevictable_allowed __read_mostly = CONFIG_COMPACT_UNEVICTABLE_DEFAULT;

I would move all the sysctl_ variables scattered later in the file to a single place here.

mm/compaction.c static unsigned int fragmentation_score_node(pg_data_t *pgdat) · line 2055

Quoted 8 lines
mm/compaction.c +1 -1
 static inline void
 update_fast_start_pfn(struct compact_control *cc, unsigned long pfn)
@@ -2052,7 +2052,7 @@ static unsigned int fragmentation_score_node(pg_data_t *pgdat)
 
 	return score;
 }
-
+unsigned int sysctl_compaction_proactiveness;

e.g. this

mm/compaction.c static enum compact_result __compaction_suitable(struct zone *zone, int order, · line 2231

Quoted 9 lines
mm/compaction.c +1 -1
 static unsigned int fragmentation_score_wmark(pg_data_t *pgdat, bool low)
 {
 	unsigned int wmark_low;
@@ -2228,7 +2228,7 @@ static enum compact_result __compaction_suitable(struct zone *zone, int order,
 
 	return COMPACT_CONTINUE;
 }
-
+static int sysctl_extfrag_threshold = 500;

and this.

mm/compaction.c static enum compact_result compact_zone_order(struct zone *zone, int order, · line 2587

Quoted 9 lines
mm/compaction.c +0 -1
 /*
  * compaction_suitable: Is this suitable to run compaction on this zone now?
  * Returns
@@ -2584,7 +2584,6 @@ static enum compact_result compact_zone_order(struct zone *zone, int order,
 	return ret;
 }
 
-int sysctl_extfrag_threshold = 500;
 

Remove newline so that's a single one.

mm/compaction.c static void compact_nodes(void) · line 2749

Quoted 5 lines
mm/compaction.c +0 -0
 /**
  * try_to_compact_pages - Direct compact to satisfy a high-order allocation
@@ -2749,7 +2748,7 @@ static void compact_nodes(void)
  */
 unsigned int __read_mostly sysctl_compaction_proactiveness = 20;

Also move this one, and can be also static now?

Quoted 15 lines
mm/compaction.c +2 -2
-int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
+static int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
 		void *buffer, size_t *length, loff_t *ppos)
 {
 	int rc, nid;
@@ -2779,7 +2778,7 @@ int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
  * This is the entry point for compacting all nodes via
  * /proc/sys/vm/compact_memory
  */
-int sysctl_compaction_handler(struct ctl_table *table, int write,
+static int sysctl_compaction_handler(struct ctl_table *table, int write,
 			void *buffer, size_t *length, loff_t *ppos)
 {
 	if (write)

mm/compaction.c static int kcompactd_cpu_online(unsigned int cpu) · line 3075

Quoted 3 lines
mm/compaction.c +0 -0
@@ -3074,7 +3073,63 @@ static int kcompactd_cpu_online(unsigned int cpu)
 	}
 	return 0;
 }

Please add newline here

Quoted 8 lines
mm/compaction.c +7 -0
+static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
+		int write, void *buffer, size_t *lenp, loff_t *ppos)
+{
+	int ret, old;
 
+	if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
+		return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
+

mm/compaction.c static int kcompactd_cpu_online(unsigned int cpu) · line 3093

Quoted 10 lines
mm/compaction.c +10 -0
+	old = *(int *)table->data;
+	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
+	if (ret)
+		return ret;
+	if (old != *(int *)table->data)
+		pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
+			     table->procname, current->comm,
+			     task_pid_nr(current));
+	return ret;
+}

Newline.

Quoted 29 lines
mm/compaction.c +29 -0
+#ifdef CONFIG_SYSCTL
+static struct ctl_table vm_compaction[] = {
+	{
+		.procname	= "compact_memory",
+		.data		= NULL,
+		.maxlen		= sizeof(int),
+		.mode		= 0200,
+		.proc_handler	= sysctl_compaction_handler,
+	},
+	{
+		.procname	= "compaction_proactiveness",
+		.data		= &sysctl_compaction_proactiveness,
+		.maxlen		= sizeof(sysctl_compaction_proactiveness),
+		.mode		= 0644,
+		.proc_handler	= compaction_proactiveness_sysctl_handler,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE_HUNDRED,
+	},
+	{
+		.procname	= "extfrag_threshold",
+		.data		= &sysctl_extfrag_threshold,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE_THOUSAND,
+	},
+	{
+		.procname	= "compact_unevictable_allowed",

mm/compaction.c static int kcompactd_cpu_online(unsigned int cpu) · line 3132

Quoted 10 lines
mm/compaction.c +10 -0
+		.data		= &sysctl_compact_unevictable_allowed,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax_warn_RT_change,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
+	{ }
+};
+#endif

Newline.

mm/compaction.c static int __init kcompactd_init(void) · line 3153

Quoted 13 lines
mm/compaction.c +3 -0
 static int __init kcompactd_init(void)
 {
 	int nid;
@@ -3090,6 +3145,9 @@ static int __init kcompactd_init(void)
 
 	for_each_node_state(nid, N_MEMORY)
 		kcompactd_run(nid);
+#ifdef CONFIG_SYSCTL
+	register_sysctl_init("vm", vm_compaction);
+#endif
 	return 0;
 }
 subsys_initcall(kcompactd_init)

Thanks!