Source-Changes-HG archive

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

[src/trunk]: src/sys Introduce two helper functions to centralise the namecac...



details:   https://anonhg.NetBSD.org/src/rev/f6d91fd057bf
branches:  trunk
changeset: 329676:f6d91fd057bf
user:      joerg <joerg%NetBSD.org@localhost>
date:      Tue Jun 03 19:30:29 2014 +0000

description:
Introduce two helper functions to centralise the namecache statistics
in vfs_cache.c. Use consistent locking around the per-cpu data.

diffstat:

 sys/fs/cd9660/cd9660_lookup.c       |  10 ++++------
 sys/fs/filecorefs/filecore_lookup.c |  10 ++++------
 sys/kern/vfs_cache.c                |  34 ++++++++++++++++++++++++++++++----
 sys/sys/namei.src                   |   4 +++-
 sys/ufs/ext2fs/ext2fs_lookup.c      |   8 ++++----
 sys/ufs/lfs/ulfs_lookup.c           |   8 ++++----
 sys/ufs/ufs/ufs_lookup.c            |   8 ++++----
 7 files changed, 53 insertions(+), 29 deletions(-)

diffs (296 lines):

diff -r d3ab9db9e7b0 -r f6d91fd057bf sys/fs/cd9660/cd9660_lookup.c
--- a/sys/fs/cd9660/cd9660_lookup.c     Tue Jun 03 15:56:14 2014 +0000
+++ b/sys/fs/cd9660/cd9660_lookup.c     Tue Jun 03 19:30:29 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cd9660_lookup.c,v 1.26 2014/02/07 15:29:21 hannken Exp $       */
+/*     $NetBSD: cd9660_lookup.c,v 1.27 2014/06/03 19:30:30 joerg Exp $ */
 
 /*-
  * Copyright (c) 1989, 1993, 1994
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cd9660_lookup.c,v 1.26 2014/02/07 15:29:21 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd9660_lookup.c,v 1.27 2014/06/03 19:30:30 joerg Exp $");
 
 #include <sys/param.h>
 #include <sys/namei.h>
@@ -57,8 +57,6 @@
 #include <fs/cd9660/cd9660_rrip.h>
 #include <fs/cd9660/cd9660_mount.h>
 
-struct nchstats iso_nchstats;
-
 /*
  * Convert a component of a pathname into a pointer to a locked inode.
  * This is a very central and rather complicated routine.
@@ -191,7 +189,7 @@
                    &bp)))
                                return (error);
                numdirpasses = 2;
-               iso_nchstats.ncs_2passes++;
+               namecache_count_2passes();
        }
        endsearch = dp->i_size;
 
@@ -343,7 +341,7 @@
 
 found:
        if (numdirpasses == 2)
-               iso_nchstats.ncs_pass2++;
+               namecache_count_pass2();
 
        /*
         * Found component in pathname.
diff -r d3ab9db9e7b0 -r f6d91fd057bf sys/fs/filecorefs/filecore_lookup.c
--- a/sys/fs/filecorefs/filecore_lookup.c       Tue Jun 03 15:56:14 2014 +0000
+++ b/sys/fs/filecorefs/filecore_lookup.c       Tue Jun 03 19:30:29 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: filecore_lookup.c,v 1.19 2014/02/07 15:29:21 hannken Exp $     */
+/*     $NetBSD: filecore_lookup.c,v 1.20 2014/06/03 19:30:30 joerg Exp $       */
 
 /*-
  * Copyright (c) 1989, 1993, 1994 The Regents of the University of California.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: filecore_lookup.c,v 1.19 2014/02/07 15:29:21 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: filecore_lookup.c,v 1.20 2014/06/03 19:30:30 joerg Exp $");
 
 #include <sys/param.h>
 #include <sys/namei.h>
@@ -80,8 +80,6 @@
 #include <fs/filecorefs/filecore_extern.h>
 #include <fs/filecorefs/filecore_node.h>
 
-struct nchstats filecore_nchstats;
-
 /*
  * Convert a component of a pathname into a pointer to a locked inode.
  * This is a very central and rather complicated routine.
@@ -193,7 +191,7 @@
        } else {
                i = dp->i_diroff;
                numdirpasses = 2;
-               filecore_nchstats.ncs_2passes++;
+               namecache_count_2passes();
        }
        endsearch = FILECORE_MAXDIRENTS;
 
@@ -251,7 +249,7 @@
 
 found:
        if (numdirpasses == 2)
-               filecore_nchstats.ncs_pass2++;
+               namecache_count_pass2();
 
        /*
         * Found component in pathname.
diff -r d3ab9db9e7b0 -r f6d91fd057bf sys/kern/vfs_cache.c
--- a/sys/kern/vfs_cache.c      Tue Jun 03 15:56:14 2014 +0000
+++ b/sys/kern/vfs_cache.c      Tue Jun 03 19:30:29 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_cache.c,v 1.94 2014/02/07 15:29:22 hannken Exp $   */
+/*     $NetBSD: vfs_cache.c,v 1.95 2014/06/03 19:30:30 joerg Exp $     */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.94 2014/02/07 15:29:22 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.95 2014/06/03 19:30:30 joerg Exp $");
 
 #include "opt_ddb.h"
 #include "opt_revcache.h"
