diff options
author | rwatson <rwatson@FreeBSD.org> | 2005-01-08 04:45:57 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2005-01-08 04:45:57 +0000 |
commit | afca6a6239c4512281cf6f6df54151e522cee3f7 (patch) | |
tree | e4f14341d48f468695460fb38bbe6d1532d24520 /sys/kern/kern_acct.c | |
parent | 41cf7f35b4ac60e93d5b9723174fdf98dca2c32a (diff) | |
download | FreeBSD-src-afca6a6239c4512281cf6f6df54151e522cee3f7.zip FreeBSD-src-afca6a6239c4512281cf6f6df54151e522cee3f7.tar.gz |
In acct_process(), do a lockless read of acctvp to see if it's NULL
before deciding to do more expensive locking to account for process
exit. This acceptable minor race avoids two mutex operations in
that highly common case of accounting not being enabled.
MFC after: 2 weeks
Diffstat (limited to 'sys/kern/kern_acct.c')
-rw-r--r-- | sys/kern/kern_acct.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 2b810ed..8574d21 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -229,9 +229,20 @@ acct_process(td) struct vnode *vp; int t, ret; + /* + * Lockless check of accounting condition before doing the hard + * work. + */ + if (acctp == NULLVP) + return (0); + mtx_lock(&acct_mtx); - /* If accounting isn't enabled, don't bother */ + /* + * If accounting isn't enabled, don't bother. Have to check again + * once we own the lock in case we raced with disabling of accounting + * by another thread. + */ vp = acctp; if (vp == NULLVP) { mtx_unlock(&acct_mtx); |