From owner-p4-projects@FreeBSD.ORG Thu Jul 22 18:39:42 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id EEDB31065673; Thu, 22 Jul 2010 18:39:41 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9ACE3106566B for ; Thu, 22 Jul 2010 18:39:41 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 87BF98FC08 for ; Thu, 22 Jul 2010 18:39:41 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o6MIdfdX000897 for ; Thu, 22 Jul 2010 18:39:41 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o6MIdf7r000895 for perforce@freebsd.org; Thu, 22 Jul 2010 18:39:41 GMT (envelope-from trasz@freebsd.org) Date: Thu, 22 Jul 2010 18:39:41 GMT Message-Id: <201007221839.o6MIdf7r000895@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to trasz@freebsd.org using -f From: Edward Tomasz Napierala To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 181332 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Jul 2010 18:39:42 -0000 http://p4web.freebsd.org/@@181332?ac=10 Change 181332 by trasz@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); /*