aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
diff options
context:
space:
mode:
authorMike Galbraith <efault@gmx.de>2010-11-30 08:18:03 -0500
committerIngo Molnar <mingo@elte.hu>2010-11-30 10:03:35 -0500
commit5091faa449ee0b7d73bc296a93bca9540fc51d0a (patch)
tree55f5e96e189af65c85c769fce48627b8a5abb86b /kernel/sched.c
parent822bc180a7f7a7bc5fcaaea195f41b487cc8cae8 (diff)
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. Signed-off-by: Mike Galbraith <efault@gmx.de> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Markus Trippelsdorf <markus@trippelsdorf.de> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Paul Turner <pjt@google.com> Cc: Oleg Nesterov <oleg@redhat.com> [ Removed the task_group_path() debug code, and fixed !EVENTFD build failure. ] Signed-off-by: Ingo Molnar <mingo@elte.hu> LKML-Reference: <1290281700.28711.9.camel@maggy.simson.net> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/sched.c')
-rw-r--r--kernel/sched.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 66ef5790d932..b646dad4a40e 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -79,6 +79,7 @@
79 79
80#include "sched_cpupri.h" 80#include "sched_cpupri.h"
81#include "workqueue_sched.h" 81#include "workqueue_sched.h"
82#include "sched_autogroup.h"
82 83
83#define CREATE_TRACE_POINTS 84#define CREATE_TRACE_POINTS
84#include <trace/events/sched.h> 85#include <trace/events/sched.h>
@@ -271,6 +272,10 @@ struct task_group {
271 struct task_group *parent; 272 struct task_group *parent;
272 struct list_head siblings; 273 struct list_head siblings;
273 struct list_head children; 274 struct list_head children;
275
276#ifdef CONFIG_SCHED_AUTOGROUP
277 struct autogroup *autogroup;
278#endif
274}; 279};
275 280
276#define root_task_group init_task_group 281#define root_task_group init_task_group
@@ -603,11 +608,14 @@ static inline int cpu_of(struct rq *rq)
603 */ 608 */
604static inline struct task_group *task_group(struct task_struct *p) 609static inline struct task_group *task_group(struct task_struct *p)
605{ 610{
611 struct task_group *tg;
606 struct cgroup_subsys_state *css; 612 struct cgroup_subsys_state *css;
607 613
608 css = task_subsys_state_check(p, cpu_cgroup_subsys_id, 614 css = task_subsys_state_check(p, cpu_cgroup_subsys_id,
609 lockdep_is_held(&task_rq(p)->lock)); 615 lockdep_is_held(&task_rq(p)->lock));
610 return container_of(css, struct task_group, css); 616 tg = container_of(css, struct task_group, css);
617
618 return autogroup_task_group(p, tg);
611} 619}
612 620
613/* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */ 621/* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
@@ -1869,6 +1877,7 @@ static void sched_irq_time_avg_update(struct rq *rq, u64 curr_irq_time) { }
1869#include "sched_idletask.c" 1877#include "sched_idletask.c"
1870#include "sched_fair.c" 1878#include "sched_fair.c"
1871#include "sched_rt.c" 1879#include "sched_rt.c"
1880#include "sched_autogroup.c"
1872#include "sched_stoptask.c" 1881#include "sched_stoptask.c"
1873#ifdef CONFIG_SCHED_DEBUG 1882#ifdef CONFIG_SCHED_DEBUG
1874# include "sched_debug.c" 1883# include "sched_debug.c"
@@ -7750,7 +7759,7 @@ void __init sched_init(void)
7750#ifdef CONFIG_CGROUP_SCHED 7759#ifdef CONFIG_CGROUP_SCHED
7751 list_add(&init_task_group.list, &task_groups); 7760 list_add(&init_task_group.list, &task_groups);
7752 INIT_LIST_HEAD(&init_task_group.children); 7761 INIT_LIST_HEAD(&init_task_group.children);
7753 7762 autogroup_init(&init_task);
7754#endif /* CONFIG_CGROUP_SCHED */ 7763#endif /* CONFIG_CGROUP_SCHED */
7755 7764
7756 for_each_possible_cpu(i) { 7765 for_each_possible_cpu(i) {