proc: add support detach proccess's autogroup
RFC PATCH 1/1 proc: add support detach proccess's autogroup
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.
--- fs/proc/base.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
fs/proc/base.c +50 -0
@@ -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),
Signature · 1 line
2.14.1
Quoted 4 lines · Weiping Zhang
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.
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines · Weiping Zhang
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.
Quoted 5 lines
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
Quoted 15 lines · Weiping Zhang
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines · Weiping Zhang
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.
Quoted 5 lines
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.
Quoted 9 lines
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 intg_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