@@ -565,6 +565,7 @@
 {
        struct namecache *ncp;
        struct vnode *dvp;
+       struct nchcpu *cpup;
        struct ncvhashhead *nvcpp;
        char *bp;
        int error, nlen;
@@ -573,6 +574,7 @@
                goto out;
 
        nvcpp = &ncvhashtbl[NCVHASH(vp)];
+       cpup = curcpu()->ci_data.cpu_nch;
 
        mutex_enter(namecache_lock);
        LIST_FOREACH(ncp, nvcpp, nc_vhash) {
@@ -591,7 +593,9 @@
                            ncp->nc_name[1] == '.')
                                panic("cache_revlookup: found entry for ..");
 #endif
-                       COUNT(nchstats, ncs_revhits);
+                       mutex_enter(&cpup->cpu_lock);
+                       COUNT(cpup->cpu_stats, ncs_revhits);
+                       mutex_exit(&cpup->cpu_lock);
                        nlen = ncp->nc_nlen;
 
                        if (bufp) {
@@ -623,7 +627,9 @@
                }
                mutex_exit(&ncp->nc_lock);
        }
-       COUNT(nchstats, ncs_revmiss);
+       mutex_enter(&cpup->cpu_lock);
+       COUNT(cpup->cpu_stats, ncs_revmiss);
+       mutex_exit(&cpup->cpu_lock);
        mutex_exit(namecache_lock);
  out:
        *dvpp = NULL;
@@ -1065,3 +1071,23 @@
        }
 }
 #endif
+
+void
+namecache_count_pass2(void)
+{
+       struct nchcpu *cpup = curcpu()->ci_data.cpu_nch;
+
+       mutex_enter(&cpup->cpu_lock);
+       COUNT(cpup->cpu_stats, ncs_pass2);
+       mutex_exit(&cpup->cpu_lock);
+}
+
+void
+namecache_count_2passes(void)
+{
+       struct nchcpu *cpup = curcpu()->ci_data.cpu_nch;
+
+       mutex_enter(&cpup->cpu_lock);
+       COUNT(cpup->cpu_stats, ncs_2passes);
+       mutex_exit(&cpup->cpu_lock);
+}
diff -r d3ab9db9e7b0 -r f6d91fd057bf sys/sys/namei.src
--- a/sys/sys/namei.src Tue Jun 03 15:56:14 2014 +0000
+++ b/sys/sys/namei.src Tue Jun 03 19:30:29 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: namei.src,v 1.31 2012/11/18 18:25:08 dholland Exp $    */
+/*     $NetBSD: namei.src,v 1.32 2014/06/03 19:30:29 joerg Exp $       */
 
 /*
  * Copyright (c) 1985, 1989, 1991, 1993
@@ -278,6 +278,8 @@
                        const char *, size_t, uint32_t);
 void   nchinit(void);
 void   nchreinit(void);
+void   namecache_count_pass2(void);
+void   namecache_count_2passes(void);
 void   cache_cpu_init(struct cpu_info *);
 void   cache_purgevfs(struct mount *);
 void   namecache_print(struct vnode *, void (*)(const char *, ...)
diff -r d3ab9db9e7b0 -r f6d91fd057bf sys/ufs/ext2fs/ext2fs_lookup.c
--- a/sys/ufs/ext2fs/ext2fs_lookup.c    Tue Jun 03 15:56:14 2014 +0000
+++ b/sys/ufs/ext2fs/ext2fs_lookup.c    Tue Jun 03 19:30:29 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ext2fs_lookup.c,v 1.76 2014/05/25 14:07:19 hannken Exp $       */
+/*     $NetBSD: ext2fs_lookup.c,v 1.77 2014/06/03 19:30:29 joerg Exp $ */
 
 /*
  * Modified for NetBSD 1.2E
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ext2fs_lookup.c,v 1.76 2014/05/25 14:07:19 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_lookup.c,v 1.77 2014/06/03 19:30:29 joerg Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -366,7 +366,7 @@
                    (error = ext2fs_blkatoff(vdp, (off_t)results->ulr_offset, NULL, &bp)))
                        return (error);
                numdirpasses = 2;
-               nchstats.ncs_2passes++;
+               namecache_count_2passes();
        }
        prevoff = results->ulr_offset;
        endsearch = roundup(ext2fs_size(dp), dirblksiz);
@@ -547,7 +547,7 @@
 
 found:
        if (numdirpasses == 2)
-               nchstats.ncs_pass2++;
+               namecache_count_pass2();
        /*
         * Check that directory length properly reflects presence
         * of this entry.
diff -r d3ab9db9e7b0 -r f6d91fd057bf sys/ufs/lfs/ulfs_lookup.c
--- a/sys/ufs/lfs/ulfs_lookup.c Tue Jun 03 15:56:14 2014 +0000
+++ b/sys/ufs/lfs/ulfs_lookup.c Tue Jun 03 19:30:29 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ulfs_lookup.c,v 1.20 2014/05/25 13:49:13 hannken Exp $ */
+/*     $NetBSD: ulfs_lookup.c,v 1.21 2014/06/03 19:30:30 joerg Exp $   */
 /*  from NetBSD: ufs_lookup.c,v 1.122 2013/01/22 09:39:18 dholland Exp  */
 
 /*
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ulfs_lookup.c,v 1.20 2014/05/25 13:49:13 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_lookup.c,v 1.21 2014/06/03 19:30:30 joerg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lfs.h"
@@ -288,7 +288,7 @@
                    NULL, &bp, false)))
                        goto out;
                numdirpasses = 2;
-               nchstats.ncs_2passes++;
+               namecache_count_2passes();
        }
        prevoff = results->ulr_offset;
        endsearch = roundup(dp->i_size, dirblksiz);
@@ -524,7 +524,7 @@
 
 found:
        if (numdirpasses == 2)
-               nchstats.ncs_pass2++;
+               namecache_count_pass2();
        /*
         * Check that directory length properly reflects presence
         * of this entry.
diff -r d3ab9db9e7b0 -r f6d91fd057bf sys/ufs/ufs/ufs_lookup.c
--- a/sys/ufs/ufs/ufs_lookup.c  Tue Jun 03 15:56:14 2014 +0000
+++ b/sys/ufs/ufs/ufs_lookup.c  Tue Jun 03 19:30:29 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_lookup.c,v 1.131 2014/05/25 13:48:40 hannken Exp $ */
+/*     $NetBSD: ufs_lookup.c,v 1.132 2014/06/03 19:30:30 joerg Exp $   */
 
 /*
  * Copyright (c) 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.131 2014/05/25 13:48:40 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.132 2014/06/03 19:30:30 joerg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ffs.h"
@@ -286,7 +286,7 @@
                    NULL, &bp, false)))
                        goto out;
                numdirpasses = 2;
-               nchstats.ncs_2passes++;
+               namecache_count_2passes();
        }
        prevoff = results->ulr_offset;
        endsearch = roundup(dp->i_size, dirblksiz);
@@ -522,7 +522,7 @@
 
 found:
        if (numdirpasses == 2)
-               nchstats.ncs_pass2++;
+               namecache_count_pass2();
        /*
         * Check that directory length properly reflects presence
         * of this entry.



Home | Main Index | Thread Index | Old Index