summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_racct.c
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2011-10-03 17:40:55 +0000
committertrasz <trasz@FreeBSD.org>2011-10-03 17:40:55 +0000
commit76ddb474d9a3bbd9eddd495cdf53ef48d9918753 (patch)
treef1c0860bb63ac1dfc40b197d2279f69fbcd5f5e1 /sys/kern/kern_racct.c
parentfa5272165dcca2593d6249d2fb2707cab94648e6 (diff)
downloadFreeBSD-src-76ddb474d9a3bbd9eddd495cdf53ef48d9918753.zip
FreeBSD-src-76ddb474d9a3bbd9eddd495cdf53ef48d9918753.tar.gz
Move some code inside the racct_proc_fork(); it spares a few lock operations
and it's more logical this way. MFC after: 3 days
Diffstat (limited to 'sys/kern/kern_racct.c')
-rw-r--r--sys/kern/kern_racct.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/sys/kern/kern_racct.c b/sys/kern/kern_racct.c
index 8414cda..04beabd 100644
--- a/sys/kern/kern_racct.c
+++ b/sys/kern/kern_racct.c
@@ -261,12 +261,8 @@ racct_alloc_resource(struct racct *racct, int resource,
}
}
-/*
- * Increase allocation of 'resource' by 'amount' for process 'p'.
- * Return 0 if it's below limits, or errno, if it's not.
- */
-int
-racct_add(struct proc *p, int resource, uint64_t amount)
+static int
+racct_add_locked(struct proc *p, int resource, uint64_t amount)
{
#ifdef RCTL
int error;
@@ -282,23 +278,35 @@ racct_add(struct proc *p, int resource, uint64_t amount)
*/
PROC_LOCK_ASSERT(p, MA_OWNED);
- mtx_lock(&racct_lock);
#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);
- mtx_unlock(&racct_lock);
return (error);
}
#endif
racct_alloc_resource(p->p_racct, resource, amount);
racct_add_cred_locked(p->p_ucred, resource, amount);
- mtx_unlock(&racct_lock);
return (0);
}
+/*
+ * Increase allocation of 'resource' by 'amount' for process 'p'.
+ * Return 0 if it's below limits, or errno, if it's not.
+ */
+int
+racct_add(struct proc *p, int resource, uint64_t amount)
+{
+ int error;
+
+ mtx_lock(&racct_lock);
+ error = racct_add_locked(p, resource, amount);
+ mtx_unlock(&racct_lock);
+ return (error);
+}
+
static void
racct_add_cred_locked(struct ucred *cred, int resource, uint64_t amount)
{
@@ -575,8 +583,13 @@ racct_proc_fork(struct proc *parent, struct proc *child)
#ifdef RCTL
error = rctl_proc_fork(parent, child);
+ if (error != 0)
+ goto out;
#endif
+ error = racct_add_locked(child, RACCT_NPROC, 1);
+ error += racct_add_locked(child, RACCT_NTHR, 1);
+
out:
mtx_unlock(&racct_lock);
PROC_UNLOCK(child);
OpenPOWER on IntegriCloud