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
This commit is contained in:
Edward Tomasz Napierala 2011-10-03 17:40:55 +00:00
parent c06f5f6cea
commit 2d8696d1e8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=225944
2 changed files with 22 additions and 20 deletions

View File

@ -879,17 +879,6 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp,
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

View File

@ -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);