Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys make cache_purge more controlable.



details:   https://anonhg.NetBSD.org/src/rev/133e444a49a0
branches:  trunk
changeset: 565361:133e444a49a0
user:      yamt <yamt%NetBSD.org@localhost>
date:      Mon Apr 05 10:20:52 2004 +0000

description:
make cache_purge more controlable.
namely, allow following operations.
        - purge only an entry specified by a component name.
        - purge only child entries.
        - purge only parent entries.
no objections on tech-kern@.

diffstat:

 sys/kern/vfs_cache.c |  79 +++++++++++++++++++++++++++++++++------------------
 sys/sys/namei.h      |   6 +++-
 2 files changed, 56 insertions(+), 29 deletions(-)

diffs (168 lines):

diff -r 4378fc185d3e -r 133e444a49a0 sys/kern/vfs_cache.c
--- a/sys/kern/vfs_cache.c      Mon Apr 05 10:10:29 2004 +0000
+++ b/sys/kern/vfs_cache.c      Mon Apr 05 10:20:52 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_cache.c,v 1.54 2003/09/01 12:13:55 yamt Exp $      */
+/*     $NetBSD: vfs_cache.c,v 1.55 2004/04/05 10:20:52 yamt Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.54 2003/09/01 12:13:55 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.55 2004/04/05 10:20:52 yamt Exp $");
 
 #include "opt_ddb.h"
 #include "opt_revcache.h"
@@ -96,6 +96,8 @@
 
 static void cache_remove(struct namecache *);
 static void cache_free(struct namecache *);
+static __inline struct namecache *cache_lookup_entry(
+    const struct vnode *, const struct componentname *);
 
 static void
 cache_remove(struct namecache *ncp)
@@ -133,6 +135,26 @@
        numcache--; /* XXX MP */
 }
 
+static __inline struct namecache *
+cache_lookup_entry(const struct vnode *dvp, const struct componentname *cnp)
+{
+       struct nchashhead *ncpp;
+       struct namecache *ncp;
+
+       LOCK_ASSERT(simple_lock_held(&namecache_slock));
+
+       ncpp = &nchashtbl[NCHASH(cnp, dvp)];
+
+       LIST_FOREACH(ncp, ncpp, nc_hash) {
+               if (ncp->nc_dvp == dvp &&
+                   ncp->nc_nlen == cnp->cn_namelen &&
+                   !memcmp(ncp->nc_name, cnp->cn_nameptr, (u_int)ncp->nc_nlen))
+                       break;
+       }
+
+       return ncp;
+}
+
 /*
  * Look for a the name in the cache. We don't do this
  * if the segment name is long, simply so the cache can avoid
@@ -153,7 +175,6 @@
 cache_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
 {
        struct namecache *ncp;
-       struct nchashhead *ncpp;
        struct vnode *vp;
        int error;
 
@@ -169,15 +190,9 @@
                cnp->cn_flags &= ~MAKEENTRY;
                goto fail;
        }
-       ncpp = &nchashtbl[NCHASH(cnp, dvp)];
        simple_lock(&namecache_slock);
-       LIST_FOREACH(ncp, ncpp, nc_hash) {
-               if (ncp->nc_dvp == dvp &&
-                   ncp->nc_nlen == cnp->cn_namelen &&
-                   !memcmp(ncp->nc_name, cnp->cn_nameptr, (u_int)ncp->nc_nlen))
-                       break;
-       }
-       if (ncp == 0) {
+       ncp = cache_lookup_entry(dvp, cnp);
+       if (ncp == NULL) {
                nchstats.ncs_miss++;
                goto fail_wlock;
        }
@@ -304,14 +319,8 @@
         * the cache entry is invalid, or otherwise don't
         * want cache entry to exist.
         */
