diff options
| author | Mike Galbraith <efault@gmx.de> | 2010-11-30 08:18:03 -0500 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2010-11-30 10:03:35 -0500 |
| commit | 5091faa449ee0b7d73bc296a93bca9540fc51d0a (patch) | |
| tree | 55f5e96e189af65c85c769fce48627b8a5abb86b | |
| parent | 822bc180a7f7a7bc5fcaaea195f41b487cc8cae8 (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>
| -rw-r--r-- | Documentation/kernel-parameters.txt | 2 | ||||
| -rw-r--r-- | fs/proc/base.c | 79 | ||||
| -rw-r--r-- | include/linux/sched.h | 23 | ||||
| -rw-r--r-- | init/Kconfig | 13 | ||||
| -rw-r--r-- | kernel/fork.c | 5 | ||||
| -rw-r--r-- | kernel/sched.c | 13 | ||||
| -rw-r--r-- | kernel/sched_autogroup.c | 229 | ||||
| -rw-r--r-- | kernel/sched_autogroup.h | 32 | ||||
| -rw-r--r-- | kernel/sched_debug.c | 47 | ||||
| -rw-r--r-- | kernel/sys.c | 4 | ||||
| -rw-r--r-- | kernel/sysctl.c | 11 |
11 files changed, 409 insertions, 49 deletions
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 92e83e53148f..86820a727b0b 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt | |||
| @@ -1622,6 +1622,8 @@ and is between 256 and 4096 characters. It is defined in the file | |||
| 1622 | noapic [SMP,APIC] Tells the kernel to not make use of any | 1622 | noapic [SMP,APIC] Tells the kernel to not make use of any |
| 1623 | IOAPICs that may be present in the system. | 1623 | IOAPICs that may be present in the system. |
| 1624 | 1624 | ||
| 1625 | noautogroup Disable scheduler automatic task group creation. | ||
| 1626 | |||
| 1625 | nobats [PPC] Do not use BATs for mapping kernel lowmem | 1627 | nobats [PPC] Do not use BATs for mapping kernel lowmem |
| 1626 | on "Classic" PPC cores. | 1628 | on "Classic" PPC cores. |
| 1627 | 1629 | ||
diff --git a/fs/proc/base.c b/fs/proc/base.c index f3d02ca461ec..2fa0ce29b6dc 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
| @@ -1407,6 +1407,82 @@ static const struct file_operations proc_pid_sched_operations = { | |||
| 1407 | 1407 | ||
| 1408 | #endif | 1408 | #endif |
| 1409 | 1409 | ||
| 1410 | #ifdef CONFIG_SCHED_AUTOGROUP | ||
| 1411 | /* | ||
| 1412 | * Print out autogroup related information: | ||
| 1413 | */ | ||
| 1414 | static int sched_autogroup_show(struct seq_file *m, void *v) | ||
| 1415 | { | ||
| 1416 | struct inode *inode = m->private; | ||
| 1417 | struct task_struct *p; | ||
| 1418 | |||
| 1419 | p = get_proc_task(inode); | ||
| 1420 | if (!p) | ||
| 1421 | return -ESRCH; | ||
| 1422 | proc_sched_autogroup_show_task(p, m); | ||
| 1423 | |||
| 1424 | put_task_struct(p); | ||
| 1425 | |||
| 1426 | return 0; | ||
| 1427 | } | ||
| 1428 | |||
| 1429 | static ssize_t | ||
| 1430 | sched_autogroup_write(struct file *file, const char __user *buf, | ||
| 1431 | size_t count, loff_t *offset) | ||
| 1432 | { | ||
| 1433 | struct inode *inode = file->f_path.dentry->d_inode; | ||
| 1434 | struct task_struct *p; | ||
| 1435 | char buffer[PROC_NUMBUF]; | ||
| 1436 | long nice; | ||
| 1437 | int err; | ||
| 1438 | |||
| 1439 | memset(buffer, 0, sizeof(buffer)); | ||
| 1440 | if (count > sizeof(buffer) - 1) | ||
| 1441 | count = sizeof(buffer) - 1; | ||
| 1442 | if (copy_from_user(buffer, buf, count)) | ||
| 1443 | return -EFAULT; | ||
| 1444 | |||
| 1445 | err = strict_strtol(strstrip(buffer), 0, &nice); | ||
| 1446 | if (err) | ||
| 1447 | return -EINVAL; | ||
| 1448 | |||
| 1449 | p = get_proc_task(inode); | ||
| 1450 | if (!p) | ||
| 1451 | return -ESRCH; | ||
| 1452 | |||
| 1453 | err = nice; | ||
| 1454 | err = proc_sched_autogroup_set_nice(p, &err); | ||
| 1455 | if (err) | ||
| 1456 | count = err; | ||
| 1457 | |||
| 1458 | put_task_struct(p); | ||
| 1459 | |||
| 1460 | return count; | ||
| 1461 | } | ||
| 1462 | |||
| 1463 | static int sched_autogroup_open(struct inode *inode, struct file *filp) | ||
| 1464 | { | ||
| 1465 | int ret; | ||
| 1466 | |||
| 1467 | ret = single_open(filp, sched_autogroup_show, NULL); | ||
| 1468 | if (!ret) { | ||
| 1469 | struct seq_file *m = filp->private_data; | ||
| 1470 | |||
| 1471 | m->private = inode; | ||
| 1472 | } | ||
| 1473 | return ret; | ||
| 1474 | } | ||
| 1475 | |||
| 1476 | static const struct file_operations proc_pid_sched_autogroup_operations = { | ||
| 1477 | .open = sched_autogroup_open, | ||
| 1478 | .read = seq_read, | ||
| 1479 | .write = sched_autogroup_write, | ||
| 1480 | .llseek = seq_lseek, | ||
| 1481 | .release = single_release, | ||
| 1482 | }; | ||
| 1483 | |||
| 1484 | #endif /* CONFIG_SCHED_AUTOGROUP */ | ||
| 1485 | |||
| 1410 | static ssize_t comm_write(struct file *file, const char __user *buf, | 1486 | static ssize_t comm_write(struct file *file, const char __user *buf, |
| 1411 | size_t count, loff_t *offset) | 1487 | size_t count, loff_t *offset) |
| 1412 | { | 1488 | { |
| @@ -2733,6 +2809,9 @@ static const struct pid_entry tgid_base_stuff[] = { | |||
| 2733 | #ifdef CONFIG_SCHED_DEBUG | 2809 | #ifdef CONFIG_SCHED_DEBUG |
| 2734 | REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), | 2810 | REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), |
| 2735 | #endif | 2811 | #endif |
| 2812 | #ifdef CONFIG_SCHED_AUTOGROUP | ||
| 2813 | REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations), | ||
| 2814 | #endif | ||
| 2736 | REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations), | 2815 | REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations), |
| 2737 | #ifdef CONFIG_HAVE_ARCH_TRACEHOOK | 2816 | #ifdef CONFIG_HAVE_ARCH_TRACEHOOK |
| 2738 | INF("syscall", S_IRUSR, proc_pid_syscall), | 2817 | INF("syscall", S_IRUSR, proc_pid_syscall), |
diff --git a/include/linux/sched.h b/include/linux/sched.h index a5b92c70c737..9c2d46da486e 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
| @@ -509,6 +509,8 @@ struct thread_group_cputimer { | |||
| 509 | spinlock_t lock; | 509 | spinlock_t lock; |
| 510 | }; | 510 | }; |
| 511 | 511 | ||
| 512 | struct autogroup; | ||
| 513 | |||
| 512 | /* | 514 | /* |
| 513 | * NOTE! "signal_struct" does not have it's own | 515 | * NOTE! "signal_struct" does not have it's own |
| 514 | * locking, because a shared signal_struct always | 516 | * locking, because a shared signal_struct always |
| @@ -576,6 +578,9 @@ struct signal_struct { | |||
| 576 | 578 | ||
| 577 | struct tty_struct *tty; /* NULL if no tty */ | 579 | struct tty_struct *tty; /* NULL if no tty */ |
| 578 | 580 | ||
| 581 | #ifdef CONFIG_SCHED_AUTOGROUP | ||
| 582 | struct autogroup *autogroup; | ||
| 583 | #endif | ||
| 579 | /* | 584 | /* |
| 580 | * Cumulative resource counters for dead threads in the group, | 585 | * Cumulative resource counters for dead threads in the group, |
| 581 | * and for reaped dead child processes forked by this group. | 586 | * and for reaped dead child processes forked by this group. |
| @@ -1927,6 +1932,24 @@ int sched_rt_handler(struct ctl_table *table, int write, | |||
| 1927 | 1932 | ||
| 1928 | extern unsigned int sysctl_sched_compat_yield; | 1933 | extern unsigned int sysctl_sched_compat_yield; |
| 1929 | 1934 | ||
| 1935 | #ifdef CONFIG_SCHED_AUTOGROUP | ||
| 1936 | extern unsigned int sysctl_sched_autogroup_enabled; | ||
| 1937 | |||
| 1938 | extern void sched_autogroup_create_attach(struct task_struct *p); | ||
| 1939 | extern void sched_autogroup_detach(struct task_struct *p); | ||
| 1940 | extern void sched_autogroup_fork(struct signal_struct *sig); | ||
| 1941 | extern void sched_autogroup_exit(struct signal_struct *sig); | ||
| 1942 | #ifdef CONFIG_PROC_FS | ||
| 1943 | extern void proc_sched_autogroup_show_task(struct task_struct *p, struct seq_file *m); | ||
| 1944 | extern int proc_sched_autogroup_set_nice(struct task_struct *p, int *nice); | ||
| 1945 | #endif | ||
| 1946 | #else | ||
| 1947 | static inline void sched_autogroup_create_attach(struct task_struct *p) { } | ||
| 1948 | static inline void sched_autogroup_detach(struct task_struct *p) { } | ||
| 1949 | static inline void sched_autogroup_fork(struct signal_struct *sig) { } | ||
| 1950 | static inline void sched_autogroup_exit(struct signal_struct *sig) { } | ||
| 1951 | #endif | ||
| 1952 | |||
| 1930 | #ifdef CONFIG_RT_MUTEXES | 1953 | #ifdef CONFIG_RT_MUTEXES |
| 1931 | extern int rt_mutex_getprio(struct task_struct *p); | 1954 | extern int rt_mutex_getprio(struct task_struct *p); |
| 1932 | extern void rt_mutex_setprio(struct task_struct *p, int prio); | 1955 | extern void rt_mutex_setprio(struct task_struct *p, int prio); |
diff --git a/init/Kconfig b/init/Kconfig index 88c10468db46..f1bba0a1b051 100644 --- a/init/Kconfig +++ b/init/Kconfig | |||
| @@ -728,6 +728,19 @@ config NET_NS | |||
| 728 | 728 | ||
| 729 | endif # NAMESPACES | 729 | endif # NAMESPACES |
| 730 | 730 | ||
| 731 | config SCHED_AUTOGROUP | ||
| 732 | bool "Automatic process group scheduling" | ||
| 733 | select EVENTFD | ||
| 734 | select CGROUPS | ||
| 735 | select CGROUP_SCHED | ||
| 736 | select FAIR_GROUP_SCHED | ||
| 737 | help | ||
