Skip to contentSkip to conversation

sched: Add CPU rate caps

PATCH In review Peter Williams 7 participants 29 messages Jun 18, 2006 – Jun 20, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover sched: Add CPU rate caps

These patches implement CPU usage rate limits for tasks.

Although the rlimit mechanism already has a CPU usage limit (RLIMIT_CPU) it is a total usage limit and therefore (to my mind) not very useful. These patches provide an alternative whereby the (recent) average CPU usage rate of a task can be limited to a (per task) specified proportion of a single CPU's capacity. The limits are specified in parts per thousand and come in two varieties -- hard and soft. The difference between the two is that the system tries to enforce hard caps regardless of the other demand for CPU resources but allows soft caps to be exceeded if there are spare CPU resources available. By default, tasks will have both caps set to 1000 (i.e. no limit) but newly forked tasks will inherit any caps that have been imposed on their parent from the parent. The mimimim soft cap allowed is 0 (which effectively puts the task in the background) and the minimim hard cap allowed is 1.

Care has been taken to minimize the overhead inflicted on tasks that have no caps and my tests using kernbench indicate that it is hidden in the noise.

Note:

1. Caps are not enforced for SCHED_FIFO and SCHED_RR tasks.

2. This versions incorporates improvements and bug fixes as a result of feedback from an earlier post. Special thanks to Con Kolivas whose suggestions with respect to improved methods for avoiding starvation and priority inversion have enabled cap enforcement to be stricter.

3. This patch is against 2.6.17-rc6-mm2.

4. Overhead Measurements. To measure the implications for overhead introduced by these patches kernbench was used on a dual 500Mhz Centrino SMP system. Runs were done for a kernel without these patches applied, one with the patches applied but no caps being used and one with the patches applied and running kernbench with a soft cap of zero (which would be inherited by all its children).

Average Optimal -j 8 Load Run:

Vanilla Patch Applied Soft Cap 0%

Elapsed Time      1056.1   (1.92)  1048.2   (0.62)  1064.1   (1.59)
User Time         1908.1   (1.09)  1895.2   (1.30)  1926.6   (1.39)
System Time        181.7   (0.60)   177.5   (0.74)   173.8   (1.07)

Total 2089.8 2072.7 2100.4
Percent CPU 197.6 (0.55) 197.0 (0) 197.0 (0)
Context Switches 49253.6 (136.31) 48881.4 (92.03) 92490.8 (163.71)
Sleeps 28038.8 (228.11) 28136.0 (250.65) 25769.4 (280.40)

