Date: Sun, 9 Jan 2011 12:42:03 GMT From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 187637 for review Message-ID: <201101091242.p09Cg3Ab066859@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@187637?ac=10 Change 187637 by trasz@trasz_victim on 2011/01/09 12:41:43 Implement dampening. This breaks %CPU horribly, this will be fixed soon. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#49 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#49 (text+ko) ==== @@ -159,6 +159,17 @@ } } +static int +container_resource_dampened(int resource) +{ + switch (resource) { + case RUSAGE_PCTCPU: + return (1); + default: + return (0); + } +} + static void container_add(struct container *dest, const struct container *src) { @@ -189,7 +200,8 @@ * Update resource usage in dest. */ for (i = 0; i <= RUSAGE_MAX; i++) { - if (!container_resource_sloppy(i)) { + if (!container_resource_sloppy(i) && + !container_resource_dampened(i)) { KASSERT(dest->c_resources[i] >= 0, ("resource usage propagation meltdown: dest < 0")); KASSERT(src->c_resources[i] >= 0, @@ -199,7 +211,7 @@ } if (container_resource_reclaimable(i)) { dest->c_resources[i] -= src->c_resources[i]; - if (container_resource_sloppy(i) && dest->c_resources[i] < 0) + if (dest->c_resources[i] < 0) dest->c_resources[i] = 0; } } @@ -230,8 +242,11 @@ for (i = 0; i <= RUSAGE_MAX; i++) { if (container_resource_sloppy(i)) continue; - KASSERT(container->c_resources[i] == 0 || - !container_resource_reclaimable(i), + if (!container_resource_reclaimable(i)) + continue; + if (container_resource_dampened(i)) + continue; + KASSERT(container->c_resources[i] == 0, ("destroying non-empty container: " "%ju allocated for resource %d\n", container->c_resources[i], i)); @@ -261,8 +276,12 @@ KASSERT(container != NULL, ("NULL container")); container->c_resources[resource] += amount; - if (container_resource_sloppy(resource) && container->c_resources[resource] < 0) + if (container->c_resources[resource] < 0) { + KASSERT(container_resource_sloppy(resource) || + container_resource_dampened(resource), + ("container_alloc_resource: usage < 0")); container->c_resources[resource] = 0; + } } /* @@ -587,7 +606,6 @@ /* * XXX: Free this some other way. */ - rusage_set(p, RUSAGE_PCTCPU, 0); rusage_set(p, RUSAGE_FSIZE, 0); rusage_set(p, RUSAGE_NPTS, 0); rusage_set(p, RUSAGE_NTHR, 0); @@ -673,6 +691,31 @@ } } +static int +container_dampen_callback(struct container *container, void *arg2, void *arg3) +{ + int orig, diff, hz; + + hz = *(int *)arg2; + + mtx_lock(&container_lock); + orig = container->c_resources[RUSAGE_PCTCPU]; + KASSERT(orig >= 0, ("container_dampen_callback: orig < 0")); + if (orig == 0) { + mtx_unlock(&container_lock); + return (0); + } + diff = orig / 10; + if (diff == 0) + diff = 1; + container->c_resources[RUSAGE_PCTCPU] -= diff; + KASSERT(container->c_resources[RUSAGE_PCTCPU] >= 0, + ("container_dampen_callback: result < 0")); + mtx_unlock(&container_lock); + + return (0); +} + static void containerd(void) { @@ -683,6 +726,11 @@ uint64_t pctcpu_limit; for (;;) { + loginclass_container_foreach(container_dampen_callback, &hz, + NULL); + ui_container_foreach(container_dampen_callback, &hz, NULL); + prison_container_foreach(container_dampen_callback, &hz, NULL); + sx_slock(&allproc_lock); FOREACH_PROC_IN_SYSTEM(p) { pctcpu_limit = rusage_get_limit(p, RUSAGE_PCTCPU);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101091242.p09Cg3Ab066859>