static int racct_add_locked(struct proc *p, int resource, uint64_t amount) { #ifdef RCTL int error; #endif if (p->p_flag & P_SYSTEM) return (0); SDT_PROBE(racct, kernel, rusage, add, p, resource, amount, 0, 0); /* * We need proc lock to dereference p->p_ucred. */ PROC_LOCK_ASSERT(p, MA_OWNED); #ifdef RCTL error = rctl_enforce(p, resource, amount); if (error && RACCT_IS_DENIABLE(resource)) { SDT_PROBE(racct, kernel, rusage, add_failure, p, resource, amount, 0, 0); return (error); } #endif racct_alloc_resource(p->p_racct, resource, amount); racct_add_cred_locked(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 racct_add_cred(struct ucred *cred, int resource, uint64_t amount) { mtx_lock(&racct_lock); racct_add_cred_locked(cred, resource, amount); mtx_unlock(&racct_lock); }
static int racct_set_locked(struct proc *p, int resource, uint64_t amount) { int64_t diff; #ifdef RCTL int error; #endif if (p->p_flag & P_SYSTEM) return (0); SDT_PROBE(racct, kernel, rusage, set, p, resource, amount, 0, 0); /* * We need proc lock to dereference p->p_ucred. */ PROC_LOCK_ASSERT(p, MA_OWNED); 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 #ifdef RCTL if (diff > 0) { error = rctl_enforce(p, resource, diff); if (error && RACCT_IS_DENIABLE(resource)) { SDT_PROBE(racct, kernel, rusage, set_failure, p, resource, amount, 0, 0); return (error); } } #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); return (0); }
void racct_set_force(struct proc *p, int resource, uint64_t amount) { int64_t diff; SDT_PROBE(racct, kernel, rusage, set, p, resource, amount, 0, 0); /* * We need proc lock to dereference p->p_ucred. */ PROC_LOCK_ASSERT(p, MA_OWNED); mtx_lock(&racct_lock); diff = amount - p->p_racct->r_resources[resource]; 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); mtx_unlock(&racct_lock); }