socsvn commit: r240175 - soc2012/rudot/sys/kern
rudot at FreeBSD.org
rudot at FreeBSD.org
Tue Aug 7 15:35:19 UTC 2012
Author: rudot
Date: Tue Aug 7 15:35:17 2012
New Revision: 240175
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240175
Log:
decay %cpu in racct containers (per-user, per-loginclass and per-jail) - work inb progress
Modified:
soc2012/rudot/sys/kern/kern_racct.c
Modified: soc2012/rudot/sys/kern/kern_racct.c
==============================================================================
--- soc2012/rudot/sys/kern/kern_racct.c Tue Aug 7 13:11:47 2012 (r240174)
+++ soc2012/rudot/sys/kern/kern_racct.c Tue Aug 7 15:35:17 2012 (r240175)
@@ -157,7 +157,9 @@
RACCT_RECLAIMABLE | RACCT_DENIABLE | RACCT_SLOPPY,
[RACCT_WALLCLOCK] =
RACCT_IN_MILLIONS,
- [RACCT_PCTCPU] = RACCT_RECLAIMABLE | RACCT_DENIABLE };
+ [RACCT_PCTCPU] = RACCT_DENIABLE };
+
+static const fixpt_t RACCT_DECAY_FACTOR = 0.9 * FSCALE;
#ifdef SCHED_4BSD
/*
@@ -579,7 +581,9 @@
static int
racct_set_check_locked(struct proc *p, int resource, uint64_t amount)
{
- int64_t diff, available;
+ int64_t available;
+ int64_t old_amount, decayed_amount;
+ int64_t diff, decayed_diff;
SDT_PROBE(racct, kernel, rusage, set, p, resource, amount, 0, 0);
@@ -591,21 +595,19 @@
/*
* may be negative
*/
- diff = amount - p->p_racct->r_resources[resource];
-#ifdef notyet
- KASSERT(diff >= 0 || RACCT_IS_RECLAIMABLE(resource),
- ("racct_set: usage of non-reclaimable resource %d dropping",
- resource));
-#endif
+ old_amount = p->p_racct->r_resources[resource];
+ diff = amount - old_amount;
+ decayed_amount = old_amount * RACCT_DECAY_FACTOR / FSCALE;
+ decayed_diff = amount - decayed_amount;
available = INT64_MAX;
#ifdef RCTL
available = rctl_pcpu_available(p);
#endif
racct_alloc_resource(p->p_racct, resource, diff);
- if (diff > 0)
- racct_add_cred_locked(p->p_ucred, resource, diff);
- else if (diff < 0)
- racct_sub_cred_locked(p->p_ucred, resource, -diff);
+ if (decayed_diff > 0)
+ racct_add_cred_locked(p->p_ucred, resource, decayed_diff);
+ else if (decayed_diff < 0)
+ racct_sub_cred_locked(p->p_ucred, resource, -decayed_diff);
return (available <= diff);
}
@@ -1017,6 +1019,38 @@
}
static void
+racct_decay_resource(struct racct *racct, void * res, void* dummy)
+{
+ int resource;
+ int64_t r_old, r_new;
+
+ mtx_assert(&racct_lock, MA_OWNED);
+
+ resource = *(int *) res;
+ r_old = racct->r_resources[resource];
+
+ /* If there is nothing to decay, just exit. */
+ if (r_old <= 0)
+ return;
+
+ r_new = r_old * RACCT_DECAY_FACTOR / FSCALE;
+ racct->r_resources[resource] = r_new;
+}
+
+static void
+racct_decay_pcpu(void)
+{
+ int resource;
+
+ mtx_assert(&racct_lock, MA_OWNED);
+
+ resource = RACCT_PCTCPU;
+ ui_racct_foreach(racct_decay_resource, &resource, NULL);
+ loginclass_racct_foreach(racct_decay_resource, &resource, NULL);
+ prison_racct_foreach(racct_decay_resource, &resource, NULL);
+}
+
+static void
racctd(void)
{
struct thread *td;
@@ -1027,6 +1061,10 @@
int over_limits;
for (;;) {
+ mtx_lock(&racct_lock);
+ racct_decay_pcpu();
+ mtx_unlock(&racct_lock);
+
sx_slock(&allproc_lock);
LIST_FOREACH(p, &zombproc, p_list) {
More information about the svn-soc-all
mailing list