Date: Thu, 6 Jan 2011 10:44:06 GMT From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 187530 for review Message-ID: <201101061044.p06Ai6mU023238@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101061044.p06Ai6mU023238>