linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: compaction: limit illegal input parameters of compact_memory interface
@ 2023-03-03  0:44 ye.xingchen
  2023-03-03 22:11 ` Luis Chamberlain
  0 siblings, 1 reply; 2+ messages in thread
From: ye.xingchen @ 2023-03-03  0:44 UTC (permalink / raw)
  To: mcgrof
  Cc: keescook, yzaikin, akpm, linmiaohe, chi.minghao, linux-kernel,
	linux-fsdevel, linux-mm

From: Minghao Chi <chi.minghao@zte.com.cn>

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.

Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
Signed-off-by: Ye Xingchen <ye.xingchen@zte.com.cn>
---
 include/linux/compaction.h |  1 +
 kernel/sysctl.c            |  4 +++-
 mm/compaction.c            | 12 +++++++++++-
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/include/linux/compaction.h b/include/linux/compaction.h
index 52a9ff65faee..caa24e33eeb1 100644
--- a/include/linux/compaction.h
+++ b/include/linux/compaction.h
@@ -81,6 +81,7 @@ static inline unsigned long compact_gap(unsigned int order)
 }

 #ifdef CONFIG_COMPACTION
+extern int sysctl_compact_memory;
 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);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 1c240d2c99bc..39eff48ada08 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2192,10 +2192,12 @@ static struct ctl_table vm_table[] = {
 #ifdef CONFIG_COMPACTION
 	{
 		.procname	= "compact_memory",
-		.data		= NULL,
+		.data		= &sysctl_compact_memory,
 		.maxlen		= sizeof(int),
 		.mode		= 0200,
 		.proc_handler	= sysctl_compaction_handler,
+		.extra1		= SYSCTL_ONE,
+		.extra2		= SYSCTL_ONE,
 	},
 	{
 		.procname	= "compaction_proactiveness",
diff --git a/mm/compaction.c b/mm/compaction.c
index 5a9501e0ae01..2c9ecc4b9d23 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -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;
 }
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm: compaction: limit illegal input parameters of compact_memory interface
  2023-03-03  0:44 [PATCH] mm: compaction: limit illegal input parameters of compact_memory interface ye.xingchen
@ 2023-03-03 22:11 ` Luis Chamberlain
  0 siblings, 0 replies; 2+ messages in thread
From: Luis Chamberlain @ 2023-03-03 22:11 UTC (permalink / raw)
  To: ye.xingchen
  Cc: keescook, yzaikin, akpm, linmiaohe, chi.minghao, linux-kernel,
	linux-fsdevel, linux-mm

On Fri, Mar 03, 2023 at 08:44:41AM +0800, ye.xingchen@zte.com.cn wrote:
> From: Minghao Chi <chi.minghao@zte.com.cn>
> 
> 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.
> 
> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> Signed-off-by: Ye Xingchen <ye.xingchen@zte.com.cn>

Do a huge favor and while you're at it split this into two patches,
one which takes this out of kernel/sysctl.c and move it to
mm/compaction.c and a second one that does your change here.

Since kernel/sysctl.c is being trimmed you can base your changes on
sysctl-next [0] and I'm happy to take in there if Andrew agrees to it.

[0] https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=sysctl-next

  Luis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-03 22:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-03  0:44 [PATCH] mm: compaction: limit illegal input parameters of compact_memory interface ye.xingchen
2023-03-03 22:11 ` Luis Chamberlain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).