Author: mjg
Date: Fri Oct 16 00:55:31 2020
New Revision: 366741
URL: https://svnweb.freebsd.org/changeset/base/366741

Log:
  cache: dedup code for negative promotion

Modified:
  head/sys/kern/vfs_cache.c

Modified: head/sys/kern/vfs_cache.c
==============================================================================
--- head/sys/kern/vfs_cache.c   Fri Oct 16 00:55:09 2020        (r366740)
+++ head/sys/kern/vfs_cache.c   Fri Oct 16 00:55:31 2020        (r366741)
@@ -807,22 +807,34 @@ cache_negative_init(struct namecache *ncp)
 }
 
 static void
-cache_negative_hit(struct namecache *ncp)
+cache_negative_promote(struct namecache *ncp)
 {
        struct neglist *nl;
        struct negstate *ns;
 
        ns = NCP2NEGSTATE(ncp);
-       if ((ns->neg_flag & NEG_HOT) != 0)
-               return;
        nl = NCP2NEGLIST(ncp);
-       mtx_lock(&nl->nl_lock);
+       mtx_assert(&nl->nl_lock, MA_OWNED);
        if ((ns->neg_flag & NEG_HOT) == 0) {
                TAILQ_REMOVE(&nl->nl_list, ncp, nc_dst);
                TAILQ_INSERT_TAIL(&nl->nl_hotlist, ncp, nc_dst);
                nl->nl_hotnum++;
                ns->neg_flag |= NEG_HOT;
        }
+}
+
+static void
+cache_negative_hit(struct namecache *ncp)
+{
+       struct neglist *nl;
+       struct negstate *ns;
+
+       ns = NCP2NEGSTATE(ncp);
+       if ((ns->neg_flag & NEG_HOT) != 0)
+               return;
+       nl = NCP2NEGLIST(ncp);
+       mtx_lock(&nl->nl_lock);
+       cache_negative_promote(ncp);
        mtx_unlock(&nl->nl_lock);
 }
 
@@ -3376,7 +3388,6 @@ cache_fplookup_negative_promote(struct cache_fpl *fpl,
        struct componentname *cnp;
        struct namecache *ncp;
        struct neglist *nl;
-       struct negstate *ns;
        struct vnode *dvp;
        u_char nc_flag;
 
@@ -3434,13 +3445,7 @@ cache_fplookup_negative_promote(struct cache_fpl *fpl,
                goto out_abort;
        }
 
-       ns = NCP2NEGSTATE(ncp);
-       if ((ns->neg_flag & NEG_HOT) == 0) {
-               TAILQ_REMOVE(&nl->nl_list, ncp, nc_dst);
-               TAILQ_INSERT_TAIL(&nl->nl_hotlist, ncp, nc_dst);
-               nl->nl_hotnum++;
-               ns->neg_flag |= NEG_HOT;
-       }
+       cache_negative_promote(ncp);
 
        SDT_PROBE2(vfs, namecache, lookup, hit__negative, dvp, ncp->nc_name);
        counter_u64_add(numneghits, 1);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to