[PATCH V3 2/2] mm: compaction: limit illegal input parameters of compact_memory interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Minghao Chi <chi.minghao@xxxxxxxxxx>

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

Link: https://lore.kernel.org/all/ZAJwoXJCzfk1WIBx@xxxxxxxxxxxxxxxxxxxxxx/
Signed-off-by: Minghao Chi <chi.minghao@xxxxxxxxxx>
Signed-off-by: Ye Xingchen <ye.xingchen@xxxxxxxxxx>
---
 mm/compaction.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index acbda28c11f4..39f4c8a6f843 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -2762,15 +2762,18 @@ int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,

 	return 0;
 }
+static int sysctl_compact_memory;

 #ifdef CONFIG_SYSCTL
 static struct ctl_table vm_compact_memory[] = {
 	{
 		.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,
 	},
 	{ }
 };
@@ -2782,6 +2785,11 @@ static struct ctl_table vm_compact_memory[] = {
 int sysctl_compaction_handler(struct ctl_table *table, int write,
 			void *buffer, size_t *length, loff_t *ppos)
 {
+	int ret;
+
+	ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
+	if (ret)
+		return ret;
 	if (write)
 		compact_nodes();

-- 
2.25.1



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux