summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2014-06-22 18:06:11 +0000
committermav <mav@FreeBSD.org>2014-06-22 18:06:11 +0000
commit0d8805deb240bfb4e7242c264b24ce5065fb4e27 (patch)
tree071b005e442bd8b45a29f9fda43b89c1f37b9986 /sys/kern
parent23b32162cef338290cead8bd5a58c7de5978da64 (diff)
downloadFreeBSD-src-0d8805deb240bfb4e7242c264b24ce5065fb4e27.zip
FreeBSD-src-0d8805deb240bfb4e7242c264b24ce5065fb4e27.tar.gz
MFC r267232, r267239:
Use atomics to modify numvnodes variable. This allows to mostly avoid lock usage in getnewvnode_[drop_]reserve(), that reduces number of global vnode_free_list_mtx mutex acquisitions from 4 to 2 per NFS request on ZFS, improving SMP scalability.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/vfs_subr.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 91c64a3..63f8768 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -997,12 +997,19 @@ getnewvnode_reserve(u_int count)
struct thread *td;
td = curthread;
+ /* First try to be quick and racy. */
+ if (atomic_fetchadd_long(&numvnodes, count) + count <= desiredvnodes) {
+ td->td_vp_reserv += count;
+ return;
+ } else
+ atomic_subtract_long(&numvnodes, count);
+
mtx_lock(&vnode_free_list_mtx);
while (count > 0) {
if (getnewvnode_wait(0) == 0) {
count--;
td->td_vp_reserv++;
- numvnodes++;
+ atomic_add_long(&numvnodes, 1);
}
}
mtx_unlock(&vnode_free_list_mtx);
@@ -1014,10 +1021,7 @@ getnewvnode_drop_reserve(void)
struct thread *td;
td = curthread;
- mtx_lock(&vnode_free_list_mtx);
- KASSERT(numvnodes >= td->td_vp_reserv, ("reserve too large"));
- numvnodes -= td->td_vp_reserv;
- mtx_unlock(&vnode_free_list_mtx);
+ atomic_subtract_long(&numvnodes, td->td_vp_reserv);
td->td_vp_reserv = 0;
}
@@ -1054,7 +1058,7 @@ getnewvnode(const char *tag, struct mount *mp, struct vop_vector *vops,
return (error);
}
#endif
- numvnodes++;
+ atomic_add_long(&numvnodes, 1);
mtx_unlock(&vnode_free_list_mtx);
alloc:
vp = (struct vnode *) uma_zalloc(vnode_zone, M_WAITOK|M_ZERO);
@@ -2383,9 +2387,7 @@ vdropl(struct vnode *vp)
* The vnode has been marked for destruction, so free it.
*/
CTR2(KTR_VFS, "%s: destroying the vnode %p", __func__, vp);
- mtx_lock(&vnode_free_list_mtx);
- numvnodes--;
- mtx_unlock(&vnode_free_list_mtx);
+ atomic_subtract_long(&numvnodes, 1);
bo = &vp->v_bufobj;
VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
("cleaned vnode still on the free list."));
OpenPOWER on IntegriCloud