PERFORCE change 181332 for review

Edward Tomasz Napierala trasz at FreeBSD.org
Thu Jul 22 18:39:42 UTC 2010


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

Change 181332 by trasz at trasz_victim on 2010/07/22 18:39:15

	Don't track resource usage for kernel processes.

Affected files ...

.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#18 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#90 edit

Differences ...

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

@@ -55,6 +55,31 @@
 
 static void container_sub(struct container *dest, const struct container *src);
 
+
+static int
+container_resource_reclaimable(int resource)
+{
+
+	switch (resource) {
+	case RUSAGE_CPU:
+		return (0);
+	default:
+		return (1);
+	}
+}
+
+static int
+container_resource_inheritable(int resource)
+{
+
+	switch (resource) {
+	case RUSAGE_NPROC:
+		return (0);
+	default:
+		return (1);
+	}
+}
+
 static int
 container_add(struct container *dest, const struct container *src)
 {
@@ -111,7 +136,8 @@
 		    ("resource usage propagation meltdown: src < 0"));
 		KASSERT(src->c_resources[i] <= dest->c_resources[i],
 		    ("resource usage propagation meltdown: src > dest"));
-		dest->c_resources[i] -= src->c_resources[i];
+		if (container_resource_reclaimable(i))
+			dest->c_resources[i] -= src->c_resources[i];
 	}
 
 	/*
@@ -226,10 +252,8 @@
 	KASSERT(container != NULL, ("NULL container"));
 
 	for (i = 0; i <= RUSAGE_MAX; i++) {
-		/*
-		 * XXX: The RUSAGE_CPU thing should be done in a better way.
-		 */
-		if (container->c_resources[i] != 0 && i != RUSAGE_CPU)
+		if (container->c_resources[i] != 0 &&
+		    container_resource_reclaimable(i))
 			printf("destroying non-empty container: "
 			    "%ju allocated for resource %d",
 			    container->c_resources[i], i);
@@ -316,6 +340,9 @@
 	int error;
 #endif
 
+	if (p->p_flag & P_SYSTEM)
+		return (0);
+
 #if 0
 	printf("rusage_add: allocating %ju of %s for %s (pid %d)\n", amount, hrl_resource_name(resource), p->p_comm, p->p_pid);
 #endif
@@ -345,13 +372,15 @@
 	int error;
 #endif
 
+	if (p->p_flag & P_SYSTEM)
+		return (0);
+
 #if 0
 	printf("rusage_set: allocated %lld of %s for %s (pid %d)\n", amount, hrl_resource_name(resource), p->p_comm, p->p_pid);
 #endif
 
 	KASSERT(amount >= 0, ("rusage_set: invalid amount for resource %d: %ju",
 	    resource, amount));
-
 	diff = amount - p->p_container.c_resources[resource];
 #ifdef HRL
 	if (diff > 0) {
@@ -393,12 +422,16 @@
 rusage_sub(struct proc *p, int resource, uint64_t amount)
 {
 
+	if (p->p_flag & P_SYSTEM)
+		return;
 #if 0
 	printf("rusage_sub: freeing %lld of %s for %s (pid %d)\n", amount, hrl_resource_name(resource), p->p_comm, p->p_pid);
 #endif
 
 	KASSERT(amount > 0, ("rusage_sub: invalid amount for resource %d: %ju",
 	    resource, amount));
+	KASSERT(container_resource_reclaimable(resource),
+	    ("rusage_sub: called for non-reclaimable resource %d", resource));
 
 	mtx_lock(&container_lock);
 	KASSERT(amount <= p->p_container.c_resources[resource],
@@ -410,18 +443,6 @@
 	mtx_unlock(&container_lock);
 }
 
-static int
-container_resource_inheritable(int resource)
-{
-
-	switch (resource) {
-	case RUSAGE_NPROC:
-		return (0);
-	default:
-		return (1);
-	}
-}
-
 /*
  * Inherit resource usage information and containing containers
  * from the parent process.
@@ -432,6 +453,12 @@
 	int i, error = 0;
 	struct container *container;
 
+	/*
+	 * No resource accounting for kernel processes.
+	 */
+	if (child->p_flag & P_SYSTEM)
+		return (0);
+
 	PROC_LOCK(parent);
 	PROC_LOCK(child);
 	mtx_lock(&container_lock);

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

@@ -1464,6 +1464,12 @@
 	struct hrl_rule_link *link;
 	struct hrl_rule *rule;
 
+	/*
+	 * No limits for kernel processes.
+	 */
+	if (child->p_flag & P_SYSTEM)
+		return (0);
+
 	mtx_lock(&hrl_lock);
 
 	/*


More information about the p4-projects mailing list