linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: move oom_kill sysctls to their own file
@ 2022-02-15  3:02 sujiaxun
  2022-02-15  7:29 ` Luis Chamberlain
  0 siblings, 1 reply; 4+ messages in thread
From: sujiaxun @ 2022-02-15  3:02 UTC (permalink / raw)
  To: mcgrof
  Cc: keescook, yzaikin, akpm, linux-kernel, linux-fsdevel, linux-mm, sujiaxun

kernel/sysctl.c is a kitchen sink where everyone leaves their dirty
dishes, this makes it very difficult to maintain.

To help with this maintenance let's start by moving sysctls to places
where they actually belong.  The proc sysctl maintainers do not want to
know what sysctl knobs you wish to add for your own piece of code, we just
care about the core logic.

So move the oom_kill sysctls to its own file.

Signed-off-by: sujiaxun <sujiaxun@uniontech.com>
---
 include/linux/oom.h |  4 ----
 kernel/sysctl.c     | 23 -----------------------
 mm/oom_kill.c       | 37 ++++++++++++++++++++++++++++++++++---
 3 files changed, 34 insertions(+), 30 deletions(-)

diff --git a/include/linux/oom.h b/include/linux/oom.h
index 2db9a1432511..02d1e7bbd8cd 100644
--- a/include/linux/oom.h
+++ b/include/linux/oom.h
@@ -123,8 +123,4 @@ extern void oom_killer_enable(void);

 extern struct task_struct *find_lock_task_mm(struct task_struct *p);

-/* sysctls */
-extern int sysctl_oom_dump_tasks;
-extern int sysctl_oom_kill_allocating_task;
-extern int sysctl_panic_on_oom;
 #endif /* _INCLUDE_LINUX_OOM_H */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 788b9a34d5ab..40d822fbb6d5 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2352,29 +2352,6 @@ static struct ctl_table vm_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_TWO,
 	},
-	{
-		.procname	= "panic_on_oom",
-		.data		= &sysctl_panic_on_oom,
-		.maxlen		= sizeof(sysctl_panic_on_oom),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_TWO,
-	},
-	{
-		.procname	= "oom_kill_allocating_task",
-		.data		= &sysctl_oom_kill_allocating_task,
-		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec,
-	},
-	{
-		.procname	= "oom_dump_tasks",
-		.data		= &sysctl_oom_dump_tasks,
-		.maxlen		= sizeof(sysctl_oom_dump_tasks),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec,
-	},
 	{
 		.procname	= "overcommit_ratio",
 		.data		= &sysctl_overcommit_ratio,
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 6b875acabd1e..c720c0710911 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -52,9 +52,35 @@
 #define CREATE_TRACE_POINTS
 #include <trace/events/oom.h>

-int sysctl_panic_on_oom;
-int sysctl_oom_kill_allocating_task;
-int sysctl_oom_dump_tasks = 1;
+static int sysctl_panic_on_oom;
+static int sysctl_oom_kill_allocating_task;
+static int sysctl_oom_dump_tasks = 1;
+
+static struct ctl_table vm_oom_kill_table[] = {
+	{
+		.procname	= "panic_on_oom",
+		.data		= &sysctl_panic_on_oom,
+		.maxlen		= sizeof(sysctl_panic_on_oom),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_TWO,
+	},
+	{
+		.procname	= "oom_kill_allocating_task",
+		.data		= &sysctl_oom_kill_allocating_task,
+		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+	{
+		.procname	= "oom_dump_tasks",
+		.data		= &sysctl_oom_dump_tasks,
+		.maxlen		= sizeof(sysctl_oom_dump_tasks),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	}
+};

 /*
  * Serializes oom killer invocations (out_of_memory()) from all contexts to
@@ -680,6 +706,11 @@ static void wake_oom_reaper(struct task_struct *tsk)
 static int __init oom_init(void)
 {
 	oom_reaper_th = kthread_run(oom_reaper, NULL, "oom_reaper");
+
+	#ifdef CONFIG_SYSCTL
+		register_sysctl_init("vm", vm_oom_kill_table);
+	#endif
+
 	return 0;
 }
 subsys_initcall(oom_init)
--
2.20.1




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

* Re: [PATCH] mm: move oom_kill sysctls to their own file
  2022-02-15  3:02 [PATCH] mm: move oom_kill sysctls to their own file sujiaxun
@ 2022-02-15  7:29 ` Luis Chamberlain
       [not found]   ` <b86e23bf-1b90-6e31-66d9-10f9785ff8ed@uniontech.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Luis Chamberlain @ 2022-02-15  7:29 UTC (permalink / raw)
  To: sujiaxun; +Cc: keescook, yzaikin, akpm, linux-kernel, linux-fsdevel, linux-mm

On Tue, Feb 15, 2022 at 11:02:57AM +0800, sujiaxun wrote:
> kernel/sysctl.c is a kitchen sink where everyone leaves their dirty
> dishes, this makes it very difficult to maintain.
> 
> To help with this maintenance let's start by moving sysctls to places
> where they actually belong.  The proc sysctl maintainers do not want to
> know what sysctl knobs you wish to add for your own piece of code, we just
> care about the core logic.
> 
> So move the oom_kill sysctls to its own file.
> 
> Signed-off-by: sujiaxun <sujiaxun@uniontech.com>
> ---
>  include/linux/oom.h |  4 ----
>  kernel/sysctl.c     | 23 -----------------------
>  mm/oom_kill.c       | 37 ++++++++++++++++++++++++++++++++++---
>  3 files changed, 34 insertions(+), 30 deletions(-)
> 
> diff --git a/include/linux/oom.h b/include/linux/oom.h
> index 2db9a1432511..02d1e7bbd8cd 100644
> --- a/include/linux/oom.h
> +++ b/include/linux/oom.h
> @@ -123,8 +123,4 @@ extern void oom_killer_enable(void);
> 
>  extern struct task_struct *find_lock_task_mm(struct task_struct *p);
> 
> -/* sysctls */
> -extern int sysctl_oom_dump_tasks;
> -extern int sysctl_oom_kill_allocating_task;
> -extern int sysctl_panic_on_oom;
>  #endif /* _INCLUDE_LINUX_OOM_H */
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 788b9a34d5ab..40d822fbb6d5 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -2352,29 +2352,6 @@ static struct ctl_table vm_table[] = {
>  		.extra1		= SYSCTL_ZERO,
>  		.extra2		= SYSCTL_TWO,
>  	},
> -	{
> -		.procname	= "panic_on_oom",
> -		.data		= &sysctl_panic_on_oom,
> -		.maxlen		= sizeof(sysctl_panic_on_oom),
> -		.mode		= 0644,
> -		.proc_handler	= proc_dointvec_minmax,
> -		.extra1		= SYSCTL_ZERO,
> -		.extra2		= SYSCTL_TWO,
> -	},
> -	{
> -		.procname	= "oom_kill_allocating_task",
> -		.data		= &sysctl_oom_kill_allocating_task,
> -		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
> -		.mode		= 0644,
> -		.proc_handler	= proc_dointvec,
> -	},
> -	{
> -		.procname	= "oom_dump_tasks",
> -		.data		= &sysctl_oom_dump_tasks,
> -		.maxlen		= sizeof(sysctl_oom_dump_tasks),
> -		.mode		= 0644,
> -		.proc_handler	= proc_dointvec,
> -	},
>  	{
>  		.procname	= "overcommit_ratio",
>  		.data		= &sysctl_overcommit_ratio,
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index 6b875acabd1e..c720c0710911 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -52,9 +52,35 @@
>  #define CREATE_TRACE_POINTS
>  #include <trace/events/oom.h>
> 
> -int sysctl_panic_on_oom;
> -int sysctl_oom_kill_allocating_task;
> -int sysctl_oom_dump_tasks = 1;
> +static int sysctl_panic_on_oom;
> +static int sysctl_oom_kill_allocating_task;
> +static int sysctl_oom_dump_tasks = 1;
> +
> +static struct ctl_table vm_oom_kill_table[] = {
> +	{
> +		.procname	= "panic_on_oom",
> +		.data		= &sysctl_panic_on_oom,
> +		.maxlen		= sizeof(sysctl_panic_on_oom),
> +		.mode		= 0644,
> +		.proc_handler	= proc_dointvec_minmax,
> +		.extra1		= SYSCTL_ZERO,
> +		.extra2		= SYSCTL_TWO,
> +	},
> +	{
> +		.procname	= "oom_kill_allocating_task",
> +		.data		= &sysctl_oom_kill_allocating_task,
> +		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
> +		.mode		= 0644,
> +		.proc_handler	= proc_dointvec,
> +	},
> +	{
> +		.procname	= "oom_dump_tasks",
> +		.data		= &sysctl_oom_dump_tasks,
> +		.maxlen		= sizeof(sysctl_oom_dump_tasks),
> +		.mode		= 0644,
> +		.proc_handler	= proc_dointvec,
> +	}
> +};
> 
>  /*
>   * Serializes oom killer invocations (out_of_memory()) from all contexts to
> @@ -680,6 +706,11 @@ static void wake_oom_reaper(struct task_struct *tsk)
>  static int __init oom_init(void)
>  {
>  	oom_reaper_th = kthread_run(oom_reaper, NULL, "oom_reaper");
> +
> +	#ifdef CONFIG_SYSCTL
> +		register_sysctl_init("vm", vm_oom_kill_table);
> +	#endif

PLease avoid the ifdefs and the tab spacing seems very off here.

Also are you running ./scripts/get_maintainer* ?

  Luis

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

* Re: [PATCH] mm: move oom_kill sysctls to their own file
       [not found]   ` <b86e23bf-1b90-6e31-66d9-10f9785ff8ed@uniontech.com>
