From owner-p4-projects@FreeBSD.ORG Thu Jan 6 10:44:07 2011 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 26D591065672; Thu, 6 Jan 2011 10:44:07 +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 DD15B106566C for ; Thu, 6 Jan 2011 10:44:06 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id CAEA48FC14 for ; Thu, 6 Jan 2011 10:44:06 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id p06Ai6NZ023241 for ; Thu, 6 Jan 2011 10:44:06 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id p06Ai6mU023238 for perforce@freebsd.org; Thu, 6 Jan 2011 10:44:06 GMT (envelope-from trasz@freebsd.org) Date: Thu, 6 Jan 2011 10:44:06 GMT Message-Id: <201101061044.p06Ai6mU023238@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.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 187530 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, 06 Jan 2011 10:44:07 -0000 http://p4web.freebsd.org/@@187530?ac=10 Change 187530 by trasz@trasz_victim on 2011/01/06 10:43:42 Get rid of recursive mutex. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#48 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#48 (text+ko) ==== @@ -63,9 +63,11 @@ #ifdef CONTAINERS static struct mtx container_lock; -MTX_SYSINIT(container_lock, &container_lock, "container lock", MTX_RECURSE); +MTX_SYSINIT(container_lock, &container_lock, "container lock", MTX_DEF); static void container_sub(struct container *dest, const struct container *src); +static void rusage_sub_cred_locked(struct ucred *cred, int resource, uint64_t amount); +static void rusage_add_cred_locked(struct ucred *cred, int resource, uint64_t amount); SDT_PROVIDER_DEFINE(container); SDT_PROBE_DEFINE3(container, kernel, rusage, add, add, "struct proc *", "int", "uint64_t"); @@ -292,20 +294,14 @@ } #endif container_alloc_resource(&p->p_container, resource, amount); + rusage_add_cred_locked(p->p_ucred, resource, amount); mtx_unlock(&container_lock); - rusage_add_cred(p->p_ucred, resource, amount); return (0); } -/* - * Increase allocation of 'resource' by 'amount' for credential 'cred'. Doesn't - * check for limits and never fails. - * - * XXX: Shouldn't this ever return an error? - */ -void -rusage_add_cred(struct ucred *cred, int resource, uint64_t amount) +static void +rusage_add_cred_locked(struct ucred *cred, int resource, uint64_t amount) { struct prison *pr; @@ -314,11 +310,24 @@ KASSERT(amount >= 0, ("rusage_add_cred: invalid amount for resource %d: %ju", resource, amount)); - mtx_lock(&container_lock); container_alloc_resource(&cred->cr_ruidinfo->ui_container, resource, amount); for (pr = cred->cr_prison; pr != NULL; pr = pr->pr_parent) container_alloc_resource(&pr->pr_container, resource, amount); container_alloc_resource(&cred->cr_loginclass->lc_container, resource, amount); +} + +/* + * Increase allocation of 'resource' by 'amount' for credential 'cred'. Doesn't + * check for limits and never fails. + * + * XXX: Shouldn't this ever return an error? + */ +void +rusage_add_cred(struct ucred *cred, int resource, uint64_t amount) +{ + + mtx_lock(&container_lock); + rusage_add_cred_locked(cred, resource, amount); mtx_unlock(&container_lock); } @@ -376,13 +385,10 @@ } #endif container_alloc_resource(&p->p_container, resource, diff); - /* - * XXX: Mutex recursion. - */ if (diff > 0) - rusage_add_cred(p->p_ucred, resource, diff); + rusage_add_cred_locked(p->p_ucred, resource, diff); else if (diff < 0) - rusage_sub_cred(p->p_ucred, resource, -diff); + rusage_sub_cred_locked(p->p_ucred, resource, -diff); return (0); } @@ -421,11 +427,11 @@ mtx_lock(&container_lock); diff = amount - p->p_container.c_resources[resource]; container_alloc_resource(&p->p_container, resource, diff); - mtx_unlock(&container_lock); if (diff > 0) - rusage_add_cred(p->p_ucred, resource, diff); + rusage_add_cred_locked(p->p_ucred, resource, diff); else if (diff < 0) - rusage_sub_cred(p->p_ucred, resource, -diff); + rusage_sub_cred_locked(p->p_ucred, resource, -diff); + mtx_unlock(&container_lock); } /* @@ -468,15 +474,12 @@ p->p_container.c_resources[resource], p->p_comm, p->p_pid)); container_alloc_resource(&p->p_container, resource, -amount); + rusage_sub_cred_locked(p->p_ucred, resource, amount); mtx_unlock(&container_lock); - rusage_sub_cred(p->p_ucred, resource, amount); } -/* - * Decrease allocation of 'resource' by 'amount' for credential 'cred'. - */ -void -rusage_sub_cred(struct ucred *cred, int resource, uint64_t amount) +static void +rusage_sub_cred_locked(struct ucred *cred, int resource, uint64_t amount) { struct prison *pr; @@ -489,11 +492,21 @@ ("rusage_sub_cred: called for non-reclaimable resource %d", resource)); #endif - mtx_lock(&container_lock); container_alloc_resource(&cred->cr_ruidinfo->ui_container, resource, -amount); for (pr = cred->cr_prison; pr != NULL; pr = pr->pr_parent) container_alloc_resource(&pr->pr_container, resource, -amount); container_alloc_resource(&cred->cr_loginclass->lc_container, resource, -amount); +} + +/* + * Decrease allocation of 'resource' by 'amount' for credential 'cred'. + */ +void +rusage_sub_cred(struct ucred *cred, int resource, uint64_t amount) +{ + + mtx_lock(&container_lock); + rusage_sub_cred_locked(cred, resource, amount); mtx_unlock(&container_lock); }