All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] proc: add support detach proccess's autogroup
@ 2020-07-02  5:20 Weiping Zhang
  2020-07-02  8:14 ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Weiping Zhang @ 2020-07-02  5:20 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman
  Cc: linux-kernel

Since setid will create a autogroup for that process, there is no
way to detach a process from that autogroup, this patch add a new interface
to detach a process from its autogroup. You can write anything to
/proc/<pid>/autogroup_detach to do that.

Signed-off-by: Weiping Zhang <zhangweiping@didiglobal.com>
---
 fs/proc/base.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index d86c0afc8a85..a210cab8b52d 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1541,6 +1541,55 @@ static const struct file_operations proc_pid_sched_autogroup_operations = {
 	.release	= single_release,
 };
 
+static int sched_autogroup_detach_show(struct seq_file *m, void *v)
+{
+	struct inode *inode = m->private;
+
+	seq_printf(m, "write any data to detach this task from a autogroup\n");
+
+	return 0;
+}
+
+static int sched_autogroup_detach_open(struct inode *inode, struct file *filp)
+{
+	int ret;
+
+	ret = single_open(filp, sched_autogroup_detach_show, NULL);
+	if (!ret) {
+		struct seq_file *m = filp->private_data;
+
+		m->private = inode;
+	}
+	return ret;
+}
+
+static ssize_t
+sched_autogroup_detach_write(struct file *file, const char __user *buf,
+	    size_t count, loff_t *offset)
+{
+	struct inode *inode = file_inode(file);
+	struct task_struct *p;
+	int ret;
+
+	p = get_proc_task(inode);
+	if (!p)
+		return -ESRCH;
+
+	sched_autogroup_detach(p);
+
+	put_task_struct(p);
+
+	return count;
+}
+
+static const struct file_operations proc_pid_sched_autogroup_detach_operations = {
+	.open		= sched_autogroup_detach_open,
+	.read		= seq_read,
+	.write		= sched_autogroup_detach_write,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
 #endif /* CONFIG_SCHED_AUTOGROUP */
 
 #ifdef CONFIG_TIME_NS
@@ -3161,6 +3210,7 @@ static const struct pid_entry tgid_base_stuff[] = {
 #endif
 #ifdef CONFIG_SCHED_AUTOGROUP
 	REG("autogroup",  S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
+	REG("autogroup_detach",  S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_detach_operations),
 #endif
 #ifdef CONFIG_TIME_NS
 	REG("timens_offsets",  S_IRUGO|S_IWUSR, proc_timens_offsets_operations),
-- 
2.14.1


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

* Re: [RFC PATCH] proc: add support detach proccess's autogroup
  2020-07-02  5:20 [RFC PATCH] proc: add support detach proccess's autogroup Weiping Zhang
@ 2020-07-02  8:14 ` Peter Zijlstra
  2020-07-02 10:21   ` Weiping Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2020-07-02  8:14 UTC (permalink / raw)
  To: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, linux-kernel

On Thu, Jul 02, 2020 at 01:20:43PM +0800, Weiping Zhang wrote:
> Since setid will create a autogroup for that process, there is no
> way to detach a process from that autogroup, this patch add a new interface
> to detach a process from its autogroup. You can write anything to
> /proc/<pid>/autogroup_detach to do that.

This is indeed what the patch does; but it fails to tell me why. Why do
we want this? Why should I care about your patch :-)

Please, always explain why you want things done, that can also help us
consider if the proposed solution is the right one.

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

* Re: [RFC PATCH] proc: add support detach proccess's autogroup
  2020-07-02  8:14 ` Peter Zijlstra
@ 2020-07-02 10:21   ` Weiping Zhang
  2020-07-07  9:34     ` Weiping Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Weiping Zhang @ 2020-07-02 10:21 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, Linux Kernel Mailing List

On Thu, Jul 2, 2020 at 4:18 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Thu, Jul 02, 2020 at 01:20:43PM +0800, Weiping Zhang wrote:
> > Since setid will create a autogroup for that process, there is no
> > way to detach a process from that autogroup, this patch add a new interface
> > to detach a process from its autogroup. You can write anything to
> > /proc/<pid>/autogroup_detach to do that.
>
> This is indeed what the patch does; but it fails to tell me why. Why do
> we want this? Why should I care about your patch :-)
>
> Please, always explain why you want things done, that can also help us
> consider if the proposed solution is the right one.

The reason is that, there are lots of autogroup created in our system, because
I forgot to disable CONFIG_SCHED_AUTOGROUP, and it leads to a hotspot
in tg_load_down (kenrel-3.10.0-514.16.1.el7.x86_64).
When user login system by ssh and launch a background job, it will create a
new autogroup even user logout ssh.
I cannot find a way do clear these unused autogroup by current kernel,
so I write a separate module to clear those unused autogroup for my system.
I think we should provide a interface to detach a process's autogroup.

Thanks

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

* Re: [RFC PATCH] proc: add support detach proccess's autogroup
  2020-07-02 10:21   ` Weiping Zhang
@ 2020-07-07  9:34     ` Weiping Zhang
  0 siblings, 0 replies; 4+ messages in thread
From: Weiping Zhang @ 2020-07-07  9:34 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: mingo, juri.lelli, Vincent Guittot, dietmar.eggemann, rostedt,
	Benjamin Segall, mgorman, Linux Kernel Mailing List

On Thu, Jul 2, 2020 at 6:21 PM Weiping Zhang <zwp10758@gmail.com> wrote:
>
> On Thu, Jul 2, 2020 at 4:18 PM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Thu, Jul 02, 2020 at 01:20:43PM +0800, Weiping Zhang wrote:
> > > Since setid will create a autogroup for that process, there is no
> > > way to detach a process from that autogroup, this patch add a new interface
> > > to detach a process from its autogroup. You can write anything to
> > > /proc/<pid>/autogroup_detach to do that.
> >
> > This is indeed what the patch does; but it fails to tell me why. Why do
> > we want this? Why should I care about your patch :-)
> >
> > Please, always explain why you want things done, that can also help us
> > consider if the proposed solution is the right one.
>
> The reason is that, there are lots of autogroup created in our system, because
> I forgot to disable CONFIG_SCHED_AUTOGROUP, and it leads to a hotspot
> in tg_load_down (kenrel-3.10.0-514.16.1.el7.x86_64).
> When user login system by ssh and launch a background job, it will create a
> new autogroup even user logout ssh.
> I cannot find a way do clear these unused autogroup by current kernel,
> so I write a separate module to clear those unused autogroup for my system.
> I think we should provide a interface to detach a process's autogroup.
>
ping

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

end of thread, other threads:[~2020-07-07  9:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-02  5:20 [RFC PATCH] proc: add support detach proccess's autogroup Weiping Zhang
2020-07-02  8:14 ` Peter Zijlstra
2020-07-02 10:21   ` Weiping Zhang
2020-07-07  9:34     ` Weiping Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.