@ 2022-02-15  8:00     ` Luis Chamberlain
       [not found]       ` <7058b3c2-5c22-f163-1f1a-3906d9b7e047@uniontech.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Luis Chamberlain @ 2022-02-15  8:00 UTC (permalink / raw)
  To: 苏家训
  Cc: keescook, yzaikin, akpm, linux-kernel, linux-fsdevel, linux-mm

On Tue, Feb 15, 2022 at 03:56:10PM +0800, 苏家训 wrote:
> I checked the patch using ./scripts/checkpatch.pl and found no errors.

./scripts/get_maintainer.pl, not checkpatch.

  Luis
>  

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

* Re: [PATCH] mm: move oom_kill sysctls to their own file
       [not found]       ` <7058b3c2-5c22-f163-1f1a-3906d9b7e047@uniontech.com>
@ 2022-02-15  8:36         ` Luis Chamberlain
  0 siblings, 0 replies; 4+ messages in thread
From: Luis Chamberlain @ 2022-02-15  8:36 UTC (permalink / raw)
  To: 苏家训
  Cc: keescook, yzaikin, akpm, linux-kernel, linux-fsdevel, linux-mm

On Tue, Feb 15, 2022 at 04:23:48PM +0800, 苏家训 wrote:
> 
> 
> 在 2022/2/15 16:00, Luis Chamberlain 写道:
> > On Tue, Feb 15, 2022 at 03:56:10PM +0800, 苏家训 wrote:
> > > I checked the patch using ./scripts/checkpatch.pl and found no errors.
> > 
> > ./scripts/get_maintainer.pl, not checkpatch.
> > 
> >    Luis
> > 
> I checked the patch using ./scripts/get_maintainer.pl. Is there something
> wrong with my sending?
> src/linux-next$ ./scripts/get_maintainer.pl
> 0001-mm-move-oom_kill-sysctls-to-their-own-file.patch
> Luis Chamberlain <mcgrof@kernel.org> (maintainer: PROC SYSCTL)
> Kees Cook <keescook@chromium.org> (maintainer:PROC SYSCTL)
> Iurii Zaikin <yzaikin@google.com> (maintainer:PROC SYSCTL)
> Andrew Morton <akpm@linux-foundation.org> (maintainer:MEMORY MANAGEMENT)
> linux-kernel@vger.kernel.org (open list)
> linux-fsdevel@vger.kernel.org (open list: PROC SYSCTL)
> linux-mm@kvack.org (open list:MEMORY MANAGEMENT)

Looks good, sorry for the noise.

  Luis


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

end of thread, other threads:[~2022-02-15  8:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15  3:02 [PATCH] mm: move oom_kill sysctls to their own file sujiaxun
2022-02-15  7:29 ` Luis Chamberlain
     [not found]   ` <b86e23bf-1b90-6e31-66d9-10f9785ff8ed@uniontech.com>
2022-02-15  8:00     ` Luis Chamberlain
     [not found]       ` <7058b3c2-5c22-f163-1f1a-3906d9b7e047@uniontech.com>
2022-02-15  8:36         ` 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).