As can be seen there is no significant overhead penalty for having these patches applied and leaving them unused (in fact, based on these numbers, there's actually a small improvement). Similarly, the overhead for running kernbench as a background (soft cap of zero) job is not significant. As expected, the context switches for the background run are double (due to the fact that ANY OTHER task running on the machine would be able to preempt the kernbench tasks) but have not seriously effected the CPU usage statistics. The similarity of the "Percent CPU" numbers indicate that load balancing hasn't been adversely effected.

5. Code size measurements:

Vanilla kernel:

   text    data     bss     dec     hex filename
  33800    4689     296   38785    9781 sched.o

2554 79 0 2633 a49 mutex.o
12076 2632 0 14708 3974 base.o

Patches applied:

   text    data     bss     dec     hex filename
  36870    4721     296   41887    a39f sched.o

2630 79 0 2709 a95 mutex.o
13011 2920 0 15931 3e3b base.o

Indicating that the size cost of the patch proper is about 3 kilobytes and the procfs costs about another 1.2 kilobytes.

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#1 lore raw

PATCH 1/4 sched: Add CPU rate soft caps

This patch implements (soft) CPU rate caps per task as a proportion of a single CPU's capacity expressed in parts per thousand. The CPU usage of capped tasks is determined by using Kalman filters to calculate the (recent) average lengths of the task's scheduling cycle and the time spent on the CPU each cycle and taking the ratio of the latter to the former. To minimize overhead associated with uncapped tasks these statistics are not kept for them.

Notes:

1. To minimize the overhead incurred when testing to skip caps processing for uncapped tasks a new flag PF_HAS_CAP has been added to flags.

2. The implementation involves the addition of two priority slots to the run queue priority arrays and this means that MAX_PRIO no longer represents the scheduling priority of the idle process and can't be used to test whether priority values are in the valid range. To alleviate this problem a new function sched_idle_prio() has been provided.

3. Thanks to suggestions from Con Kolivas with respect to alternative methods to reduce the possibility of a task being starved of CPU while holding an important system resource, enforcement of caps is now quite strict. However, there will still be occasions where caps may be exceeded due to this mechanism vetoing enforcement.

4. Modified the load weight for capped tasks to be a minimum of 1 so that load balancing still works when only background tasks are running.

 include/linux/sched.h  |   18 ++
 init/Kconfig           |    2 
 kernel/Kconfig.caps    |   13 +
 kernel/mutex.c         |   33 +++
 kernel/rtmutex-debug.c |    4 
 kernel/sched.c         |  422 +++++++++++++++++++++++++++++++++++++++++++++----
 6 files changed, 459 insertions(+), 33 deletions(-)
include/linux/sched.h +18 -0
Index: MM-2.6.17-rc6-mm2/include/linux/sched.h
===================================================================
@@ -495,6 +495,12 @@ struct signal_struct {
 #define has_rt_policy(p) \
 	unlikely((p)->policy != SCHED_NORMAL && (p)->policy != SCHED_BATCH)
 
+#ifdef CONFIG_CPU_RATE_CAPS
+int sched_idle_prio(void);
+#else
+#define sched_idle_prio()	MAX_PRIO
+#endif
+
 /*
  * Some day this will be a full-fledged user tracking system..
  */
@@ -793,6 +799,11 @@ struct task_struct {
 	unsigned long sleep_avg;
 	unsigned long long timestamp, last_ran;
 	unsigned long long sched_time; /* sched_clock time spent running */
+#ifdef CONFIG_CPU_RATE_CAPS
+	unsigned long long avg_cpu_per_cycle, avg_cycle_length;
+	unsigned int cpu_rate_cap;
+	unsigned int mutexes_held;
+#endif
 	enum sleep_type sleep_type;
 
 	unsigned long policy;
@@ -1006,6 +1017,11 @@ struct task_struct {
 #endif
 };
 
+#ifdef CONFIG_CPU_RATE_CAPS
+unsigned int get_cpu_rate_cap(const struct task_struct *);
+int set_cpu_rate_cap(struct task_struct *, unsigned int);
+#endif
+
 static inline pid_t process_group(struct task_struct *tsk)
 {
 	return tsk->signal->pgrp;
@@ -1065,6 +1081,8 @@ static inline void put_task_struct(struc
 #define PF_SPREAD_SLAB	0x08000000	/* Spread some slab caches over cpuset */
 #define PF_MEMPOLICY	0x10000000	/* Non-default NUMA mempolicy */
 #define PF_MUTEX_TESTER	0x02000000	/* Thread belongs to the rt mutex tester */
+#define PF_HAS_CAP	0x20000000	/* Has a CPU rate cap */
+#define PF_UIWAKE	0x40000000	/* Just woken from uninterrptible sleep */
 
 /*
  * Only the _current_ task can read/write to tsk->flags, but other
init/Kconfig +2 -0
Index: MM-2.6.17-rc6-mm2/init/Kconfig
===================================================================
@@ -296,6 +296,8 @@ config RELAY
 
 	  If unsure, say N.
 
+source "kernel/Kconfig.caps"
+
 source "usr/Kconfig"
 
 config UID16
kernel/Kconfig.caps new file +13 -0
Index: MM-2.6.17-rc6-mm2/kernel/Kconfig.caps
===================================================================
@@ -0,0 +1,13 @@
+#
+# CPU Rate Caps Configuration
+#
+
+config CPU_RATE_CAPS
+	bool "Support (soft) CPU rate caps"
+	default y
+	---help---
+	  Say y here if you wish to be able to put a (soft) upper limit on
+	  the rate of CPU usage by individual tasks.  A task which has been
+	  allocated a soft CPU rate cap will be limited to that rate of CPU
+	  usage unless there is spare CPU resources available after the needs
+	  of uncapped tasks are met.
kernel/sched.c +393 -29

601 lines not on this page · raw message

kernel/rtmutex-debug.c +2 -2
Index: MM-2.6.17-rc6-mm2/kernel/rtmutex-debug.c
===================================================================
@@ -210,8 +210,8 @@ void debug_rt_mutex_proxy_unlock(struct 
 void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter)
 {
 	memset(waiter, 0x11, sizeof(*waiter));
-	plist_node_init(&waiter->list_entry, MAX_PRIO);
-	plist_node_init(&waiter->pi_list_entry, MAX_PRIO);
+	plist_node_init(&waiter->list_entry, sched_idle_prio());
+	plist_node_init(&waiter->pi_list_entry, sched_idle_prio());
 }
 
 void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter)
kernel/mutex.c +31 -2
Index: MM-2.6.17-rc6-mm2/kernel/mutex.c
===================================================================
@@ -51,6 +51,20 @@ __mutex_init(struct mutex *lock, const c
 
 EXPORT_SYMBOL(__mutex_init);
 
+static inline void inc_mutex_count(void)
+{
+#ifdef CONFIG_CPU_RATE_CAPS
+	current->mutexes_held++;
+#endif
+}
+
+static inline void dec_mutex_count(void)
+{
+#ifdef CONFIG_CPU_RATE_CAPS
+	current->mutexes_held--;
+#endif
+}
+
 /*
  * We split the mutex lock/unlock logic into separate fastpath and
  * slowpath functions, to reduce the register pressure on the fastpath.
@@ -89,6 +103,7 @@ void inline fastcall __sched mutex_lock(
 	 * 'unlocked' into 'locked' state.
 	 */
 	__mutex_fastpath_lock(&lock->count, __mutex_lock_slowpath);
+	inc_mutex_count();
 }
 
 EXPORT_SYMBOL(mutex_lock);
@@ -114,6 +129,7 @@ void fastcall __sched mutex_unlock(struc
 	 * into 'unlocked' state:
 	 */
 	__mutex_fastpath_unlock(&lock->count, __mutex_unlock_slowpath);
+	dec_mutex_count();
 }
 
 EXPORT_SYMBOL(mutex_unlock);
@@ -128,6 +144,7 @@ void fastcall __sched mutex_unlock_non_n
 	 * into 'unlocked' state:
 	 */
 	__mutex_fastpath_unlock(&lock->count, __mutex_unlock_non_nested_slowpath);
+	dec_mutex_count();
 }
 
 EXPORT_SYMBOL(mutex_unlock_non_nested);
@@ -300,9 +317,16 @@ __mutex_lock_interruptible_slowpath(atom
  */
 int fastcall __sched mutex_lock_interruptible(struct mutex *lock)
 {
+	int ret;
+
 	might_sleep();
-	return __mutex_fastpath_lock_retval
+	ret = __mutex_fastpath_lock_retval
 			(&lock->count, __mutex_lock_interruptible_slowpath);
+
+	if (!ret)
+		inc_mutex_count();
+
+	return ret;
 }
 
 EXPORT_SYMBOL(mutex_lock_interruptible);
@@ -357,8 +381,13 @@ static inline int __mutex_trylock_slowpa
  */
 int fastcall __sched mutex_trylock(struct mutex *lock)
 {
-	return __mutex_fastpath_trylock(&lock->count,
+	int ret = __mutex_fastpath_trylock(&lock->count,
 					__mutex_trylock_slowpath);
+
+	if (!ret)
+		inc_mutex_count();
+
+	return ret;
 }
 
 EXPORT_SYMBOL(mutex_trylock);
Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#2 lore raw

Re: [PATCH 1/4] sched: Add CPU rate soft caps

Quoted 5 lines · Peter Williams

3. Thanks to suggestions from Con Kolivas with respect to alternative methods to reduce the possibility of a task being starved of CPU while holding an important system resource, enforcement of caps is now quite strict. However, there will still be occasions where caps may be exceeded due to this mechanism vetoing enforcement.

I hate to do this to you again but the mutexes held count advice I gave was slightly off :|

Quoted 18 lines

int fastcall __sched mutex_lock_interruptible(struct mutex *lock) {

kernel/mutex.c +8 -1
+	int ret;
+
 	might_sleep();
-	return __mutex_fastpath_lock_retval
+	ret = __mutex_fastpath_lock_retval
 			(&lock->count, __mutex_lock_interruptible_slowpath);
+
+	if (!ret)
+		inc_mutex_count();
+
+	return ret;
 }
 
 EXPORT_SYMBOL(mutex_lock_interruptible);
@@ -357,8 +381,13 @@ static inline int __mutex_trylock_slowpa
  */

kernel/mutex.c static inline int __mutex_trylock_slowpa · line 390

Quoted 10 lines
kernel/mutex.c +6 -1
 int fastcall __sched mutex_trylock(struct mutex *lock)
 {
-	return __mutex_fastpath_trylock(&lock->count,
+	int ret = __mutex_fastpath_trylock(&lock->count,
 					__mutex_trylock_slowpath);
+
+	if (!ret)
+		inc_mutex_count();
+
+	return ret;

See my track-mutexes-1.patch I recently posted.

int fastcall __sched mutex_lock_interruptible(struct mutex *lock) {
+ int ret;
+
might_sleep();
- return __mutex_fastpath_lock_retval
+ ret = __mutex_fastpath_lock_retval
(&lock->count, __mutex_lock_interruptible_slowpath);
+ if (likely(!ret))
+ inc_mutex_count();
+ return ret;
}

EXPORT_SYMBOL(mutex_lock_interruptible);
@@ -308,8 +325,12 @@ static inline int __mutex_trylock_slowpa
*/
int fastcall mutex_trylock(struct mutex *lock)
{
- return __mutex_fastpath_trylock(&lock->count,
+ int ret = __mutex_fastpath_trylock(&lock->count,
__mutex_trylock_slowpath);
+
+ if (likely(ret))
+ inc_mutex_count();
+ return ret;
}

Note the if !ret in mutex_lock_interruptible vs the if ret in mutex_trylock(

I really should have given you the original debugging code that went with it, sorry.

Signature · 1 line
-ck
#3 lore raw

Re: [PATCH 1/4] sched: Add CPU rate soft caps

Quoted 68 lines · Con Kolivas
Quoted 5 lines · Peter Williams

3. Thanks to suggestions from Con Kolivas with respect to alternative methods to reduce the possibility of a task being starved of CPU while holding an important system resource, enforcement of caps is now quite strict. However, there will still be occasions where caps may be exceeded due to this mechanism vetoing enforcement.

I hate to do this to you again but the mutexes held count advice I gave was slightly off :|

Quoted 18 lines

int fastcall __sched mutex_lock_interruptible(struct mutex *lock) {

kernel/mutex.c +8 -1
+	int ret;
+
 	might_sleep();
-	return __mutex_fastpath_lock_retval
+	ret = __mutex_fastpath_lock_retval
 			(&lock->count, __mutex_lock_interruptible_slowpath);
+
+	if (!ret)
+		inc_mutex_count();
+
+	return ret;
 }
 
 EXPORT_SYMBOL(mutex_lock_interruptible);
@@ -357,8 +381,13 @@ static inline int __mutex_trylock_slowpa
  */

kernel/mutex.c static inline int __mutex_trylock_slowpa · line 390

Quoted 10 lines
kernel/mutex.c +6 -1
 int fastcall __sched mutex_trylock(struct mutex *lock)
 {
-	return __mutex_fastpath_trylock(&lock->count,
+	int ret = __mutex_fastpath_trylock(&lock->count,
 					__mutex_trylock_slowpath);
+
+	if (!ret)
+		inc_mutex_count();
+
+	return ret;

See my track-mutexes-1.patch I recently posted.

int fastcall __sched mutex_lock_interruptible(struct mutex *lock) {

kernel/mutex.c +11 -2
+	int ret;
+
 	might_sleep();
-	return __mutex_fastpath_lock_retval
+	ret = __mutex_fastpath_lock_retval
 			(&lock->count, __mutex_lock_interruptible_slowpath);
+	if (likely(!ret))
+		inc_mutex_count();
+	return ret;
 }
 
 EXPORT_SYMBOL(mutex_lock_interruptible);
@@ -308,8 +325,12 @@ static inline int __mutex_trylock_slowpa
  */
 int fastcall mutex_trylock(struct mutex *lock)
 {
-	return __mutex_fastpath_trylock(&lock->count,
+	int ret = __mutex_fastpath_trylock(&lock->count,
 					__mutex_trylock_slowpath);
+
+	if (likely(ret))
+		inc_mutex_count();
+	return ret;
 }
 

Note the if !ret in mutex_lock_interruptible vs the if ret in mutex_trylock(

Quoted 2 lines

I really should have given you the original debugging code that went with it, sorry.

That's OK. I should have read the comments above mutex_trylock() more carefully myself.

Thanks
Peter
PS Have you thought about merging these caps into staircase in lieu of SCHED_IDLEPRIO? Hard caps should be easy and soft caps not much harder. If that was available I could merge the caps patch with plugsched.

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#4 lore raw

Re: [PATCH 1/4] sched: Add CPU rate soft caps

In reply to Peter Williams

As pointed out by Con Kolivas there is an error in the mutex count part of this code and an opportunity to increase efficiency with use of the likely() macro. The attached patch addresses these issues.

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
---
 kernel/mutex.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/mutex.c +2 -2
Index: MM-2.6.17-rc6-mm2/kernel/mutex.c
===================================================================
@@ -319,7 +319,7 @@ int fastcall __sched mutex_lock_interrup
 	ret = __mutex_fastpath_lock_retval
 			(&lock->count, __mutex_lock_interruptible_slowpath);
 
-	if (!ret)
+	if (likely(!ret))
 		inc_mutex_count();
 
 	return ret;
@@ -380,7 +380,7 @@ int fastcall __sched mutex_trylock(struc
 	int ret = __mutex_fastpath_trylock(&lock->count,
 					__mutex_trylock_slowpath);
 
-	if (!ret)
+	if (likely(ret))
 		inc_mutex_count();
 
 	return ret;
#5 lore raw

PATCH 2/4 sched: Add CPU rate hard caps

In reply to Peter Williams

This patch implements hard CPU rate caps per task as a proportion of a single CPU's capacity expressed in parts per thousand.

Notes:

1. Simplified calculation of sinbin durations to eliminat need for 64 bit divide.

 include/linux/sched.h |    8 ++
 kernel/Kconfig.caps   |   14 +++-
 kernel/sched.c        |  160 +++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 172 insertions(+), 10 deletions(-)
include/linux/sched.h +8 -0
Index: MM-2.6.17-rc6-mm2/include/linux/sched.h
===================================================================
@@ -803,6 +803,10 @@ struct task_struct {
 	unsigned long long avg_cpu_per_cycle, avg_cycle_length;
 	unsigned int cpu_rate_cap;
 	unsigned int mutexes_held;
+#ifdef CONFIG_CPU_RATE_HARD_CAPS
+	unsigned int cpu_rate_hard_cap;
+	struct timer_list sinbin_timer;
+#endif
 #endif
 	enum sleep_type sleep_type;
 
@@ -1020,6 +1024,10 @@ struct task_struct {
 #ifdef CONFIG_CPU_RATE_CAPS
 unsigned int get_cpu_rate_cap(const struct task_struct *);
 int set_cpu_rate_cap(struct task_struct *, unsigned int);
+#ifdef CONFIG_CPU_RATE_HARD_CAPS
+unsigned int get_cpu_rate_hard_cap(const struct task_struct *);
+int set_cpu_rate_hard_cap(struct task_struct *, unsigned int);
+#endif
 #endif
 
 static inline pid_t process_group(struct task_struct *tsk)
kernel/Kconfig.caps +12 -2
Index: MM-2.6.17-rc6-mm2/kernel/Kconfig.caps
===================================================================
@@ -3,11 +3,21 @@
 #
 
 config CPU_RATE_CAPS
-	bool "Support (soft) CPU rate caps"
+	bool "Support CPU rate caps"
 	default y
 	---help---
-	  Say y here if you wish to be able to put a (soft) upper limit on
+	  Say y here if you wish to be able to put a soft upper limit on
 	  the rate of CPU usage by individual tasks.  A task which has been
 	  allocated a soft CPU rate cap will be limited to that rate of CPU
 	  usage unless there is spare CPU resources available after the needs
 	  of uncapped tasks are met.
+
+config CPU_RATE_HARD_CAPS
+	bool "Support CPU rate hard caps"
+	depends on CPU_RATE_CAPS
+	default n
+	---help---
+	  Say y here if you wish to be able to put a hard upper limit on
+	  the rate of CPU usage by individual tasks.  A task which has been
+	  allocated a hard CPU rate cap will be limited to that rate of CPU
+	  usage regardless of whether there is spare CPU resources available.
kernel/sched.c +152 -8

231 lines not on this page · raw message

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#6 lore raw

PATCH 3/4 sched: Add procfs interface for CPU rate soft caps

In reply to Peter Williams

This patch implements a procfs interface for soft CPU rate caps.

 fs/proc/base.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
fs/proc/base.c +59 -0
Index: MM-2.6.17-rc6-mm2/fs/proc/base.c
===================================================================
@@ -167,6 +167,9 @@ enum pid_directory_inos {
 #ifdef CONFIG_CPUSETS
 	PROC_TID_CPUSET,
 #endif
+#ifdef CONFIG_CPU_RATE_CAPS
+	PROC_TID_CPU_RATE_CAP,
+#endif
 #ifdef CONFIG_SECURITY
 	PROC_TID_ATTR,
 	PROC_TID_ATTR_CURRENT,
@@ -280,6 +283,9 @@ static struct pid_entry tid_base_stuff[]
 #ifdef CONFIG_AUDITSYSCALL
 	E(PROC_TID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
 #endif
+#ifdef CONFIG_CPU_RATE_CAPS
+	E(PROC_TID_CPU_RATE_CAP,  "cpu_rate_cap",   S_IFREG|S_IRUGO|S_IWUSR),
+#endif
 	{0,0,NULL,0}
 };
 
@@ -1037,6 +1043,54 @@ static struct file_operations proc_secco
 };
 #endif /* CONFIG_SECCOMP */
 
+#ifdef CONFIG_CPU_RATE_CAPS
+static ssize_t cpu_rate_cap_read(struct file * file, char * buf,
+			size_t count, loff_t *ppos)
+{
+	struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
+	char buffer[64];
+	size_t len;
+	unsigned int cppt = get_cpu_rate_cap(task);
+
+	if (*ppos)
+		return 0;
+	*ppos = len = sprintf(buffer, "%u\n", cppt);
+	if (copy_to_user(buf, buffer, len))
+		return -EFAULT;
+
+	return len;
+}
+
+static ssize_t cpu_rate_cap_write(struct file * file, const char * buf,
+			 size_t count, loff_t *ppos)
+{
+	struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
+	char buffer[128] = "";
+	char *endptr = NULL;
+	unsigned long hcppt;
+	int res;
+
+
+	if ((count > 63) || *ppos)
+		return -EFBIG;
+	if (copy_from_user(buffer, buf, count))
+		return -EFAULT;
+	hcppt = simple_strtoul(buffer, &endptr, 0);
+	if ((endptr == buffer) || (hcppt == ULONG_MAX))
+		return -EINVAL;
+
+	if ((res = set_cpu_rate_cap(task, hcppt)) != 0)
+		return res;
+
+	return count;
+}
+
+struct file_operations proc_cpu_rate_cap_operations = {
+	read:		cpu_rate_cap_read,
+	write:		cpu_rate_cap_write,
+};
+#endif
+
 static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
 {
 	struct inode *inode = dentry->d_inode;
@@ -1797,6 +1851,11 @@ static struct dentry *proc_pident_lookup
 			inode->i_fop = &proc_loginuid_operations;
 			break;
 #endif
+#ifdef CONFIG_CPU_RATE_CAPS
+		case PROC_TID_CPU_RATE_CAP:
+			inode->i_fop = &proc_cpu_rate_cap_operations;
+			break;
+#endif
 		default:
 			printk("procfs: impossible type (%d)",p->type);
 			iput(inode);
Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#7 lore raw

PATCH 4/4 sched: Add procfs interface for CPU rate hard caps

In reply to Peter Williams

This patch implements a procfs interface for hard CPU rate caps.

 fs/proc/base.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
fs/proc/base.c +59 -0
Index: MM-2.6.17-rc6-mm2/fs/proc/base.c
===================================================================
@@ -170,6 +170,9 @@ enum pid_directory_inos {
 #ifdef CONFIG_CPU_RATE_CAPS
 	PROC_TID_CPU_RATE_CAP,
 #endif
+#ifdef CONFIG_CPU_RATE_HARD_CAPS
+	PROC_TID_CPU_RATE_HARD_CAP,
+#endif
 #ifdef CONFIG_SECURITY
 	PROC_TID_ATTR,
 	PROC_TID_ATTR_CURRENT,
@@ -286,6 +289,9 @@ static struct pid_entry tid_base_stuff[]
 #ifdef CONFIG_CPU_RATE_CAPS
 	E(PROC_TID_CPU_RATE_CAP,  "cpu_rate_cap",   S_IFREG|S_IRUGO|S_IWUSR),
 #endif
+#ifdef CONFIG_CPU_RATE_HARD_CAPS
+	E(PROC_TID_CPU_RATE_HARD_CAP,  "cpu_rate_hard_cap",   S_IFREG|S_IRUGO|S_IWUSR),
+#endif
 	{0,0,NULL,0}
 };
 
@@ -1091,6 +1097,54 @@ struct file_operations proc_cpu_rate_cap
 };
 #endif
 
+#ifdef CONFIG_CPU_RATE_HARD_CAPS
+static ssize_t cpu_rate_hard_cap_read(struct file * file, char * buf,
+			size_t count, loff_t *ppos)
+{
+	struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
+	char buffer[64];
+	size_t len;
+	unsigned int cppt = get_cpu_rate_hard_cap(task);
+
+	if (*ppos)
+		return 0;
+	*ppos = len = sprintf(buffer, "%u\n", cppt);
+	if (copy_to_user(buf, buffer, len))
+		return -EFAULT;
+
+	return len;
+}
+
+static ssize_t cpu_rate_hard_cap_write(struct file * file, const char * buf,
+			 size_t count, loff_t *ppos)
+{
+	struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
+	char buffer[128] = "";
+	char *endptr = NULL;
+	unsigned long hcppt;
+	int res;
+
+
+	if ((count > 63) || *ppos)
+		return -EFBIG;
+	if (copy_from_user(buffer, buf, count))
+		return -EFAULT;
+	hcppt = simple_strtoul(buffer, &endptr, 0);
+	if ((endptr == buffer) || (hcppt == ULONG_MAX))
+		return -EINVAL;
+
+	if ((res = set_cpu_rate_hard_cap(task, hcppt)) != 0)
+		return res;
+
+	return count;
+}
+
+struct file_operations proc_cpu_rate_hard_cap_operations = {
+	read:		cpu_rate_hard_cap_read,
+	write:		cpu_rate_hard_cap_write,
+};
+#endif
+
 static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
 {
 	struct inode *inode = dentry->d_inode;
@@ -1856,6 +1910,11 @@ static struct dentry *proc_pident_lookup
 			inode->i_fop = &proc_cpu_rate_cap_operations;
 			break;
 #endif
+#ifdef CONFIG_CPU_RATE_HARD_CAPS
+		case PROC_TID_CPU_RATE_HARD_CAP:
+			inode->i_fop = &proc_cpu_rate_hard_cap_operations;
+			break;
+#endif
 		default:
 			printk("procfs: impossible type (%d)",p->type);
 			iput(inode);
Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#8 lore raw
In reply to Peter Williams
Quoted 1 line · On Sun, 18 Jun 2006 18:26:38 +1000 Peter Williams <[email protected]>…

These patches implement CPU usage rate limits for tasks.

Via /proc/pid/cpu_rate_cap. Important detail, that.

People are going to want to extend this to capping a *group* of tasks, with some yet-to-be-determined means of tying those tasks together. How well suited is this code to that extension?

If the task can exceed its cap without impacting any other tasks (ie: there is spare idle capacity), what happens? I trust that spare capacity gets used? (Is this termed "work conserving"?)

Quoted 11 lines

5. Code size measurements:

Vanilla kernel:

   text    data     bss     dec     hex filename
  33800    4689     296   38785    9781 sched.o

2554 79 0 2633 a49 mutex.o
12076 2632 0 14708 3974 base.o

Patches applied:

Quoted 8 lines
   text    data     bss     dec     hex filename
  36870    4721     296   41887    a39f sched.o

2630 79 0 2709 a95 mutex.o
13011 2920 0 15931 3e3b base.o

Indicating that the size cost of the patch proper is about 3 kilobytes and the procfs costs about another 1.2 kilobytes.

hm. That seems rather a lot. I guess it's not a simple thing to do.

#9 lore raw
Quoted 6 lines · Andrew Morton
Quoted 1 line · On Sun, 18 Jun 2006 18:26:38 +1000 Peter Williams <[email protected]>…

These patches implement CPU usage rate limits for tasks.

Via /proc/pid/cpu_rate_cap. Important detail, that.

Via /proc/tgid/task/pid/cpu_rate_cap actually. I.e. it's at the task level not the process level.

Also, the /proc interface is just one possible interface and the one I implemented because it was easy and useful for testing. Alternate interfaces would be easy to provide (or add).

There are exported functions to set/get caps and all the necessary checking is done there. The /proc stuff is a very thin wrapper around that.

Other options for interfaces would be RLIMIT and/or a syscall.

Quoted 4 lines

People are going to want to extend this to capping a *group* of tasks, with some yet-to-be-determined means of tying those tasks together. How well suited is this code to that extension?

Quite good. It can be used from outside the scheduler to impose caps on arbitrary groups of tasks. Were the PAGG interface available I could knock up a module to demonstrate this. When/if the "task watchers" patch is included I will try and implement a higher level mechanism using that. The general technique is to get an estimate of the "effective number" of tasks in the group (similar to load) and give each task in the group a cap which is the group's cap divided by the effective number of tasks (or the group cap whichever is smaller -- i.e. the effective number of tasks could be less than one).

Doing it inside the scheduler is also doable but would have some locking issues. The run queue lock could no longer be used to protect the data as there's no guarantee that all the tasks in the group are associated with the same queue.

Quoted 3 lines

If the task can exceed its cap without impacting any other tasks (ie: there is spare idle capacity), what happens?

That's the difference between soft and hard caps. If it's a soft cap then the task is allowed to exceed it if there's spare capacity. If it's a hard cap it's not.

Quoted 2 lines

I trust that spare capacity gets
used? (Is this termed "work conserving"?)

Soft caps, yes. Hard caps, no.

Quoted 17 lines
Quoted 17 lines

5. Code size measurements:

Vanilla kernel:

   text    data     bss     dec     hex filename
  33800    4689     296   38785    9781 sched.o

2554 79 0 2633 a49 mutex.o
12076 2632 0 14708 3974 base.o

Patches applied:

   text    data     bss     dec     hex filename
  36870    4721     296   41887    a39f sched.o

2630 79 0 2709 a95 mutex.o
13011 2920 0 15931 3e3b base.o

Quoted 5 lines
Quoted 3 lines

Indicating that the size cost of the patch proper is about 3 kilobytes and the procfs costs about another 1.2 kilobytes.

hm. That seems rather a lot. I guess it's not a simple thing to do.

I suspect that a large part of that is the functions that set the caps (i.e. the equivalents of set_user_nice()) one for soft and one for hard caps. The actual capping mechanisms are quite simple.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#10 lore raw
Quoted 7 lines · Peter Williams
Quoted 3 lines

People are going to want to extend this to capping a *group* of tasks, with some yet-to-be-determined means of tying those tasks together. How well suited is this code to that extension?

Quite good. It can be used from outside the scheduler to impose caps on arbitrary groups of tasks. Were the PAGG interface available I could knock up a module to demonstrate this. When/if the "task watchers"

For demonstration purpose, maybe you could use tsk->uid to group tasks and and see how capping at group level works out? Basically cap the per-user cpu usage.

Quoted 6 lines

patch is included I will try and implement a higher level mechanism using that. The general technique is to get an estimate of the "effective number" of tasks in the group (similar to load) and give each task in the group a cap which is the group's cap divided by the effective number of tasks (or the group cap whichever is smaller -- i.e. the effective number of tasks could be less than one).

For "effective number" do you include only runnable tasks? As and when this number changes, you would need to go and change the per-task cap of all tasks in the group. Any idea what the cost of that operation would be? Or do you intend to do it lazily to amortize some of that cost?

Quoted 4 lines

Doing it inside the scheduler is also doable but would have some locking issues. The run queue lock could no longer be used to protect the data as there's no guarantee that all the tasks in the group are associated with the same queue.

Signature · 2 lines
Regards,
vatsa
#11 lore raw
Quoted 8 lines · Srivatsa Vaddagiri
Quoted 4 lines · Peter Williams
Quoted 3 lines

People are going to want to extend this to capping a *group* of tasks, with some yet-to-be-determined means of tying those tasks together. How well suited is this code to that extension?

Quite good. It can be used from outside the scheduler to impose caps on arbitrary groups of tasks. Were the PAGG interface available I could knock up a module to demonstrate this. When/if the "task watchers"

For demonstration purpose, maybe you could use tsk->uid to group tasks and and see how capping at group level works out? Basically cap the per-user cpu usage.

I was thinking of doing the group of tasks that represent a process's threads as a first example as that will be more useful to ordinary users as well as demonstrating the technique.

Quoted 4 lines
Quoted 2 lines

patch is included I will try and implement a higher level mechanism using that. The general technique is to get an estimate of the "effective number" of tasks in the group (similar to load) and give each task in the group a cap which is the group's cap divided by the effective number of tasks (or the group cap whichever is smaller -- i.e. the effective number of tasks could be less than one).

For "effective number" do you include only runnable tasks?

It would be roughly equivalent to a smoothed smoothed estimate of the number of runnable tasks in the group.

Quoted 4 lines

As and when
this number changes, you would need to go and change the per-task cap of all tasks in the group. Any idea what the cost of that operation would be? Or do you intend to do it lazily to amortize some of that cost?

Yes. It would be some form of periodical sampling mechanism. It could be done from user space or from a module.

The costs can also be reduced by realizing that it is only necessary to do anything at all if the number of tasks in the group is greater than the group's cap. I.e. if a group has a cap of 3000 but only two tasks there is no way the group can exceed its cap so that group can be ignored.

Quoted 3 lines
Quoted 2 lines

Doing it inside the scheduler is also doable but would have some locking issues. The run queue lock could no longer be used to protect the data as there's no guarantee that all the tasks in the group are associated with the same queue.

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#12 lore raw
In reply to Peter Williams
Quoted 5 lines · Peter Williams
Quoted 3 lines · Andrew Morton

On Sun, 18 Jun 2006 18:26:38 +1000
Peter Williams <[email protected]> wrote:

Quoted 7 lines
Quoted 3 lines

People are going to want to extend this to capping a *group* of tasks, with some yet-to-be-determined means of tying those tasks together. How well suited is this code to that extension?

Quite good. It can be used from outside the scheduler to impose caps on arbitrary groups of tasks. Were the PAGG interface available I could knock up a module to demonstrate this. When/if the "task watchers" patch is included I will try and implement a higher level mechanism using that. The general technique is to get an estimate of the "effective number" of tasks in the group (similar to load) and give each task in the group a cap which is the group's cap divided by the effective number of tasks (or the group cap whichever is smaller -- i.e. the effective number of tasks could be less than one). )

There is one possible issue with this approach. Lets assume that we desire a cap of 10 for a set of two tasks. As discussed earlier, each task would get a limit of 5% if they are equally busy.

Lets call the group as G1 and the tasks as T1 and T2.

If we have another group called G2 with tasks T3, T4 and T5 and a soft cap of 90. Then each of T3, T4 and T5 would get a soft cap of 30% (assuming that they are equally busy). Now if T5 stops using its limit for a while let say its cpu utilization is 10% - how do we divide the saved 20% between T1, T2, T3 and T4.

In a group scenario, the balance 20% should be shared between T3 and T4.

Also mathematically

A group is a superset of task

It is hard to implement things for a task and make it work for groups, but if we had something for groups, we could easily adapt it to tasks by making each group equal to a task

Quoted 9 lines

Doing it inside the scheduler is also doable but would have some locking issues. The run queue lock could no longer be used to protect the data as there's no guarantee that all the tasks in the group are associated with the same queue.

Quoted 3 lines

If the task can exceed its cap without impacting any other tasks (ie: there is spare idle capacity), what happens?

That's the difference between soft and hard caps. If it's a soft cap then the task is allowed to exceed it if there's spare capacity. If it's a hard cap it's not.

By how much is the task allowed to exceed if there is spare capacity? Will the spare capacity allocation require resetting of caps to implement the new caps?

Quoted 6 lines
Quoted 2 lines

I trust that spare capacity gets
used? (Is this termed "work conserving"?)

Soft caps, yes. Hard caps, no.

Signature · 4 lines
	Cheers,
	Balbir Singh,
	Linux Technology Center,
	IBM Software Labs
#13 lore raw
Quoted 20 lines · Balbir Singh
Quoted 11 lines · Peter Williams
Quoted 6 lines · Andrew Morton

On Sun, 18 Jun 2006 18:26:38 +1000
Peter Williams <[email protected]> wrote:

People are going to want to extend this to capping a *group* of tasks, with some yet-to-be-determined means of tying those tasks together. How well suited is this code to that extension?

Quite good. It can be used from outside the scheduler to impose caps on arbitrary groups of tasks. Were the PAGG interface available I could knock up a module to demonstrate this. When/if the "task watchers" patch is included I will try and implement a higher level mechanism using that. The general technique is to get an estimate of the "effective number" of tasks in the group (similar to load) and give each task in the group a cap which is the group's cap divided by the effective number of tasks (or the group cap whichever is smaller -- i.e. the effective number of tasks could be less than one). )

There is one possible issue with this approach. Lets assume that we desire a cap of 10 for a set of two tasks. As discussed earlier, each task would get a limit of 5% if they are equally busy.

Lets call the group as G1 and the tasks as T1 and T2.

Quoted 7 lines

If we have another group called G2 with tasks T3, T4 and T5 and a soft cap of 90. Then each of T3, T4 and T5 would get a soft cap of 30% (assuming that they are equally busy). Now if T5 stops using its limit for a while let say its cpu utilization is 10% - how do we divide the saved 20% between T1, T2, T3 and T4.

In a group scenario, the balance 20% should be shared between T3 and T4.

You're mixing up the method described above with the other one we discussed where the group's cap is divided among its tasks in proportion to their demand. With the model I describe above reduced demand by any tasks in a group would be reflected in a reduced value for the "effective number of tasks" in the group with a consequent increase in the cap applied to all group members.

I think both methods will work and the main difference would be in their complexity.

Quoted 6 lines

Also mathematically

A group is a superset of task

It is hard to implement things for a task and make it work for groups,

I disagree. If the low level control is there at the task level or (if we were managing memory) the address space level then it is relatively simple (even if boring) to do arbitrary resource control for groups from the outside.

One of the key advantages of doing it from the outside is that any locking that is required at the group level is unlikely to get tangled up with the existing locking mechanisms such as the run queue lock. This is not true if group management is done on the inside e.g. in the scheduling code.

Quoted 2 lines

but if we had something for groups, we could easily adapt it to tasks by making each group equal to a task

You seem to have a flair for adding unnecessary overhead for those who won't use this functionality. :-)

Quoted 1 line
Quoted 1 line

Doing it inside the scheduler is also doable but would have some locking issues. The run queue lock could no longer be used to protect the data as there's no guarantee that all the tasks in the group are associated with the same queue.

I should have elaborated here that (conceptually) modifying this code to apply caps to groups of tasks instead of individual tasks is simple. It mainly involves moving most the data (statistics plus cap values) to a group structure and then modifying the code to update statistics for the group instead of the task and then make the decisions about whether a task should have a cap enforced (i.e. moved to one of the soft cap priorities or sin binned) based on the group statistics.

However, maintaining and accessing the group statistics will require additional locking as the run queue lock will no longer be able to protect the data as not all tasks in the group will be associated with the same CPU. Care will be needed to ensure that this new locking doesn't lead to dead locks with the run queue locks.

In addition to the extra overhead caused by these locking requirements, the code for gathering the statistics will need to be more complex also adding to the overhead. There is also the issue of increased serialization (there is already some due to load balancing) of task scheduling to be considered although, to be fair, this increased serialization will be within groups.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

If the task can exceed its cap without impacting any other tasks (ie: there is spare idle capacity), what happens?

That's the difference between soft and hard caps. If it's a soft cap then the task is allowed to exceed it if there's spare capacity. If it's a hard cap it's not.

By how much is the task allowed to exceed if there is spare capacity?

Up to the amount of spare capacity.

Quoted 2 lines

Will the spare capacity allocation require resetting of caps to implement the new caps?

No. It's part of the soft cap mechanism.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

I trust that spare capacity gets
used? (Is this termed "work conserving"?)

Soft caps, yes. Hard caps, no.

In summary, these patches are a good basis for doing capping for groups of tasks by at least two means:

1. modification to do group capping in the scheduler, or
2. implementing group capping from outside the scheduler.

I intend spending more effort looking at the second of these options than looking at the first.

Peter

Signature · 4 lines
Dr Peter Williams, Chief Scientist         <[email protected]>
Aurema Pty Limited
Level 2, 130 Elizabeth St, Sydney, NSW 2000, Australia
Tel:+61 2 9698 2322  Fax:+61 2 9699 9174 http://www.aurema.com
#14 lore raw
Quoted 30 lines · Peter Williams
Quoted 28 lines · Balbir Singh
Quoted 6 lines · Peter Williams
Quoted 3 lines · Andrew Morton

On Sun, 18 Jun 2006 18:26:38 +1000
Peter Williams <[email protected]> wrote:

Quoted 6 lines
Quoted 3 lines

People are going to want to extend this to capping a *group* of tasks, with some yet-to-be-determined means of tying those tasks together. How well suited is this code to that extension?

Quite good. It can be used from outside the scheduler to impose caps on arbitrary groups of tasks. Were the PAGG interface available I could knock up a module to demonstrate this. When/if the "task watchers" patch is included I will try and implement a higher level mechanism using that. The general technique is to get an estimate of the "effective number" of tasks in the group (similar to load) and give each task in the group a cap which is the group's cap divided by the effective number of tasks (or the group cap whichever is smaller -- i.e. the effective number of tasks could be less than one). )

There is one possible issue with this approach. Lets assume that we desire a cap of 10 for a set of two tasks. As discussed earlier, each task would get a limit of 5% if they are equally busy.

Lets call the group as G1 and the tasks as T1 and T2.

If we have another group called G2 with tasks T3, T4 and T5 and a soft cap of 90. Then each of T3, T4 and T5 would get a soft cap of 30% (assuming that they are equally busy). Now if T5 stops using its limit for a while let say its cpu utilization is 10% - how do we divide the saved 20% between T1, T2, T3 and T4.

Quoted 5 lines
Quoted 1 line

In a group scenario, the balance 20% should be shared between T3 and T4.

You're mixing up the method described above with the other one we discussed where the group's cap is divided among its tasks in proportion to their demand. With the model I describe above reduced demand by any tasks in a group would be reflected in a reduced value for the "effective number of tasks" in the group with a consequent increase in the cap applied to all group members.

Thanks for clarifying. How frequently is the reduction in effective number of tasks calculated and how frequently is the cap updated? Does it require setting the cap values of all the tasks in the group again (O(N), N is the number of tasks in the group)? Is it possible that the effective tasks is greater than the limit of the group? How do we handle this scenario?

Quoted 1 line

I think both methods will work and the main difference would be in their complexity.

An implementation or prototype when available will be interesting to play around and experiment with. I think it will help clarify if the task mechanism will indeed work for groups or may expose some limitations of the mechanism.

Quoted 4 lines
Quoted 4 lines

Also mathematically

Quoted 9 lines
Quoted 3 lines

A group is a superset of task

It is hard to implement things for a task and make it work for groups,

I disagree. If the low level control is there at the task level or (if we were managing memory) the address space level then it is relatively simple (even if boring) to do arbitrary resource control for groups from the outside.

One of the key advantages of doing it from the outside is that any locking that is required at the group level is unlikely to get tangled up with the existing locking mechanisms such as the run queue lock. This is not true if group management is done on the inside e.g. in the scheduling code.

The f-series controller from ckrm does so without changing or getting tangled with the existing locking system.

Quoted 8 lines
Quoted 3 lines

but if we had something for groups, we could easily adapt it to tasks by making each group equal to a task

You seem to have a flair for adding unnecessary overhead for those who won't use this functionality. :-)

Quoted 10 lines
Quoted 1 line
Quoted 1 line

Doing it inside the scheduler is also doable but would have some locking issues. The run queue lock could no longer be used to protect the data as there's no guarantee that all the tasks in the group are associated with the same queue.

I should have elaborated here that (conceptually) modifying this code to apply caps to groups of tasks instead of individual tasks is simple. It mainly involves moving most the data (statistics plus cap values) to a group structure and then modifying the code to update statistics for the group instead of the task and then make the decisions about whether a task should have a cap enforced (i.e. moved to one of the soft cap priorities or sin binned) based on the group statistics.

However, maintaining and accessing the group statistics will require additional locking as the run queue lock will no longer be able to protect the data as not all tasks in the group will be associated with the same CPU. Care will be needed to ensure that this new locking doesn't lead to dead locks with the run queue locks.

In addition to the extra overhead caused by these locking requirements, the code for gathering the statistics will need to be more complex also adding to the overhead. There is also the issue of increased serialization (there is already some due to load balancing) of task scheduling to be considered although, to be fair, this increased serialization will be within groups.

The f-series CPU controller does all of what you say in 403 lines (including comments and copyright). I think the biggest advantage of maintaining the group statistics in the kernel is that certain scheduling decisions can be made based on group statistics rather than task statistics, which makes the mechanism independent of the number of tasks in the group (isolates the groups from changes in number of tasks).

If we can achieve something similar with low overhead in user space, I would certainly love to see it.

Quoted 34 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

If the task can exceed its cap without impacting any other tasks (ie: there is spare idle capacity), what happens?

That's the difference between soft and hard caps. If it's a soft cap then the task is allowed to exceed it if there's spare capacity. If it's a hard cap it's not.

By how much is the task allowed to exceed if there is spare capacity?

Up to the amount of spare capacity.

Quoted 2 lines

Will the spare capacity allocation require resetting of caps to implement the new caps?

No. It's part of the soft cap mechanism.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

I trust that spare capacity gets
used? (Is this termed "work conserving"?)

Soft caps, yes. Hard caps, no.

In summary, these patches are a good basis for doing capping for groups of tasks by at least two means:

1. modification to do group capping in the scheduler, or
2. implementing group capping from outside the scheduler.

I intend spending more effort looking at the second of these options than looking at the first.

Peter

Signature · 4 lines
	Double the cheers,
	Balbir Singh,
	Linux Technology Center,
	IBM Software Labs
#15 lore raw
Quoted 31 lines · Balbir Singh
Quoted 30 lines · Peter Williams
Quoted 28 lines · Balbir Singh
Quoted 6 lines · Peter Williams
Quoted 3 lines · Andrew Morton

On Sun, 18 Jun 2006 18:26:38 +1000
Peter Williams <[email protected]> wrote:

Quoted 6 lines
Quoted 3 lines

People are going to want to extend this to capping a *group* of tasks, with some yet-to-be-determined means of tying those tasks together. How well suited is this code to that extension?

Quite good. It can be used from outside the scheduler to impose caps on arbitrary groups of tasks. Were the PAGG interface available I could knock up a module to demonstrate this. When/if the "task watchers" patch is included I will try and implement a higher level mechanism using that. The general technique is to get an estimate of the "effective number" of tasks in the group (similar to load) and give each task in the group a cap which is the group's cap divided by the effective number of tasks (or the group cap whichever is smaller -- i.e. the effective number of tasks could be less than one). )

There is one possible issue with this approach. Lets assume that we desire a cap of 10 for a set of two tasks. As discussed earlier, each task would get a limit of 5% if they are equally busy.

Lets call the group as G1 and the tasks as T1 and T2.

If we have another group called G2 with tasks T3, T4 and T5 and a soft cap of 90. Then each of T3, T4 and T5 would get a soft cap of 30% (assuming that they are equally busy). Now if T5 stops using its limit for a while let say its cpu utilization is 10% - how do we divide the saved 20% between T1, T2, T3 and T4.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

In a group scenario, the balance 20% should be shared between T3 and T4.

You're mixing up the method described above with the other one we discussed where the group's cap is divided among its tasks in proportion to their demand. With the model I describe above reduced demand by any tasks in a group would be reflected in a reduced value for the "effective number of tasks" in the group with a consequent increase in the cap applied to all group members.

Thanks for clarifying. How frequently is the reduction in effective number of tasks calculated and how frequently is the cap updated?

I'll answer that when I've done an implementation.

Quoted 3 lines

Does it require
setting the cap values of all the tasks in the group again (O(N), N is the number of tasks in the group)?

Probably but it's not on a fast path.

Quoted 2 lines

Is it possible that the effective tasks
is greater than the limit of the group?

Yes.

Quoted 1 line

How do we handle this scenario?

You've got the problem back to front. If the number of effective tasks is less than the group limit then you have the situation that needs special handling (not the other way around). I.e. if the number of effective tasks is less than the group limit then (strictly speaking) there's no need to do any capping at all as the demand is less than the limit. However, in the case where the group limit is less than one CPU (i.e. less than 1000) the recommended thing to do would be set the limit of each task in the group to the group limit.

Obviously, group limits can be greater than one CPU (i.e. 1000).

The number of CPUs on the system also needs to be taken into account for group capping as if the group cap is greater than the number of CPUs there's no way it can be exceeded and tasks in this group would not need any processing.

Quoted 7 lines
Quoted 3 lines

I think both methods will work and the main difference would be in their complexity.

An implementation or prototype when available will be interesting to play around and experiment with. I think it will help clarify if the task mechanism will indeed work for groups or may expose some limitations of the mechanism.

I'm going to start looking at the "task tracking" patches with a view to using them for an implementation. The "executive overview" for these patches indicates that they're sufficiently similar to PAGG for this purpose.

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

Also mathematically

A group is a superset of task

It is hard to implement things for a task and make it work for groups,

Quoted 7 lines
Quoted 4 lines

I disagree. If the low level control is there at the task level or (if we were managing memory) the address space level then it is relatively simple (even if boring) to do arbitrary resource control for groups from the outside.

One of the key advantages of doing it from the outside is that any locking that is required at the group level is unlikely to get tangled up with the existing locking mechanisms such as the run queue lock. This is not true if group management is done on the inside e.g. in the scheduling code.

The f-series controller from ckrm does so without changing or getting tangled with the existing locking system.

I didn't say it was impossible just in need of care.

Quoted 20 lines
Quoted 9 lines
Quoted 4 lines

but if we had something for groups, we could easily adapt it to tasks by making each group equal to a task

You seem to have a flair for adding unnecessary overhead for those who won't use this functionality. :-)

Quoted 10 lines
Quoted 1 line
Quoted 1 line

Doing it inside the scheduler is also doable but would have some locking issues. The run queue lock could no longer be used to protect the data as there's no guarantee that all the tasks in the group are associated with the same queue.

I should have elaborated here that (conceptually) modifying this code to apply caps to groups of tasks instead of individual tasks is simple. It mainly involves moving most the data (statistics plus cap values) to a group structure and then modifying the code to update statistics for the group instead of the task and then make the decisions about whether a task should have a cap enforced (i.e. moved to one of the soft cap priorities or sin binned) based on the group statistics.

However, maintaining and accessing the group statistics will require additional locking as the run queue lock will no longer be able to protect the data as not all tasks in the group will be associated with the same CPU. Care will be needed to ensure that this new locking doesn't lead to dead locks with the run queue locks.

In addition to the extra overhead caused by these locking requirements, the code for gathering the statistics will need to be more complex also adding to the overhead. There is also the issue of increased serialization (there is already some due to load balancing) of task scheduling to be considered although, to be fair, this increased serialization will be within groups.

Quoted 6 lines

The f-series CPU controller does all of what you say in 403 lines (including comments and copyright). I think the biggest advantage of maintaining the group statistics in the kernel is that certain scheduling decisions can be made based on group statistics rather than task statistics, which makes the mechanism independent of the number of tasks in the group (isolates the groups from changes in number of tasks).

Yes, that's one of its advantages. Both methods have advantages and disadvantages.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#16 lore raw
Quoted 4 lines · Peter Williams
Quoted 2 lines · Balbir Singh

Peter Williams wrote:

<snip>

Quoted 6 lines
Quoted 2 lines

Is it possible that the effective tasks
is greater than the limit of the group?

Yes.

Quoted 9 lines
Quoted 1 line

How do we handle this scenario?

You've got the problem back to front. If the number of effective tasks is less than the group limit then you have the situation that needs special handling (not the other way around). I.e. if the number of effective tasks is less than the group limit then (strictly speaking) there's no need to do any capping at all as the demand is less than the limit. However, in the case where the group limit is less than one CPU (i.e. less than 1000) the recommended thing to do would be set the limit of each task in the group to the group limit.

Obviously, group limits can be greater than one CPU (i.e. 1000).

The number of CPUs on the system also needs to be taken into account for group capping as if the group cap is greater than the number of CPUs there's no way it can be exceeded and tasks in this group would not need any processing.

What if we have a group limit of 100 (out of 1000) and 150 effective tasks in the group? How do you calculate the cap of each task?
I hope my understanding of effective tasks is correct.

<snip>

Quoted 20 lines
Quoted 9 lines
Quoted 8 lines

I should have elaborated here that (conceptually) modifying this code to apply caps to groups of tasks instead of individual tasks is simple. It mainly involves moving most the data (statistics plus cap values) to a group structure and then modifying the code to update statistics for the group instead of the task and then make the decisions about whether a task should have a cap enforced (i.e. moved to one of the soft cap priorities or sin binned) based on the group statistics.

However, maintaining and accessing the group statistics will require additional locking as the run queue lock will no longer be able to protect the data as not all tasks in the group will be associated with the same CPU. Care will be needed to ensure that this new locking doesn't lead to dead locks with the run queue locks.

In addition to the extra overhead caused by these locking requirements, the code for gathering the statistics will need to be more complex also adding to the overhead. There is also the issue of increased serialization (there is already some due to load balancing) of task scheduling to be considered although, to be fair, this increased serialization will be within groups.

Quoted 6 lines

The f-series CPU controller does all of what you say in 403 lines (including comments and copyright). I think the biggest advantage of maintaining the group statistics in the kernel is that certain scheduling decisions can be made based on group statistics rather than task statistics, which makes the mechanism independent of the number of tasks in the group (isolates the groups from changes in number of tasks).

Yes, that's one of its advantages. Both methods have advantages and disadvantages.

Peter

Signature · 4 lines
	Cheers,
	Balbir Singh,
	Linux Technology Center,
	IBM Software Labs
#17 lore raw
Quoted 19 lines · Balbir Singh
Quoted 4 lines · Peter Williams
Quoted 2 lines · Balbir Singh

Peter Williams wrote:

<snip>

Quoted 11 lines
Quoted 2 lines

Is it possible that the effective tasks
is greater than the limit of the group?

Yes.

Quoted 1 line

How do we handle this scenario?

You've got the problem back to front. If the number of effective tasks is less than the group limit then you have the situation that needs special handling (not the other way around). I.e. if the number of effective tasks is less than the group limit then (strictly speaking) there's no need to do any capping at all as the demand is less than the limit. However, in the case where the group limit is less than one CPU (i.e. less than 1000) the recommended thing to do would be set the limit of each task in the group to the group limit.

Quoted 7 lines
Quoted 4 lines

Obviously, group limits can be greater than one CPU (i.e. 1000).

The number of CPUs on the system also needs to be taken into account for group capping as if the group cap is greater than the number of CPUs there's no way it can be exceeded and tasks in this group would not need any processing.

What if we have a group limit of 100 (out of 1000) and 150 effective tasks in the group? How do you calculate the cap of each task?

Personally I'd round up to 1 :-) but rounding down to zero is also an option. The reason I'd opt for 1 is that a zero cap has a special meaning i.e. background.

Quoted 1 line

I hope my understanding of effective tasks is correct.

Yes, but I think that you fail to realize that this problem (a lower limit to what caps can be enforced) exists for any mechanism due to the fact we're stuck with discrete mathematics in computers. This includes floating point representations of numbers which are just crude (discrete maths) approximations of real numbers.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#18 lore raw
Quoted 33 lines · Peter Williams
Quoted 22 lines · Balbir Singh
Quoted 4 lines · Peter Williams
Quoted 2 lines · Balbir Singh

Peter Williams wrote:

<snip>

Quoted 13 lines
Quoted 2 lines

Is it possible that the effective tasks
is greater than the limit of the group?

Yes.

Quoted 1 line

How do we handle this scenario?

You've got the problem back to front. If the number of effective tasks is less than the group limit then you have the situation that needs special handling (not the other way around). I.e. if the number of effective tasks is less than the group limit then (strictly speaking) there's no need to do any capping at all as the demand is less than the limit. However, in the case where the group limit is less than one CPU (i.e. less than 1000) the recommended thing to do would be set the limit of each task in the group to the group limit.

Quoted 7 lines
Quoted 4 lines

Obviously, group limits can be greater than one CPU (i.e. 1000).

The number of CPUs on the system also needs to be taken into account for group capping as if the group cap is greater than the number of CPUs there's no way it can be exceeded and tasks in this group would not need any processing.

What if we have a group limit of 100 (out of 1000) and 150 effective tasks in the group? How do you calculate the cap of each task?

Quoted 6 lines

Personally I'd round up to 1 :-) but rounding down to zero is also an option. The reason I'd opt for 1 is that a zero cap has a special meaning i.e. background.

Quoted 1 line

I hope my understanding of effective tasks is correct.

Yes, but I think that you fail to realize that this problem (a lower limit to what caps can be enforced) exists for any mechanism due to the fact we're stuck with discrete mathematics in computers. This includes floating point representations of numbers which are just crude (discrete maths) approximations of real numbers.

I do appreciate and realize the problem, thats why I asked the question.

There are some ways of solving this problem (that I could think about)

1. Keep a whole number and fraction pair and increment the fraction until it reaches a whole number and then schedule the task when the whole number value reaches a minimal threshold. Or provide tasks with some minimal whole number ticks in advance and then do not schedule them again till their fractions add up to the whole number (credit system).

For example if T1 and T2 have a cap of 0.5%. Then represent the values as whole number zero and fraction represented as 1 and divisor as 2.

Every two ticks their whole number would become 1 and fraction 0, divisor 2. Schedule the tasks for a tick whenever its whole number becomes 1 and reset then its whole number to 0.

2. In a group based cap management system, schedule some tasks (highest priority) until their cap run out. In the subsequent rounds pick and choose tasks that did not get a chance to run earlier.

Solving this is indeed a interesting problem.

Quoted 2 lines

Peter

Signature · 3 lines
	Balbir Singh,
	Linux Technology Center,
	IBM Software Labs
#19 lore raw
Quoted 51 lines · Balbir Singh
Quoted 33 lines · Peter Williams
Quoted 22 lines · Balbir Singh
Quoted 4 lines · Peter Williams
Quoted 2 lines · Balbir Singh

Peter Williams wrote:

<snip>

Quoted 13 lines
Quoted 2 lines

Is it possible that the effective tasks
is greater than the limit of the group?

Yes.

Quoted 1 line

How do we handle this scenario?

You've got the problem back to front. If the number of effective tasks is less than the group limit then you have the situation that needs special handling (not the other way around). I.e. if the number of effective tasks is less than the group limit then (strictly speaking) there's no need to do any capping at all as the demand is less than the limit. However, in the case where the group limit is less than one CPU (i.e. less than 1000) the recommended thing to do would be set the limit of each task in the group to the group limit.

Quoted 7 lines
Quoted 4 lines

Obviously, group limits can be greater than one CPU (i.e. 1000).

The number of CPUs on the system also needs to be taken into account for group capping as if the group cap is greater than the number of CPUs there's no way it can be exceeded and tasks in this group would not need any processing.

What if we have a group limit of 100 (out of 1000) and 150 effective tasks in the group? How do you calculate the cap of each task?

Quoted 6 lines

Personally I'd round up to 1 :-) but rounding down to zero is also an option. The reason I'd opt for 1 is that a zero cap has a special meaning i.e. background.

Quoted 1 line

I hope my understanding of effective tasks is correct.

Yes, but I think that you fail to realize that this problem (a lower limit to what caps can be enforced) exists for any mechanism due to the fact we're stuck with discrete mathematics in computers. This includes floating point representations of numbers which are just crude (discrete maths) approximations of real numbers.

I do appreciate and realize the problem, thats why I asked the question.

There are some ways of solving this problem (that I could think about)

1. Keep a whole number and fraction pair and increment the fraction until it reaches a whole number and then schedule the task when the whole number value reaches a minimal threshold. Or provide tasks with some minimal whole number ticks in advance and then do not schedule them again till their fractions add up to the whole number (credit system).

Quoted 7 lines

For example if T1 and T2 have a cap of 0.5%. Then represent the values as whole number zero and fraction represented as 1 and divisor as 2.

Every two ticks their whole number would become 1 and fraction 0,
divisor 2.
Schedule the tasks for a tick whenever its whole number becomes 1 and reset then its whole number to 0.

You're over engineering and you're not solving the problem. You're just moving it down a bit.

Quoted 9 lines

2. In a group based cap management system, schedule some tasks (highest priority) until their cap run out. In the subsequent rounds pick and choose
tasks that
did not get a chance to run earlier.

Solving this is indeed a interesting problem.

Once again, you're over engineering and probably making the problem worse.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#20 lore raw
Quoted 11 lines · Peter Williams

You're over engineering and you're not solving the problem. You're just moving it down a bit.

Quoted 6 lines

2. In a group based cap management system, schedule some tasks (highest priority) until their cap run out. In the subsequent rounds pick and choose
tasks that
did not get a chance to run earlier.

Quoted 6 lines
Quoted 2 lines

Solving this is indeed a interesting problem.

Once again, you're over engineering and probably making the problem worse.

I like this term over-engineering. Lets focus on the solution for the most common case and see what works out. I was pointing you to the possible limitations of the approach, which is always a good thing to do in engineering.

Quoted 1 line

Peter

Signature · 3 lines
	Balbir Singh,
	Linux Technology Center,
	IBM Software Labs
#21 lore raw
Quoted 17 lines · Balbir Singh
Quoted 15 lines · Peter Williams

You're over engineering and you're not solving the problem. You're just moving it down a bit.

Quoted 8 lines

2. In a group based cap management system, schedule some tasks (highest priority) until their cap run out. In the subsequent rounds pick and choose
tasks that
did not get a chance to run earlier.

Solving this is indeed a interesting problem.

Quoted 6 lines
Quoted 2 lines

Once again, you're over engineering and probably making the problem worse.

I like this term over-engineering. Lets focus on the solution for the most common case and see what works out. I was pointing you to the possible limitations of the approach, which is always a good thing to do in engineering.

And I was pointing out that it's a fundamental limitation that can't be avoided no matter which implementation route you follow.

Peter

Signature · 4 lines
Dr Peter Williams, Chief Scientist         <[email protected]>
Aurema Pty Limited
Level 2, 130 Elizabeth St, Sydney, NSW 2000, Australia
Tel:+61 2 9698 2322  Fax:+61 2 9699 9174 http://www.aurema.com
#22 lore raw
In reply to Balbir Singh
Quoted 4 lines · Balbir Singh

Peter Williams wrote:

If we can achieve something similar with low overhead in user space, I would certainly love to see it.

The Windows and Solaris components of IBM's eWLM product provide much the same functionality as CKRM from user space. Don't they?

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#23 lore raw
Quoted 11 lines · Peter Williams
Quoted 4 lines · Balbir Singh

Peter Williams wrote:

If we can achieve something similar with low overhead in user space, I would certainly love to see it.

The Windows and Solaris components of IBM's eWLM product provide much the same functionality as CKRM from user space. Don't they?

Peter

I know absolutely nothing about eWLM's Windows and Solaris product.

Signature · 3 lines
	Balbir Singh,
	Linux Technology Center,
	IBM Software Labs
#24 lore raw
Quoted 9 lines · Balbir Singh
Quoted 8 lines · Peter Williams
Quoted 4 lines · Balbir Singh

Peter Williams wrote:

If we can achieve something similar with low overhead in user space, I would certainly love to see it.

Quoted 7 lines
Quoted 3 lines

The Windows and Solaris components of IBM's eWLM product provide much the same functionality as CKRM from user space. Don't they?

Peter

I know absolutely nothing about eWLM's Windows and Solaris product.

I'm sorry I've always assumed that (due to its design) CKRM was intended as the Linux component of eWLM.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#25 lore raw
In reply to Peter Williams
Quoted 19 lines · Peter Williams
Quoted 18 lines · Andrew Morton
Quoted 16 lines · On Sun, 18 Jun 2006 18:26:38 +1000 Peter Williams <[email protected]>…

5. Code size measurements:

Vanilla kernel:

   text    data     bss     dec     hex filename
  33800    4689     296   38785    9781 sched.o

2554 79 0 2633 a49 mutex.o
12076 2632 0 14708 3974 base.o

Patches applied:

   text    data     bss     dec     hex filename
  36870    4721     296   41887    a39f sched.o

2630 79 0 2709 a95 mutex.o
13011 2920 0 15931 3e3b base.o

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Indicating that the size cost of the patch proper is about 3 kilobytes and the procfs costs about another 1.2 kilobytes.

hm. That seems rather a lot. I guess it's not a simple thing to do.

I suspect that a large part of that is the functions that set the caps (i.e. the equivalents of set_user_nice()) one for soft and one for hard caps. The actual capping mechanisms are quite simple.

This contribution may not be as large as I thought. Realizing that the function to set soft caps and the function to set hard caps duplicate a lot of code I've modified them to share code rather than duplicate. I've also made the functions for getting caps inline and they should just be optimized away to a field reference. But the reduction in code size is only about 285 bytes.

Before:

   text    data     bss     dec     hex filename
  32820    4913     672   38405    9605 kernel/sched.o

After:

   text    data     bss     dec     hex filename
  32535    4913     672   38120    94e8 kernel/sched.o

Noting that these values were less than those in the original mail, I've also checked the size for when the patches are excluded.

   text    data     bss     dec     hex filename
  30061    4881     672   35614    8b1e kernel/sched.o

The numbers in the e-mail were from a different computer with gcc-4.0.2 installed while these are generated with gcc-4.1.1 (also that build would not have had CONFIG_SCHED_SMT or CONFIG_SCHED_MC set). But the end result is that the cost is still of the order of 2.5 kilobytes.

A patch to make these changes is attached.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
---
 include/linux/sched.h |   24 +++++++++++--
 kernel/sched.c        |   90 ++++++++++----------------------------------------
 2 files changed, 38 insertions(+), 76 deletions(-)
include/linux/sched.h +20 -4
Index: MM-2.6.17-rc6-mm2/include/linux/sched.h
===================================================================
@@ -1022,11 +1022,27 @@ struct task_struct {
 };
 
 #ifdef CONFIG_CPU_RATE_CAPS
-unsigned int get_cpu_rate_cap(const struct task_struct *);
-int set_cpu_rate_cap(struct task_struct *, unsigned int);
+int set_cpu_rate_cap_low(struct task_struct *, unsigned int, int);
+
+static inline unsigned int get_cpu_rate_cap(const struct task_struct *p)
+{
+	return p->cpu_rate_cap;
+}
+
+static inline int set_cpu_rate_cap(struct task_struct *p, unsigned int newcap)
+{
+	return set_cpu_rate_cap_low(p, newcap, 0);
+}
 #ifdef CONFIG_CPU_RATE_HARD_CAPS
-unsigned int get_cpu_rate_hard_cap(const struct task_struct *);
-int set_cpu_rate_hard_cap(struct task_struct *, unsigned int);
+static inline unsigned int get_cpu_rate_hard_cap(const struct task_struct *p)
+{
+	return p->cpu_rate_hard_cap;
+}
+
+static inline int set_cpu_rate_hard_cap(struct task_struct *p, unsigned int newcap)
+{
+	return set_cpu_rate_cap_low(p, newcap, 1);
+}
 #endif
 #endif
 
kernel/sched.c +18 -72

123 lines not on this page · raw message

#26 lore raw
In reply to Andrew Morton
Quoted 4 lines · Andrew Morton

If the task can exceed its cap without impacting any other tasks (ie: there is spare idle capacity), what happens? I trust that spare capacity gets used?

As I said in another reply, the answer to this is yes for soft caps and how good a job was demonstrated by the kernbench results that I included. Repeated here:

Average Optimal -j 8 Load Run:

Vanilla Patch Applied Soft Cap 0%

Elapsed Time      1056.1   (1.92)  1048.2   (0.62)  1064.1   (1.59)
User Time         1908.1   (1.09)  1895.2   (1.30)  1926.6   (1.39)
System Time        181.7   (0.60)   177.5   (0.74)   173.8   (1.07)

Total 2089.8 2072.7 2100.4
Percent CPU 197.6 (0.55) 197.0 (0) 197.0 (0)
Context Switches 49253.6 (136.31) 48881.4 (92.03) 92490.8 (163.71)
Sleeps 28038.8 (228.11) 28136.0 (250.65) 25769.4 (280.40)

Note that the (slight) increase in the elapsed time when using a soft cap of zero can be directly attributed to the increase in CPU usage due to the cap overhead (an approximate increase of 16 seconds for elapsed time with an approximate increase of 28 seconds (for two CPUs) in CPU time consumed when comparing the "patch applied" and "soft cap 0%" numbers).

I think this illustrates that (for soft caps) spare capacity is not wasted?

Quoted 1 line

(Is this termed "work conserving"?)

I don't know but it sounds apt.

Peter
PS For ordinary users, I think that the ability to run jobs in the background by using a soft cap of zero is the most useful thing that this patch provides.

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#27 lore raw
In reply to Peter Williams
Quoted 1 line · Peter Williams

These patches implement CPU usage rate limits for tasks.

Personally, I'm more comfortable with guarantees rather than limits.

Specifying a limit doesn't do anything to ensure that a task (or group of tasks) gets enough cpu time to actually accomplish anything unless you specify limits on every task in the system.

Suppose you have a server app that needs at least 50% of the cpu. With a guarantee, you can say "this guy needs 50%, and I don't care about anything else". With limits you have to flip it around--"all these guys together are limited to 50%, and that guy isn't limited". Seems counterintuitive.

Chris

#28 lore raw
Quoted 4 lines · Chris Friesen
Quoted 1 line · Peter Williams

These patches implement CPU usage rate limits for tasks.

Personally, I'm more comfortable with guarantees rather than limits.

It's not an "either or" situation. You can have both.

As I said recently in other mail on this topic, the only thing that needs to be resolved when you have both caps and guarantees is which one has precedence if they conflict. Of course, one solution to this is to disallow conflicting caps and guarantees but that is really just the same as saying whichever was set first has precedence.

Quoted 2 lines

Specifying a limit doesn't do anything to ensure that a task (or group of tasks) gets enough cpu time to actually accomplish anything unless you specify limits on every task in the system.

No, but it can be used to make sure certain tasks don't hog the CPU and prevent other tasks from getting their job done.

Quoted 2 lines

Suppose you have a server app that needs at least 50% of the cpu. With a guarantee, you can say "this guy needs 50%, and I don't care about anything else". With limits you have to flip it around--"all these guys together are limited to 50%, and that guy isn't limited". Seems counterintuitive.

Yes, guarantees would be better for that problem but this doesn't mean that caps are useless. Also an equivalent situation where caps are a better solution to guarantees would be easy to generate. Ergo both mechanisms are useful.

For the ordinary user, I think that the most useful feature of this patch is the ability to impose a soft cap of zero on a task and for that cap to be inherited by its children (which it is). This is a very useful for running a job (such as a kernel build) in the background. If you look at the kernbench numbers that I enclosed you will note that, in the absence of other load on the computer, the increase in the build time using this feature is very small. The advantages of having the build run in the background are improved responsiveness for those interactive tasks we're using (e.g. editing files, reading/writing mail etc.) while the build is in progress.

Peter

Signature · 4 lines
Dr Peter Williams, Chief Scientist         <[email protected]>
Aurema Pty Limited
Level 2, 130 Elizabeth St, Sydney, NSW 2000, Australia
Tel:+61 2 9698 2322  Fax:+61 2 9699 9174 http://www.aurema.com