git: 33f3e81df531 - main - cache: combine fast path enabled status into one flag

Mateusz Guzik mjg at FreeBSD.org
Wed Jan 6 07:36:12 UTC 2021


The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=33f3e81df531d62a53390de20812d4e94720e1d3

commit 33f3e81df531d62a53390de20812d4e94720e1d3
Author:     Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-01-01 07:06:12 +0000
Commit:     Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-01-06 07:28:06 +0000

    cache: combine fast path enabled status into one flag
    
    Tested by:      pho
---
 sys/kern/vfs_cache.c             | 51 ++++++++++++++++++++++++++++++----------
 sys/security/mac/mac_framework.c |  3 +++
 sys/sys/vnode.h                  |  1 +
 3 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index ad661339b492..40298cd9fbdc 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -3571,12 +3571,45 @@ DB_SHOW_COMMAND(vpath, db_show_vpath)
 
 #endif
 
-static bool __read_frequently cache_fast_lookup = true;
-SYSCTL_BOOL(_vfs, OID_AUTO, cache_fast_lookup, CTLFLAG_RW,
-    &cache_fast_lookup, 0, "");
+static int cache_fast_lookup = 1;
+static char __read_frequently cache_fast_lookup_enabled = true;
 
 #define CACHE_FPL_FAILED	-2020
 
+void
+cache_fast_lookup_enabled_recalc(void)
+{
+	int lookup_flag;
+	int mac_on;
+
+#ifdef MAC
+	mac_on = mac_vnode_check_lookup_enabled();
+#else
+	mac_on = 0;
+#endif
+
+	lookup_flag = atomic_load_int(&cache_fast_lookup);
+	if (lookup_flag && !mac_on) {
+		atomic_store_char(&cache_fast_lookup_enabled, true);
+	} else {
+		atomic_store_char(&cache_fast_lookup_enabled, false);
+	}
+}
+
+static int
+syscal_vfs_cache_fast_lookup(SYSCTL_HANDLER_ARGS)
+{
+	int error, old;
+
+	old = atomic_load_int(&cache_fast_lookup);
+	error = sysctl_handle_int(oidp, arg1, arg2, req);
+	if (error == 0 && req->newptr && old != atomic_load_int(&cache_fast_lookup))
+		cache_fast_lookup_enabled_recalc();
+	return (error);
+}
+SYSCTL_PROC(_vfs, OID_AUTO, cache_fast_lookup, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_MPSAFE,
+    &cache_fast_lookup, 0, syscal_vfs_cache_fast_lookup, "IU", "");
+
 /*
  * Components of nameidata (or objects it can point to) which may
  * need restoring in case fast path lookup fails.
@@ -3854,16 +3887,10 @@ cache_can_fplookup(struct cache_fpl *fpl)
 	cnp = fpl->cnp;
 	td = cnp->cn_thread;
 
-	if (!cache_fast_lookup) {
-		cache_fpl_aborted_early(fpl);
-		return (false);
-	}
-#ifdef MAC
-	if (mac_vnode_check_lookup_enabled()) {
+	if (!atomic_load_char(&cache_fast_lookup_enabled)) {
 		cache_fpl_aborted_early(fpl);
 		return (false);
 	}
-#endif
 	if ((cnp->cn_flags & ~CACHE_FPL_SUPPORTED_CN_FLAGS) != 0) {
 		cache_fpl_aborted_early(fpl);
 		return (false);
@@ -5205,9 +5232,9 @@ cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status,
 	}
 	MPASS(cnp->cn_nameptr == cnp->cn_pnbuf);
 
-	if (!cache_can_fplookup(&fpl)) {
-		SDT_PROBE3(vfs, fplookup, lookup, done, ndp, fpl.line, fpl.status);
+	if (__predict_false(!cache_can_fplookup(&fpl))) {
 		*status = fpl.status;
+		SDT_PROBE3(vfs, fplookup, lookup, done, ndp, fpl.line, fpl.status);
 		return (EOPNOTSUPP);
 	}
 
diff --git a/sys/security/mac/mac_framework.c b/sys/security/mac/mac_framework.c
index 3ec932147637..c1d52eff383e 100644
--- a/sys/security/mac/mac_framework.c
+++ b/sys/security/mac/mac_framework.c
@@ -82,6 +82,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/sdt.h>
 #include <sys/sx.h>
 #include <sys/sysctl.h>
+#include <sys/vnode.h>
 
 #include <security/mac/mac_framework.h>
 #include <security/mac/mac_internal.h>
@@ -399,6 +400,8 @@ mac_policy_update(void)
 		mac_labeled |= mac_policy_getlabeled(mpc);
 		mac_policy_count++;
 	}
+
+	cache_fast_lookup_enabled_recalc();
 }
 
 /*
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 9be22f02e8d4..cb71d80c244f 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -657,6 +657,7 @@ cache_validate(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
 {
 }
 #endif
+void	cache_fast_lookup_enabled_recalc(void);
 int	change_dir(struct vnode *vp, struct thread *td);
 void	cvtstat(struct stat *st, struct ostat *ost);
 void	freebsd11_cvtnstat(struct stat *sb, struct nstat *nsb);


More information about the dev-commits-src-all mailing list