-       TAILQ_REMOVE(&nclruhead, ncp, nc_lru);
-       LIST_REMOVE(ncp, nc_hash);
-       ncp->nc_hash.le_prev = NULL;
-       if (ncp->nc_vhash.le_prev != NULL) {
-               LIST_REMOVE(ncp, nc_vhash);
-               ncp->nc_vhash.le_prev = NULL;
-       }
-       TAILQ_INSERT_HEAD(&nclruhead, ncp, nc_lru);
+       cache_remove(ncp);
+       cache_free(ncp);
 
 fail_wlock:
        simple_unlock(&namecache_slock);
@@ -408,6 +417,7 @@
         * Free the cache slot at head of lru chain.
         */
        simple_lock(&namecache_slock);
+       KASSERT(cache_lookup_entry(dvp, cnp) == NULL);
        if (numcache < numvnodes) {
                numcache++;
                simple_unlock(&namecache_slock);
@@ -529,20 +539,33 @@
  * hide entries that would now be invalid
  */
 void
-cache_purge(struct vnode *vp)
+cache_purge1(struct vnode *vp, const struct componentname *cnp, int flags)
 {
        struct namecache *ncp, *ncnext;
 
        simple_lock(&namecache_slock);
-       for (ncp = LIST_FIRST(&vp->v_nclist); ncp != NULL; ncp = ncnext) {
-               ncnext = LIST_NEXT(ncp, nc_vlist);
-               cache_remove(ncp);
-               cache_free(ncp);
+       if (flags & PURGE_PARENTS) {
+               for (ncp = LIST_FIRST(&vp->v_nclist); ncp != NULL;
+                   ncp = ncnext) {
+                       ncnext = LIST_NEXT(ncp, nc_vlist);
+                       cache_remove(ncp);
+                       cache_free(ncp);
+               }
        }
-       for (ncp = LIST_FIRST(&vp->v_dnclist); ncp != NULL; ncp = ncnext) {
-               ncnext = LIST_NEXT(ncp, nc_dvlist);
-               cache_remove(ncp);
-               cache_free(ncp);
+       if (flags & PURGE_CHILDREN) {
+               for (ncp = LIST_FIRST(&vp->v_dnclist); ncp != NULL;
+                   ncp = ncnext) {
+                       ncnext = LIST_NEXT(ncp, nc_dvlist);
+                       cache_remove(ncp);
+                       cache_free(ncp);
+               }
+       }
+       if (cnp != NULL) {
+               ncp = cache_lookup_entry(vp, cnp);
+               if (ncp) {
+                       cache_remove(ncp);
+                       cache_free(ncp);
+               }
        }
        simple_unlock(&namecache_slock);
 }
diff -r 4378fc185d3e -r 133e444a49a0 sys/sys/namei.h
--- a/sys/sys/namei.h   Mon Apr 05 10:10:29 2004 +0000
+++ b/sys/sys/namei.h   Mon Apr 05 10:20:52 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: namei.h,v 1.34 2003/09/11 17:33:43 christos Exp $      */
+/*     $NetBSD: namei.h,v 1.35 2004/04/05 10:20:52 yamt Exp $  */
 
 /*
  * Copyright (c) 1985, 1989, 1991, 1993
@@ -189,6 +189,10 @@
 int    lookup __P((struct nameidata *));
 int    relookup __P((struct vnode *, struct vnode **, struct componentname *));
 void cache_purge __P((struct vnode *));
+void cache_purge1 __P((struct vnode *, const struct componentname *, int));
+#define        PURGE_PARENTS   1
+#define        PURGE_CHILDREN  2
+#define        cache_purge(vp) cache_purge1((vp), NULL, PURGE_PARENTS|PURGE_CHILDREN)
 int cache_lookup __P((struct vnode *, struct vnode **, struct componentname *));
 int cache_revlookup __P((struct vnode *, struct vnode **, char **, char *));
 void cache_enter __P((struct vnode *, struct vnode *, struct componentname *));



Home | Main Index | Thread Index | Old Index