Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Aug 2006 08:31:32 GMT
From:      Chris Jones <cdjones@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 103817 for review
Message-ID:  <200608140831.k7E8VWiB043867@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=103817

Change 103817 by cdjones@cdjones-impulse on 2006/08/14 08:31:14

	Limit jailed KSEs' priorities based on their jails' shares of total jailed CPU shares.  (Experimental)

Affected files ...

.. //depot/projects/soc2006/cdjones_jail/src/sys/kern/sched_hier.c#8 edit

Differences ...

==== //depot/projects/soc2006/cdjones_jail/src/sys/kern/sched_hier.c#8 (text+ko) ====

@@ -41,6 +41,7 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/jail.h>
 #include <sys/kernel.h>
 #include <sys/ktr.h>
 #include <sys/lock.h>
@@ -176,6 +177,8 @@
 static int	forward_wakeup(int  cpunum);
 #endif
 
+static uint32_t total_jail_sched_shares;
+
 static struct kproc_desc sched_kp = {
         "schedcpu",
         schedcpu_thread,
@@ -227,7 +230,7 @@
 
 SYSCTL_NODE(_kern, OID_AUTO, sched, CTLFLAG_RD, 0, "Scheduler");
 
-SYSCTL_STRING(_kern_sched, OID_AUTO, name, CTLFLAG_RD, "4BSD", 0,
+SYSCTL_STRING(_kern_sched, OID_AUTO, name, CTLFLAG_RD, "HIER", 0,
     "Scheduler name");
 
 SYSCTL_PROC(_kern_sched, OID_AUTO, quantum, CTLTYPE_INT | CTLFLAG_RW,
@@ -540,8 +543,25 @@
 schedcpu_thread(void)
 {
 	int nowake;
+	struct prison *pr;
+	u_int32_t nShares = 0;
 
 	for (;;) {
+  	       /* 
+		* Update total jail CPU shares in case they've changed.
+		* Safe to read pr_sched_shares without mutex because
+		* in worst case, we get a bogus value which will be 
+		* corrected on the next pass.
+		*
+		* TODO: this should be done by forcing a recalculation
+		* when jail CPU shares are added / changed, rather than
+		* doing it every second.
+		*/
+	        LIST_FOREACH(pr, &allprison, pr_list) {
+		  nShares += pr->pr_sched_shares;
+   	        }
+		total_jail_sched_shares = nShares;
+
 		schedcpu();
 		tsleep(&nowake, 0, "-", hz);
 	}
@@ -579,10 +599,23 @@
 resetpriority(struct ksegrp *kg)
 {
 	register unsigned int newpriority;
+	struct prison *pr = kg->kg_proc->p_ucred->cr_prison;
 
 	if (kg->kg_pri_class == PRI_TIMESHARE) {
 		newpriority = PUSER + kg->kg_estcpu / INVERSE_ESTCPU_WEIGHT +
 		    NICE_WEIGHT * (kg->kg_proc->p_nice - PRIO_MIN);
+		if (NULL != pr) {
+		  /* 
+		   * Skew the priority by the jail's share of CPU resources.
+		   * The unjailed processes get half the CPU time.
+		   *
+		   * TODO: this is a hard limit.  We should really also have
+		   * soft limits available.  Also, the amount of CPU time 
+		   * reserved to unjailed processes really should be sysctl'd.
+		   */ 
+		    newpriority *= pr->pr_sched_shares;
+		    newpriority /= 2*total_jail_sched_shares;
+		}
 		newpriority = min(max(newpriority, PRI_MIN_TIMESHARE),
 		    PRI_MAX_TIMESHARE);
 		kg->kg_user_pri = newpriority;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608140831.k7E8VWiB043867>