svn commit: r366986 - head/sys/kern

Mateusz Guzik mjg at FreeBSD.org
Sat Oct 24 01:13:48 UTC 2020


Author: mjg
Date: Sat Oct 24 01:13:47 2020
New Revision: 366986
URL: https://svnweb.freebsd.org/changeset/base/366986

Log:
  cache: fold branch prediction into cache_ncp_canuse

Modified:
  head/sys/kern/vfs_cache.c

Modified: head/sys/kern/vfs_cache.c
==============================================================================
--- head/sys/kern/vfs_cache.c	Sat Oct 24 01:13:16 2020	(r366985)
+++ head/sys/kern/vfs_cache.c	Sat Oct 24 01:13:47 2020	(r366986)
@@ -233,14 +233,15 @@ cache_ncp_invalidate(struct namecache *ncp)
  * All places which elide locks are supposed to call this after they are
  * done with reading from an entry.
  */
-static bool
-cache_ncp_canuse(struct namecache *ncp)
-{
+#define cache_ncp_canuse(ncp)	({					\
+	struct namecache *_ncp = (ncp);					\
+	u_char _nc_flag;						\
+									\
+	atomic_thread_fence_acq();					\
+	_nc_flag = atomic_load_char(&_ncp->nc_flag);			\
+	__predict_true((_nc_flag & (NCF_INVALID | NCF_WIP)) == 0);	\
+})
 
-	atomic_thread_fence_acq();
-	return ((atomic_load_char(&ncp->nc_flag) & (NCF_INVALID | NCF_WIP)) == 0);
-}
-
 /*
  * Name caching works as follows:
  *
@@ -1056,7 +1057,7 @@ cache_neg_promote_cond(struct vnode *dvp, struct compo
 		goto out_abort;
 	}
 
-	if (__predict_false(!cache_ncp_canuse(ncp))) {
+	if (!cache_ncp_canuse(ncp)) {
 		goto out_abort;
 	}
 
@@ -1834,7 +1835,7 @@ negative_success:
 	cache_out_ts(ncp, tsp, ticksp);
 	whiteout = (ncp->nc_flag & NCF_WHITE);
 	neg_promote = cache_neg_hit_prep(ncp);
-	if (__predict_false(!cache_ncp_canuse(ncp))) {
+	if (!cache_ncp_canuse(ncp)) {
 		cache_neg_hit_abort(ncp);
 		vfs_smr_exit();
 		goto out_fallback;
@@ -4008,7 +4009,7 @@ cache_fplookup_dotdot(struct cache_fpl *fpl)
 		fpl->tvp = ncp->nc_dvp;
 	}
 
-	if (__predict_false(!cache_ncp_canuse(ncp))) {
+	if (!cache_ncp_canuse(ncp)) {
 		return (cache_fpl_aborted(fpl));
 	}
 
@@ -4041,7 +4042,7 @@ cache_fplookup_neg(struct cache_fpl *fpl, struct namec
 		return (cache_fpl_partial(fpl));
 	}
 	neg_promote = cache_neg_hit_prep(ncp);
-	if (__predict_false(!cache_ncp_canuse(ncp))) {
+	if (!cache_ncp_canuse(ncp)) {
 		cache_neg_hit_abort(ncp);
 		return (cache_fpl_partial(fpl));
 	}
@@ -4096,7 +4097,7 @@ cache_fplookup_next(struct cache_fpl *fpl)
 		return (cache_fplookup_neg(fpl, ncp, hash));
 	}
 
-	if (__predict_false(!cache_ncp_canuse(ncp))) {
+	if (!cache_ncp_canuse(ncp)) {
 		return (cache_fpl_partial(fpl));
 	}
 


More information about the svn-src-all mailing list