PERFORCE change 188139 for review
Edward Tomasz Napierala
trasz at FreeBSD.org
Mon Jan 24 22:58:01 UTC 2011
http://p4web.freebsd.org/@@188139?ac=10
Change 188139 by trasz at trasz_victim on 2011/01/24 22:56:59
Rounding of %CPU is bad, especially for a very shortly living
processes. Implement a workaround.
Affected files ...
.. //depot/projects/soc2009/trasz_limits/TODO#41 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#64 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_rctl.c#16 edit
.. //depot/projects/soc2009/trasz_limits/sys/sys/container.h#23 edit
Differences ...
==== //depot/projects/soc2009/trasz_limits/TODO#41 (text+ko) ====
@@ -20,6 +20,9 @@
Also, try to figure out what's going on with 'intr' p_flag - checking for P_SYSTEM
didn't really work for that process.
+ - The jailstat(1)/userstat(1) tool seems to use lots of CPU time. Rewriting
+ it in C could make sense.
+
Issues:
- Setting RSS limit too low can make the system thrash to death.
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#64 (text+ko) ====
@@ -86,6 +86,19 @@
SDT_PROBE_DEFINE2(container, kernel, container, join_failure, join-failure, "struct container *", "struct container *");
SDT_PROBE_DEFINE2(container, kernel, container, leave, leave, "struct container *", "struct container *");
+int
+container_resource_in_thousands(int resource)
+{
+ switch (resource) {
+ case RUSAGE_CPU:
+ case RUSAGE_WALLCLOCK:
+ case RUSAGE_PCTCPU:
+ return (1);
+ default:
+ return (0);
+ }
+}
+
static int
container_resource_reclaimable(int resource)
{
@@ -658,7 +671,7 @@
if (runtime < p->p_prev_runtime)
runtime = p->p_prev_runtime;
#endif
- pctcpu = (runtime - p->p_prev_runtime) / 10000;
+ pctcpu = (runtime - p->p_prev_runtime) / 10;
rusage_set(p, RUSAGE_CPU, runtime);
rusage_add(p, RUSAGE_PCTCPU, pctcpu);
@@ -811,7 +824,7 @@
if (runtime < p->p_prev_runtime)
runtime = p->p_prev_runtime;
#endif
- pctcpu = (runtime - p->p_prev_runtime) / 10000;
+ pctcpu = (runtime - p->p_prev_runtime) / 10;
p->p_prev_runtime = runtime;
if (pctcpu > pctcpu_limit)
rusage_throttle(p, 1);
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_rctl.c#16 (text+ko) ====
@@ -867,6 +867,8 @@
error = str2int64(amountstr, &rule->rr_amount);
if (error != 0)
goto out;
+ if (container_resource_in_thousands(rule->rr_resource))
+ rule->rr_amount *= 1000;
}
if (perstr == NULL || perstr[0] == '\0')
@@ -1048,6 +1050,7 @@
static void
rctl_rule_to_sbuf(struct sbuf *sb, const struct rctl_rule *rule)
{
+ int64_t amount;
sbuf_printf(sb, "%s:", rctl_subject_type_name(rule->rr_subject_type));
@@ -1081,10 +1084,15 @@
rule->rr_subject_type);
}
+ amount = rule->rr_amount;
+ if (amount != RCTL_AMOUNT_UNDEFINED &&
+ container_resource_in_thousands(rule->rr_resource))
+ amount /= 1000;
+
sbuf_printf(sb, "%s:%s=%jd",
rctl_resource_name(rule->rr_resource),
rctl_action_name(rule->rr_action),
- rule->rr_amount);
+ amount);
if (rule->rr_per != rule->rr_subject_type)
sbuf_printf(sb, "/%s", rctl_subject_type_name(rule->rr_per));
@@ -1140,12 +1148,15 @@
rctl_container_to_sbuf(struct container *container)
{
int i;
+ int64_t amount;
struct sbuf *sb;
sb = sbuf_new_auto();
for (i = 0; i <= RUSAGE_MAX; i++) {
- sbuf_printf(sb, "%s=%jd,", rctl_resource_name(i),
- container->c_resources[i]);
+ amount = container->c_resources[i];
+ if (container_resource_in_thousands(i))
+ amount /= 1000;
+ sbuf_printf(sb, "%s=%jd,", rctl_resource_name(i), amount);
}
sbuf_setpos(sb, sbuf_len(sb) - 1);
return (sb);
==== //depot/projects/soc2009/trasz_limits/sys/sys/container.h#23 (text+ko) ====
@@ -113,4 +113,6 @@
void container_proc_ucred_changed(struct proc *p, struct ucred *oldcred,
struct ucred *newcred);
+int container_resource_in_thousands(int resource);
+
#endif /* !_CONTAINER_H_ */
More information about the p4-projects
mailing list