PERFORCE change 188135 for review

Edward Tomasz Napierala trasz at FreeBSD.org
Mon Jan 24 20:05:41 UTC 2011


http://p4web.freebsd.org/@@188135?ac=10

Change 188135 by trasz at trasz_victim on 2011/01/24 20:04:54

	Turns out, resource dampening is required.

Affected files ...

.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#62 edit

Differences ...

==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#62 (text+ko) ====

@@ -161,6 +161,17 @@
 	}
 }
 
+static int
+container_resource_dampened(int resource)
+{
+	switch (resource) {
+	case RUSAGE_PCTCPU:
+		return (1);
+	default:
+		return (0);
+	}
+}
+
 static void
 container_add(struct container *dest, const struct container *src)
 {
@@ -191,7 +202,8 @@
 	 * Update resource usage in dest.
 	 */
 	for (i = 0; i <= RUSAGE_MAX; i++) {
-		if (!container_resource_sloppy(i)) {
+		if (!container_resource_sloppy(i) &&
+		    !container_resource_dampened(i)) {
 			KASSERT(dest->c_resources[i] >= 0,
 			    ("resource usage propagation meltdown: dest < 0"));
 			KASSERT(src->c_resources[i] >= 0,
@@ -202,7 +214,8 @@
 		if (container_resource_reclaimable(i)) {
 			dest->c_resources[i] -= src->c_resources[i];
 			if (dest->c_resources[i] < 0) {
-				KASSERT(container_resource_sloppy(i),
+				KASSERT(container_resource_sloppy(i) ||
+				    container_resource_dampened(i),
 				    ("container_sub: usage < 0"));
 				dest->c_resources[i] = 0;
 			}
@@ -237,6 +250,8 @@
 			continue;
 		if (!container_resource_reclaimable(i))
 			continue;
+		if (container_resource_dampened(i))
+			continue;
 		KASSERT(container->c_resources[i] == 0,
 		    ("destroying non-empty container: "
 		    "%ju allocated for resource %d\n",
@@ -268,7 +283,8 @@
 
 	container->c_resources[resource] += amount;
 	if (container->c_resources[resource] < 0) {
-		KASSERT(container_resource_sloppy(resource),
+		KASSERT(container_resource_sloppy(resource) ||
+		    container_resource_dampened(resource),
 		    ("container_alloc_resource: usage < 0"));
 		container->c_resources[resource] = 0;
 	}
@@ -637,7 +653,6 @@
 	rusage_set(p, RUSAGE_NPTS, 0);
 	rusage_set(p, RUSAGE_NTHR, 0);
 	rusage_set(p, RUSAGE_RSS, 0);
-	rusage_set(p, RUSAGE_PCTCPU, 0);
 	PROC_UNLOCK(p);
 
 #ifdef RCTL
@@ -725,6 +740,29 @@
 }
 
 static void
+container_dampen_callback(struct container *container, void *arg2, void *arg3)
+{
+	int orig, diff, hz;
+
+	hz = *(int *)arg2;
+
+	mtx_lock(&container_lock);
+	orig = container->c_resources[RUSAGE_PCTCPU];
+	KASSERT(orig >= 0, ("container_dampen_callback: orig < 0"));
+	if (orig == 0) {
+		mtx_unlock(&container_lock);
+		return;
+	}
+	diff = orig / 10;
+	if (diff == 0)
+		diff = 1;
+	container->c_resources[RUSAGE_PCTCPU] -= diff;
+	KASSERT(container->c_resources[RUSAGE_PCTCPU] >= 0,
+	    ("container_dampen_callback: result < 0"));
+	mtx_unlock(&container_lock);
+}
+
+static void
 containerd(void)
 {
 	struct thread *td;
@@ -733,6 +771,11 @@
 	uint64_t pctcpu, pctcpu_limit, runtime;
 
 	for (;;) {
+		loginclass_container_foreach(container_dampen_callback, &hz,
+		    NULL);
+		ui_container_foreach(container_dampen_callback, &hz, NULL);
+		prison_container_foreach(container_dampen_callback, &hz, NULL);
+
 		sx_slock(&allproc_lock);
 		FOREACH_PROC_IN_SYSTEM(p) {
 			microuptime(&wallclock);


More information about the p4-projects mailing list