Date: Thu, 23 Dec 2010 14:49:55 GMT From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 187161 for review Message-ID: <201012231449.oBNEntD9053359@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@187161?ac=10 Change 187161 by trasz@trasz_victim on 2010/12/23 14:48:53 Introduce rusage_set_force and rework error handling in obreak(). Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#42 edit .. //depot/projects/soc2009/trasz_limits/sys/sys/container.h#19 edit .. //depot/projects/soc2009/trasz_limits/sys/vm/vm_unix.c#13 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#42 (text+ko) ==== @@ -399,6 +399,29 @@ return (error); } +void +rusage_set_force(struct proc *p, int resource, uint64_t amount) +{ + int64_t diff; + + if (p->p_flag & P_SYSTEM) + return; + + SDT_PROBE(container, kernel, rusage, set, p, resource, amount, 0, 0); + + KASSERT(amount >= 0, ("rusage_set: invalid amount for resource %d: %ju", + resource, amount)); + + 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); + else if (diff < 0) + rusage_sub_cred(p->p_ucred, resource, -diff); +} + /* * Returns amount of 'resource' the process 'p' can keep allocated. * Allocating more than that would be denied, unless the resource ==== //depot/projects/soc2009/trasz_limits/sys/sys/container.h#19 (text+ko) ==== @@ -98,6 +98,7 @@ void rusage_add_cred(struct ucred *cred, int resource, uint64_t amount); void rusage_add_force(struct proc *p, int resource, uint64_t amount); int rusage_set(struct proc *p, int resource, uint64_t amount); +void rusage_set_force(struct proc *p, int resource, uint64_t amount); void rusage_sub(struct proc *p, int resource, uint64_t amount); void rusage_sub_cred(struct ucred *cred, int resource, uint64_t amount); uint64_t rusage_get_limit(struct proc *p, int resource); ==== //depot/projects/soc2009/trasz_limits/sys/vm/vm_unix.c#13 (text+ko) ==== @@ -99,12 +99,6 @@ error = ENOMEM; goto done; } - error = rusage_set(td->td_proc, RUSAGE_DATA, new - base); - if (error != 0) { - error = ENOMEM; - goto done; - } - if (new > vm_map_max(&vm->vm_map)) { error = ENOMEM; goto done; @@ -123,18 +117,23 @@ error = ENOMEM; goto done; } + error = rusage_set(td->td_proc, RUSAGE_DATA, new - base); + if (error != 0) { + error = ENOMEM; + goto done; + } error = rusage_set(td->td_proc, RUSAGE_VMEM, vm->vm_map.size + (new - old)); if (error != 0) { + rusage_set_force(td->td_proc, RUSAGE_DATA, old - base); error = ENOMEM; goto done; } - /* - * XXX: Rollback for rusage_set() call above? - */ rv = vm_map_insert(&vm->vm_map, NULL, 0, old, new, VM_PROT_RW, VM_PROT_ALL, 0); if (rv != KERN_SUCCESS) { + rusage_set_force(td->td_proc, RUSAGE_DATA, old - base); + rusage_set_force(td->td_proc, RUSAGE_VMEM, vm->vm_map.size); error = ENOMEM; goto done; } @@ -160,6 +159,8 @@ goto done; } vm->vm_dsize -= btoc(old - new); + rusage_set_force(td->td_proc, RUSAGE_DATA, new - base); + rusage_set_force(td->td_proc, RUSAGE_VMEM, vm->vm_map.size); } done: vm_map_unlock(&vm->vm_map);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201012231449.oBNEntD9053359>