summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2014-06-22 21:16:18 +0000
committermav <mav@FreeBSD.org>2014-06-22 21:16:18 +0000
commit48559e83fe4df046cb41c32db61d773aae911fd8 (patch)
tree33080f6667a6aa7d02ee2f4549e588666df51d92 /sys
parentfebec37d72817eae6f4c86618558d6d9d64c79d8 (diff)
downloadFreeBSD-src-48559e83fe4df046cb41c32db61d773aae911fd8.zip
FreeBSD-src-48559e83fe4df046cb41c32db61d773aae911fd8.tar.gz
MFC r267392:
Implement simple direct-mapped cache for popular filesystem identifiers to avoid congestion on global mountlist_mtx mutex in vfs_busyfs(), while traversing through the list of mount points. This change significantly improves NFS server scalability, since it had to do this translation for every request, and the global lock becomes quite congested. This code is more optimized for relatively small number of mount points. On systems with hundreds of active mount points this simple cache may have many collisions. But the original traversal code in that case should also behave much worse, so we are not loosing much.
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/vfs_subr.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 8c3af46..52b4059 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -500,23 +500,53 @@ vfs_getvfs(fsid_t *fsid)
/*
* Lookup a mount point by filesystem identifier, busying it before
* returning.
+ *
+ * To avoid congestion on mountlist_mtx, implement simple direct-mapped
+ * cache for popular filesystem identifiers. The cache is lockess, using
+ * the fact that struct mount's are never freed. In worst case we may
+ * get pointer to unmounted or even different filesystem, so we have to
+ * check what we got, and go slow way if so.
*/
struct mount *
vfs_busyfs(fsid_t *fsid)
{
+#define FSID_CACHE_SIZE 256
+ typedef struct mount * volatile vmp_t;
+ static vmp_t cache[FSID_CACHE_SIZE];
struct mount *mp;
int error;
+ uint32_t hash;
CTR2(KTR_VFS, "%s: fsid %p", __func__, fsid);
+ hash = fsid->val[0] ^ fsid->val[1];
+ hash = (hash >> 16 ^ hash) & (FSID_CACHE_SIZE - 1);
+ mp = cache[hash];
+ if (mp == NULL ||
+ mp->mnt_stat.f_fsid.val[0] != fsid->val[0] ||
+ mp->mnt_stat.f_fsid.val[1] != fsid->val[1])
+ goto slow;
+ if (vfs_busy(mp, 0) != 0) {
+ cache[hash] = NULL;
+ goto slow;
+ }
+ if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
+ mp->mnt_stat.f_fsid.val[1] == fsid->val[1])
+ return (mp);
+ else
+ vfs_unbusy(mp);
+
+slow:
mtx_lock(&mountlist_mtx);
TAILQ_FOREACH(mp, &mountlist, mnt_list) {
if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
mp->mnt_stat.f_fsid.val[1] == fsid->val[1]) {
error = vfs_busy(mp, MBF_MNTLSTLOCK);
if (error) {
+ cache[hash] = NULL;
mtx_unlock(&mountlist_mtx);
return (NULL);
}
+ cache[hash] = mp;
return (mp);
}
}
OpenPOWER on IntegriCloud