autogroup patches for mainline 2.6.37-rc4 and stable 2.6.36.1
Subsystems (6)
Greetings,
For those interested in trying out 'autogroup', please find patches for $subject attached. The 2.6.36.1 patch depends upon the (also attached) cgroup movement fixup patch already in mainline.
Bug reports welcome. I'll likely be a bit slow responding, as I have a backlog to slog through, but rest assured, they'll not go to waste.
-Mike
Subject: sched, cgroup: Fixup broken cgroup movement
From: Peter Zijlstra <[email protected]>
Date: Fri Oct 15 15:24:15 CEST 2010
--- include/linux/sched.h | 2 +- kernel/sched.c | 8 ++++---- kernel/sched_fair.c | 25 +++++++++++++++++++------ 3 files changed, 24 insertions(+), 11 deletions(-)
kernel/sched.c +4 -4
@@ -8290,12 +8290,12 @@ void sched_move_task(struct task_structif (unlikely (running)) tsk->sched_class->put_prev_task (rq, tsk); -set_task_rq (tsk,task_cpu (tsk)); -#ifdef CONFIG_FAIR_GROUP_SCHED -if (tsk->sched_class->moved_group) - tsk->sched_class->moved_group (tsk, on_rq); +if (tsk->sched_class->task_move_group) + tsk->sched_class->task_move_group (tsk, on_rq); + else#endif +set_task_rq (tsk,task_cpu (tsk));if (unlikely (running)) tsk->sched_class->set_curr_task (rq);
include/linux/sched.h +1 -1
@@ -1072,7 +1072,7 @@ struct sched_class { struct task_struct *task);#ifdef CONFIG_FAIR_GROUP_SCHED -void (*moved_group) (struct task_struct *p,int on_rq); +void (*task_move_group) (struct task_struct *p,int on_rq);#endif };
kernel/sched_fair.c +19 -6
@@ -3824,13 +3824,26 @@ static void set_curr_task_fair(struct rq }#ifdef CONFIG_FAIR_GROUP_SCHED -static void moved_group_fair (struct task_struct *p,int on_rq) +static void task_move_group_fair (struct task_struct *p,int on_rq) { -struct cfs_rq *cfs_rq =task_cfs_rq (p); - -update_curr (cfs_rq); +/* +* If the task was not on the rq at the time of this cgroup movement +* it must have been asleep, sleeping tasks keep their ->vruntime +* absolute on their old rq until wakeup (needed for the fair sleeper +* bonus in place_entity()). +* +* If it was on the rq, we've just 'preempted' it, which does convert +* ->vruntime to a relative base. +* +* Make sure both cases convert their relative position when migrating +* to another cgroup's rq. This does somewhat interfere with the +* fair sleeper stuff for the first placement, but who cares. +*/ +if (!on_rq) + p->se.vruntime -=cfs_rq_of (&p->se)->min_vruntime; +set_task_rq (p,task_cpu (p));if (!on_rq) -place_entity (cfs_rq, &p->se,1 ); + p->se.vruntime +=cfs_rq_of (&p->se)->min_vruntime; }#endif
@@ -3882,7 +3895,7 @@ static const struct sched_class fair_sch .get_rr_interval = get_rr_interval_fair, #ifdef CONFIG_FAIR_GROUP_SCHED - .moved_group = moved_group_fair, + .task_move_group = task_move_group_fair,#endif };
commit 5091faa449ee0b7d73bc296a93bca9540fc51d0a
Author: Mike Galbraith <[email protected]> Date: Tue Nov 30 14:18:03 2010 +0100
sched: Add 'autogroup' scheduling feature: automated per session task groups
A recurring complaint from CFS users is that parallel kbuild has a negative impact on desktop interactivity. This patch implements an idea from Linus, to automatically create task groups. Currently, only per session autogroups are implemented, but the patch leaves the way open for enhancement.
Implementation: each task's signal struct contains an inherited pointer to a refcounted autogroup struct containing a task group pointer, the default for all tasks pointing to the init_task_group. When a task calls setsid(), a new task group is created, the process is moved into the new task group, and a reference to the preveious task group is dropped. Child processes inherit this task group thereafter, and increase it's refcount. When the last thread of a process exits, the process's reference is dropped, such that when the last process referencing an autogroup exits, the autogroup is destroyed.
At runqueue selection time, IFF a task has no cgroup assignment, its current autogroup is used.
Autogroup bandwidth is controllable via setting it's nice level through the proc filesystem:
cat /proc/<pid>/autogroup
Displays the task's group and the group's nice level.
echo <nice level> > /proc/<pid>/autogroup
Sets the task group's shares to the weight of nice <level> task. Setting nice level is rate limited for !admin users due to the abuse risk of task group locking.
The feature is enabled from boot by default if CONFIG_SCHED_AUTOGROUP=y is selected, but can be disabled via the boot option noautogroup, and can also be turned on/off on the fly via:
echo [01] > /proc/sys/kernel/sched_autogroup_enabled
... which will automatically move tasks to/from the root task group.
LKML-Reference: <[email protected]>
--- Documentation/kernel-parameters.txt | 2 fs/proc/base.c | 79 ++++++++++++ include/linux/sched.h | 23 +++ init/Kconfig | 13 ++ kernel/fork.c | 5 kernel/sched.c | 13 +- kernel/sched_autogroup.c | 229 ++++++++++++++++++++++++++++++++++++ kernel/sched_autogroup.h | 32 +++++ kernel/sched_debug.c | 45 ------- kernel/sys.c | 4 kernel/sysctl.c | 11 + 11 files changed, 408 insertions(+), 48 deletions(-)
Documentation/kernel-parameters.txt +2 -0
@@ -1622,6 +1622,8 @@ and is between 256 and 4096 characters. noapic [SMP,APIC] Tells the kernel to not make use of any IOAPICs that may be present in the system. + noautogroup Disable scheduler automatic task group creation. + nobats [PPC] Do not use BATs for mapping kernel lowmem on "Classic" PPC cores.
fs/proc/base.c +79 -0
91 lines not on this page · raw message
include/linux/sched.h +23 -0
@@ -509,6 +509,8 @@ struct thread_group_cputimer {spinlock_t lock; }; +struct autogroup ; +/* * NOTE! "signal_struct" does not have it's own * locking, because a shared signal_struct always
@@ -576,6 +578,9 @@ struct signal_struct {struct tty_struct *tty;/* NULL if no tty */ +#ifdef CONFIG_SCHED_AUTOGROUP +struct autogroup *autogroup; +#endif /* * Cumulative resource counters for dead threads in the group, * and for reaped dead child processes forked by this group.
@@ -1931,6 +1936,24 @@ int sched_rt_handler(struct ctl_table *textern unsigned int sysctl_sched_compat_yield; +#ifdef CONFIG_SCHED_AUTOGROUP +extern unsigned int sysctl_sched_autogroup_enabled; + +extern void sched_autogroup_create_attach (struct task_struct *p); +extern void sched_autogroup_detach (struct task_struct *p); +extern void sched_autogroup_fork (struct signal_struct *sig); +extern void sched_autogroup_exit (struct signal_struct *sig); +#ifdef CONFIG_PROC_FS +extern void proc_sched_autogroup_show_task (struct task_struct *p,struct seq_file *m); +extern int proc_sched_autogroup_set_nice (struct task_struct *p,int *nice); +#endif +#else +static inline void sched_autogroup_create_attach (struct task_struct *p) { } +static inline void sched_autogroup_detach (struct task_struct *p) { } +static inline void sched_autogroup_fork (struct signal_struct *sig) { } +static inline void sched_autogroup_exit (struct signal_struct *sig) { } +#endif +#ifdef CONFIG_RT_MUTEXES extern int rt_mutex_getprio (struct task_struct *p);extern void rt_mutex_setprio (struct task_struct *p,int prio);
init/Kconfig +13 -0
@@ -741,6 +741,19 @@ config NET_NS endif # NAMESPACES +config SCHED_AUTOGROUP + bool "Automatic process group scheduling" + select EVENTFD + select CGROUPS + select CGROUP_SCHED + select FAIR_GROUP_SCHED + help + This option optimizes the scheduler for common desktop workloads by + automatically creating and populating task groups. This separation + of workloads isolates aggressive CPU burners (like build jobs) from + desktop applications. Task group autogeneration is currently based + upon task session. + config MM_OWNER bool
kernel/fork.c +4 -1
@@ -174,8 +174,10 @@ static inline void free_signal_struct(ststatic inline void put_signal_struct (struct signal_struct *sig) { -if (atomic_dec_and_test (&sig->sigcnt)) +if (atomic_dec_and_test (&sig->sigcnt)) { +sched_autogroup_exit (sig);free_signal_struct (sig); + } }void __put_task_struct (struct task_struct *tsk)
@@ -904,6 +906,7 @@ static int copy_signal(unsigned long cloposix_cpu_timers_init_group (sig);tty_audit_fork (sig); +sched_autogroup_fork (sig); sig->oom_adj = current->signal->oom_adj; sig->oom_score_adj = current->signal->oom_score_adj;
kernel/sched.c +11 -2
@@ -78,6 +78,7 @@#include "sched_cpupri.h" #include "workqueue_sched.h" +#include "sched_autogroup.h" #define CREATE_TRACE_POINTS #include <trace/events/sched.h>
@@ -268,6 +269,10 @@ struct task_group {struct task_group *parent;struct list_head siblings;struct list_head children; + +#ifdef CONFIG_SCHED_AUTOGROUP +struct autogroup *autogroup; +#endif };#define root_task_group init_task_group
@@ -605,11 +610,14 @@ static inline int cpu_of(struct rq *rq)*/ static inline struct task_group *task_group (struct task_struct *p) { +struct task_group *tg;struct cgroup_subsys_state *css; css =task_subsys_state_check (p, cpu_cgroup_subsys_id,lockdep_is_held (&task_rq (p)->lock)); - return container_of(css, struct task_group, css); + tg = container_of(css, struct task_group, css); + +return autogroup_task_group (p, tg); }/* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
@@ -2006,6 +2014,7 @@ static void sched_irq_time_avg_update(st#include "sched_idletask.c" #include "sched_fair.c" #include "sched_rt.c" +#include "sched_autogroup.c" #include "sched_stoptask.c" #ifdef CONFIG_SCHED_DEBUG # include "sched_debug.c"
@@ -7979,7 +7988,7 @@ void __init sched_init(void)#ifdef CONFIG_CGROUP_SCHED list_add (&init_task_group.list, &task_groups);INIT_LIST_HEAD (&init_task_group.children); - +autogroup_init (&init_task);#endif /* CONFIG_CGROUP_SCHED */ #if definedCONFIG_FAIR_GROUP_SCHED && definedCONFIG_SMP
kernel/sched_autogroup.c new file +229 -0
229 lines not on this page · raw message
kernel/sched_autogroup.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifdef CONFIG_SCHED_AUTOGROUP + +struct autogroup { +struct kref kref; +struct task_group *tg; +struct rw_semaphore lock; +unsigned long id; +int nice; +}; + +static inline struct task_group * +autogroup_task_group (struct task_struct *p,struct task_group *tg); + +#else /* !CONFIG_SCHED_AUTOGROUP */ + +static inline void autogroup_init (struct task_struct *init_task) { } +static inline void autogroup_free (struct task_group *tg) { } + +static inline struct task_group * +autogroup_task_group (struct task_struct *p,struct task_group *tg) +{ +return tg; +} + +#ifdef CONFIG_SCHED_DEBUG +static inline int autogroup_path (struct task_group *tg,char *buf,int buflen) +{ +return 0 ; +} +#endif + +#endif /* CONFIG_SCHED_AUTOGROUP */
kernel/sched_debug.c +1 -44
77 lines not on this page · raw message
kernel/sys.c +3 -1
@@ -1080,8 +1080,10 @@ SYSCALL_DEFINE0(setsid) err = session; out:write_unlock_irq (&tasklist_lock); -if (err >0 ) +if (err >0 ) {proc_sid_connector (group_leader); +sched_autogroup_create_attach (group_leader); + }return err; }
kernel/sysctl.c +11 -0
@@ -382,6 +382,17 @@ static struct ctl_table kern_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, +#ifdef CONFIG_SCHED_AUTOGROUP + { + .procname = "sched_autogroup_enabled", + .data = &sysctl_sched_autogroup_enabled, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec, + .extra1 = &zero, + .extra2 = &one, + }, +#endif #ifdef CONFIG_PROVE_LOCKING { .procname = "prove_locking",
commit 5091faa449ee0b7d73bc296a93bca9540fc51d0a
Author: Mike Galbraith <[email protected]> Date: Tue Nov 30 14:18:03 2010 +0100
sched: Add 'autogroup' scheduling feature: automated per session task groups
A recurring complaint from CFS users is that parallel kbuild has a negative impact on desktop interactivity. This patch implements an idea from Linus, to automatically create task groups. Currently, only per session autogroups are implemented, but the patch leaves the way open for enhancement.
Implementation: each task's signal struct contains an inherited pointer to a refcounted autogroup struct containing a task group pointer, the default for all tasks pointing to the init_task_group. When a task calls setsid(), a new task group is created, the process is moved into the new task group, and a reference to the preveious task group is dropped. Child processes inherit this task group thereafter, and increase it's refcount. When the last thread of a process exits, the process's reference is dropped, such that when the last process referencing an autogroup exits, the autogroup is destroyed.
At runqueue selection time, IFF a task has no cgroup assignment, its current autogroup is used.
Autogroup bandwidth is controllable via setting it's nice level through the proc filesystem:
cat /proc/<pid>/autogroup
Displays the task's group and the group's nice level.
echo <nice level> > /proc/<pid>/autogroup
Sets the task group's shares to the weight of nice <level> task. Setting nice level is rate limited for !admin users due to the abuse risk of task group locking.
The feature is enabled from boot by default if CONFIG_SCHED_AUTOGROUP=y is selected, but can be disabled via the boot option noautogroup, and can also be turned on/off on the fly via:
echo [01] > /proc/sys/kernel/sched_autogroup_enabled
... which will automatically move tasks to/from the root task group.
LKML-Reference: <[email protected]>
--- Documentation/kernel-parameters.txt | 2 fs/proc/base.c | 79 ++++++++++++ include/linux/sched.h | 23 +++ init/Kconfig | 13 ++ kernel/fork.c | 5 kernel/sched.c | 13 +- kernel/sched_autogroup.c | 229 ++++++++++++++++++++++++++++++++++++ kernel/sched_autogroup.h | 32 +++++ kernel/sched_debug.c | 45 ------- kernel/sys.c | 4 kernel/sysctl.c | 11 + 11 files changed, 408 insertions(+), 48 deletions(-)
Documentation/kernel-parameters.txt +2 -0
@@ -1610,6 +1610,8 @@ and is between 256 and 4096 characters. noapic [SMP,APIC] Tells the kernel to not make use of any IOAPICs that may be present in the system. + noautogroup Disable scheduler automatic task group creation. + nobats [PPC] Do not use BATs for mapping kernel lowmem on "Classic" PPC cores.
fs/proc/base.c +79 -0
91 lines not on this page · raw message
include/linux/sched.h +23 -0
@@ -506,6 +506,8 @@ struct thread_group_cputimer {spinlock_t lock; }; +struct autogroup ; +/* * NOTE! "signal_struct" does not have it's own * locking, because a shared signal_struct always
@@ -573,6 +575,9 @@ struct signal_struct {struct tty_struct *tty;/* NULL if no tty */ +#ifdef CONFIG_SCHED_AUTOGROUP +struct autogroup *autogroup; +#endif /* * Cumulative resource counters for dead threads in the group, * and for reaped dead child processes forked by this group.
@@ -1900,6 +1905,24 @@ int sched_rt_handler(struct ctl_table *textern unsigned int sysctl_sched_compat_yield; +#ifdef CONFIG_SCHED_AUTOGROUP +extern unsigned int sysctl_sched_autogroup_enabled; + +extern void sched_autogroup_create_attach (struct task_struct *p); +extern void sched_autogroup_detach (struct task_struct *p); +extern void sched_autogroup_fork (struct signal_struct *sig); +extern void sched_autogroup_exit (struct signal_struct *sig); +#ifdef CONFIG_PROC_FS +extern void proc_sched_autogroup_show_task (struct task_struct *p,struct seq_file *m); +extern int proc_sched_autogroup_set_nice (struct task_struct *p,int *nice); +#endif +#else +static inline void sched_autogroup_create_attach (struct task_struct *p) { } +static inline void sched_autogroup_detach (struct task_struct *p) { } +static inline void sched_autogroup_fork (struct signal_struct *sig) { } +static inline void sched_autogroup_exit (struct signal_struct *sig) { } +#endif +#ifdef CONFIG_RT_MUTEXES extern int rt_mutex_getprio (struct task_struct *p);extern void rt_mutex_setprio (struct task_struct *p,int prio);
init/Kconfig +13 -0
@@ -652,6 +652,19 @@ config DEBUG_BLK_CGROUP endif # CGROUPS +config SCHED_AUTOGROUP + bool "Automatic process group scheduling" + select EVENTFD + select CGROUPS + select CGROUP_SCHED + select FAIR_GROUP_SCHED + help + This option optimizes the scheduler for common desktop workloads by + automatically creating and populating task groups. This separation + of workloads isolates aggressive CPU burners (like build jobs) from + desktop applications. Task group autogeneration is currently based + upon task session. + config MM_OWNER bool
kernel/fork.c +4 -1
@@ -173,8 +173,10 @@ static inline void free_signal_struct(ststatic inline void put_signal_struct (struct signal_struct *sig) { -if (atomic_dec_and_test (&sig->sigcnt)) +if (atomic_dec_and_test (&sig->sigcnt)) { +sched_autogroup_exit (sig);free_signal_struct (sig); + } }void __put_task_struct (struct task_struct *tsk)
@@ -900,6 +902,7 @@ static int copy_signal(unsigned long cloposix_cpu_timers_init_group (sig);tty_audit_fork (sig); +sched_autogroup_fork (sig); sig->oom_adj = current->signal->oom_adj; sig->oom_score_adj = current->signal->oom_score_adj;
kernel/sched.c +11 -2
@@ -78,6 +78,7 @@#include "sched_cpupri.h" #include "workqueue_sched.h" +#include "sched_autogroup.h" #define CREATE_TRACE_POINTS #include <trace/events/sched.h>
@@ -268,6 +269,10 @@ struct task_group {struct task_group *parent;struct list_head siblings;struct list_head children; + +#ifdef CONFIG_SCHED_AUTOGROUP +struct autogroup *autogroup; +#endif };#define root_task_group init_task_group
@@ -612,11 +617,14 @@ static inline int cpu_of(struct rq *rq)*/ static inline struct task_group *task_group (struct task_struct *p) { +struct task_group *tg;struct cgroup_subsys_state *css; css =task_subsys_state_check (p, cpu_cgroup_subsys_id,lockdep_is_held (&task_rq (p)->lock)); - return container_of(css, struct task_group, css); + tg = container_of(css, struct task_group, css); + +return autogroup_task_group (p, tg); }/* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
@@ -1913,6 +1921,7 @@ static void deactivate_task(struct rq *r#include "sched_idletask.c" #include "sched_fair.c" #include "sched_rt.c" +#include "sched_autogroup.c" #ifdef CONFIG_SCHED_DEBUG # include "sched_debug.c" #endif
@@ -7742,7 +7751,7 @@ void __init sched_init(void)#ifdef CONFIG_CGROUP_SCHED list_add (&init_task_group.list, &task_groups);INIT_LIST_HEAD (&init_task_group.children); - +autogroup_init (&init_task);#endif /* CONFIG_CGROUP_SCHED */ #if definedCONFIG_FAIR_GROUP_SCHED && definedCONFIG_SMP
kernel/sched_autogroup.c new file +229 -0
229 lines not on this page · raw message
kernel/sched_autogroup.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifdef CONFIG_SCHED_AUTOGROUP + +struct autogroup { +struct kref kref; +struct task_group *tg; +struct rw_semaphore lock; +unsigned long id; +int nice; +}; + +static inline struct task_group * +autogroup_task_group (struct task_struct *p,struct task_group *tg); + +#else /* !CONFIG_SCHED_AUTOGROUP */ + +static inline void autogroup_init (struct task_struct *init_task) { } +static inline void autogroup_free (struct task_group *tg) { } + +static inline struct task_group * +autogroup_task_group (struct task_struct *p,struct task_group *tg) +{ +return tg; +} + +#ifdef CONFIG_SCHED_DEBUG +static inline int autogroup_path (struct task_group *tg,char *buf,int buflen) +{ +return 0 ; +} +#endif + +#endif /* CONFIG_SCHED_AUTOGROUP */
kernel/sched_debug.c +1 -44
77 lines not on this page · raw message
kernel/sys.c +3 -1
@@ -1080,8 +1080,10 @@ SYSCALL_DEFINE0(setsid) err = session; out:write_unlock_irq (&tasklist_lock); -if (err >0 ) +if (err >0 ) {proc_sid_connector (group_leader); +sched_autogroup_create_attach (group_leader); + }return err; }
kernel/sysctl.c +11 -0
@@ -384,6 +384,17 @@ static struct ctl_table kern_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, +#ifdef CONFIG_SCHED_AUTOGROUP + { + .procname = "sched_autogroup_enabled", + .data = &sysctl_sched_autogroup_enabled, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec, + .extra1 = &zero, + .extra2 = &one, + }, +#endif #ifdef CONFIG_PROVE_LOCKING { .procname = "prove_locking",
Quoted 8 lines · Mike Galbraith
Greetings,
For those interested in trying out 'autogroup', please find patches for $subject attached. The 2.6.36.1 patch depends upon the (also attached) cgroup movement fixup patch already in mainline.
Bug reports welcome. I'll likely be a bit slow responding, as I have a backlog to slog through, but rest assured, they'll not go to waste.
The autogroup scheduling feature is now also available via the scheduler development tree, 2.6.37-rc4 based, via:
http://people.redhat.com/mingo/tip.git/README
And the feature has been queued up for a v2.6.38 merge. Testing so far is promising
- beyond testboxes i run it on one of my main boxes as well and have noticed no troubles.
Thanks,
Ingo