svn commit: r225944 - head/sys/kern
Edward Tomasz Napierala
trasz at FreeBSD.org
Mon Oct 3 17:40:55 UTC 2011
Author: trasz
Date: Mon Oct 3 17:40:55 2011
New Revision: 225944
URL: http://svn.freebsd.org/changeset/base/225944
Log:
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
Modified:
head/sys/kern/kern_fork.c
head/sys/kern/kern_racct.c
Modified: head/sys/kern/kern_fork.c
==============================================================================
--- head/sys/kern/kern_fork.c Mon Oct 3 17:01:31 2011 (r225943)
+++ head/sys/kern/kern_fork.c Mon Oct 3 17:40:55 2011 (r225944)
@@ -879,17 +879,6 @@ fork1(struct thread *td, int flags, int
goto fail1;
}
-#ifdef RACCT
- PROC_LOCK(newproc);
- error = racct_add(newproc, RACCT_NPROC, 1);
- error += racct_add(newproc, RACCT_NTHR, 1);
- PROC_UNLOCK(newproc);
- if (error != 0) {
- error = EAGAIN;
- goto fail1;
- }
-#endif
-
#ifdef MAC
mac_proc_init(newproc);
#endif
Modified: head/sys/kern/kern_racct.c
==============================================================================
--- head/sys/kern/kern_racct.c Mon Oct 3 17:01:31 2011 (r225943)
+++ head/sys/kern/kern_racct.c Mon Oct 3 17:40:55 2011 (r225944)
@@ -261,12 +261,8 @@ racct_alloc_resource(struct racct *racct
}
}
-/*
- * 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,
*/
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, str
#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);
More information about the svn-src-all
mailing list