linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/drop_caches: move drop_caches sysctls into its own file
@ 2023-03-21 13:09 Yangtao Li
  2023-03-21 14:28 ` Christian Brauner
  2023-03-21 16:42 ` Matthew Wilcox
  0 siblings, 2 replies; 10+ messages in thread
From: Yangtao Li @ 2023-03-21 13:09 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Andrew Morton,
	Luis Chamberlain, Kees Cook, Iurii Zaikin
  Cc: Yangtao Li, linux-fsdevel, linux-kernel, linux-mm

This moves the fs/drop_caches.c respective sysctls to its own file.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/drop_caches.c   | 25 ++++++++++++++++++++++---
 include/linux/mm.h |  6 ------
 kernel/sysctl.c    |  9 ---------
 3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index e619c31b6bd9..3032b83ce6f2 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -12,8 +12,7 @@
 #include <linux/gfp.h>
 #include "internal.h"
 
-/* A global variable is a bit ugly, but it keeps the code simple */
-int sysctl_drop_caches;
+static int sysctl_drop_caches;
 
 static void drop_pagecache_sb(struct super_block *sb, void *unused)
 {
@@ -47,7 +46,7 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
 	iput(toput_inode);
 }
 
-int drop_caches_sysctl_handler(struct ctl_table *table, int write,
+static int drop_caches_sysctl_handler(struct ctl_table *table, int write,
 		void *buffer, size_t *length, loff_t *ppos)
 {
 	int ret;
@@ -75,3 +74,23 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write,
 	}
 	return 0;
 }
+
+static struct ctl_table drop_caches_table[] = {
+	{
+		.procname	= "drop_caches",
+		.data		= &sysctl_drop_caches,
+		.maxlen		= sizeof(int),
+		.mode		= 0200,
+		.proc_handler	= drop_caches_sysctl_handler,
+		.extra1		= SYSCTL_ONE,
+		.extra2		= SYSCTL_FOUR,
+	},
+	{}
+};
+
+static int __init drop_cache_init(void)
+{
+	register_sysctl_init("vm", drop_caches_table);
+	return 0;
+}
+fs_initcall(drop_cache_init);
diff --git a/include/linux/mm.h b/include/linux/mm.h
index ee755bb4e1c1..1a5d9e8a41b5 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3513,12 +3513,6 @@ static inline int in_gate_area(struct mm_struct *mm, unsigned long addr)
 
 extern bool process_shares_mm(struct task_struct *p, struct mm_struct *mm);
 
-#ifdef CONFIG_SYSCTL
-extern int sysctl_drop_caches;
-int drop_caches_sysctl_handler(struct ctl_table *, int, void *, size_t *,
-		loff_t *);
-#endif
-
 void drop_slab(void);
 
 #ifndef CONFIG_MMU
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index ce0297acf97c..6cbae0f7d50f 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2148,15 +2148,6 @@ static struct ctl_table vm_table[] = {
 		.mode		= 0644,
 		.proc_handler	= lowmem_reserve_ratio_sysctl_handler,
 	},
-	{
-		.procname	= "drop_caches",
-		.data		= &sysctl_drop_caches,
-		.maxlen		= sizeof(int),
-		.mode		= 0200,
-		.proc_handler	= drop_caches_sysctl_handler,
-		.extra1		= SYSCTL_ONE,
-		.extra2		= SYSCTL_FOUR,
-	},
 #ifdef CONFIG_COMPACTION
 	{
 		.procname	= "compact_memory",
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread
* Re: [PATCH] fs/drop_caches: move drop_caches sysctls into its own file
@ 2023-03-21 14:37 Alexey Dobriyan
  2023-03-21 16:42 ` Luis Chamberlain
  0 siblings, 1 reply; 10+ messages in thread
From: Alexey Dobriyan @ 2023-03-21 14:37 UTC (permalink / raw)
  To: brauner, frank.li
  Cc: mcgrof, Alexander Viro, Andrew Morton, Kees Cook, Iurii Zaikin,
	linux-fsdevel, linux-kernel, linux-mm

> > +static struct ctl_table drop_caches_table[] = {
> > +	{
> > +		.procname	= "drop_caches",
> > +		.data		= &sysctl_drop_caches,
> > +		.maxlen		= sizeof(int),
> > +		.mode		= 0200,
> > +		.proc_handler	= drop_caches_sysctl_handler,
> > +		.extra1		= SYSCTL_ONE,
> > +		.extra2		= SYSCTL_FOUR,
> > +	},
> > +	{}
> > +};
> > +
> > +static int __init drop_cache_init(void)
> > +{
> > +	register_sysctl_init("vm", drop_caches_table);
> 
> Does this belong under mm/ or fs/?
> And is it intended to be moved into a completely separate file?
> Feels abit wasteful for 20 lines of code...

It is better to keep all sysctls in one preallocated structure
for memory reasons:

	header = kzalloc(sizeof(struct ctl_table_header) +
                         sizeof(struct ctl_node)*nr_entries, GFP_KERNEL_ACCOUNT);

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

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21 13:09 [PATCH] fs/drop_caches: move drop_caches sysctls into its own file Yangtao Li
2023-03-21 14:28 ` Christian Brauner
2023-03-21 16:39   ` Luis Chamberlain
2023-03-21 17:19     ` Christian Brauner
2023-03-21 16:42 ` Matthew Wilcox
2023-03-21 16:56   ` Luis Chamberlain
2023-03-21 17:19     ` Matthew Wilcox
2023-03-21 18:10       ` Luis Chamberlain
2023-03-21 14:37 Alexey Dobriyan
2023-03-21 16:42 ` 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).