summaryrefslogtreecommitdiffstats
path: root/sys/fs/nullfs/null_subr.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2012-09-09 19:20:23 +0000
committerkib <kib@FreeBSD.org>2012-09-09 19:20:23 +0000
commit3ed1c80d257237f50d1eb45a535cd5a9b2ce243e (patch)
tree0f1623ea0434b273e48d26ddda4c72d4d29053ef /sys/fs/nullfs/null_subr.c
parent5a86a6849adc026d814651fd6afc864b2377b9c8 (diff)
downloadFreeBSD-src-3ed1c80d257237f50d1eb45a535cd5a9b2ce243e.zip
FreeBSD-src-3ed1c80d257237f50d1eb45a535cd5a9b2ce243e.tar.gz
Allow shared lookups for nullfs mounts, if lower filesystem supports
it. There are two problems which shall be addressed for shared lookups use to have measurable effect on nullfs scalability: 1. When vfs_lookup() calls VOP_LOOKUP() for nullfs, which passes lookup operation to lower fs, resulting vnode is often only shared-locked. Then null_nodeget() cannot instantiate covering vnode for lower vnode, since insmntque1() and null_hashins() require exclusive lock on the lower. Change the assert that lower vnode is exclusively locked to only require any lock. If null hash failed to find pre-existing nullfs vnode for lower vnode and the vnode is shared-locked, the lower vnode lock is upgraded. 2. Nullfs reclaims its vnodes on deactivation. This is due to nullfs inability to detect reclamation of the lower vnode. Reclamation of a nullfs vnode at deactivation time prevents a reference to the lower vnode to become stale. Change nullfs VOP_INACTIVE to not reclaim the vnode, instead use the VFS_RECLAIM_LOWERVP to get notification and reclaim upper vnode together with the reclamation of the lower vnode. Note that nullfs reclamation procedure calls vput() on the lowervp vnode, temporary unlocking the vnode being reclaimed. This seems to be fine for MPSAFE filesystems, but not-MPSAFE code often put partially initialized vnode on some globally visible list, and later can decide that half-constructed vnode is not needed. If nullfs mount is created above such filesystem, then other threads might catch such not properly initialized vnode. Instead of trying to overcome this case, e.g. by recursing the lower vnode lock in null_reclaim_lowervp(), I decided to rely on nearby removal of the support for non-MPSAFE filesystems. In collaboration with: pho MFC after: 3 weeks
Diffstat (limited to 'sys/fs/nullfs/null_subr.c')
-rw-r--r--sys/fs/nullfs/null_subr.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/sys/fs/nullfs/null_subr.c b/sys/fs/nullfs/null_subr.c
index 7e3571d..5f926a6 100644
--- a/sys/fs/nullfs/null_subr.c
+++ b/sys/fs/nullfs/null_subr.c
@@ -67,7 +67,6 @@ struct mtx null_hashmtx;
static MALLOC_DEFINE(M_NULLFSHASH, "nullfs_hash", "NULLFS hash table");
MALLOC_DEFINE(M_NULLFSNODE, "nullfs_node", "NULLFS vnode private part");
-static struct vnode * null_hashget(struct mount *, struct vnode *);
static struct vnode * null_hashins(struct mount *, struct null_node *);
/*
@@ -98,7 +97,7 @@ nullfs_uninit(vfsp)
* Return a VREF'ed alias for lower vnode if already exists, else 0.
* Lower vnode should be locked on entry and will be left locked on exit.
*/
-static struct vnode *
+struct vnode *
null_hashget(mp, lowervp)
struct mount *mp;
struct vnode *lowervp;
@@ -209,14 +208,10 @@ null_nodeget(mp, lowervp, vpp)
struct vnode *vp;
int error;
- /*
- * The insmntque1() call below requires the exclusive lock on
- * the nullfs vnode.
- */
- ASSERT_VOP_ELOCKED(lowervp, "lowervp");
- KASSERT(lowervp->v_usecount >= 1, ("Unreferenced vnode %p\n", lowervp));
+ ASSERT_VOP_LOCKED(lowervp, "lowervp");
+ KASSERT(lowervp->v_usecount >= 1, ("Unreferenced vnode %p", lowervp));
- /* Lookup the hash firstly */
+ /* Lookup the hash firstly. */
*vpp = null_hashget(mp, lowervp);
if (*vpp != NULL) {
vrele(lowervp);
@@ -224,6 +219,19 @@ null_nodeget(mp, lowervp, vpp)
}
/*
+ * The insmntque1() call below requires the exclusive lock on
+ * the nullfs vnode. Upgrade the lock now if hash failed to
+ * provide ready to use vnode.
+ */
+ if (VOP_ISLOCKED(lowervp) != LK_EXCLUSIVE) {
+ vn_lock(lowervp, LK_UPGRADE | LK_RETRY);
+ if ((lowervp->v_iflag & VI_DOOMED) != 0) {
+ vput(lowervp);
+ return (ENOENT);
+ }
+ }
+
+ /*
* We do not serialize vnode creation, instead we will check for
* duplicates later, when adding new vnode to hash.
* Note that duplicate can only appear in hash if the lowervp is
@@ -233,8 +241,7 @@ null_nodeget(mp, lowervp, vpp)
* might cause a bogus v_data pointer to get dereferenced
* elsewhere if MALLOC should block.
*/
- xp = malloc(sizeof(struct null_node),
- M_NULLFSNODE, M_WAITOK);
+ xp = malloc(sizeof(struct null_node), M_NULLFSNODE, M_WAITOK);
error = getnewvnode("null", mp, &null_vnodeops, &vp);
if (error) {
OpenPOWER on IntegriCloud