Source-Changes-HG archive

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

[src/trunk]: src/sys move some buffer cache internals declarations from buf.h...



details:   https://anonhg.NetBSD.org/src/rev/16c62c2ec2d4
branches:  trunk
changeset: 824516:16c62c2ec2d4
user:      chs <chs%NetBSD.org@localhost>
date:      Thu Jun 08 01:23:01 2017 +0000

description:
move some buffer cache internals declarations from buf.h to vfs_bio.c.
this is needed to avoid name conflicts with ZFS and also
makes it clearer that other code shouldn't be messing with these.
remove the LFS debug code that poked around in bufqueues and
remove the BQ_EMPTY bufqueue since nothing uses it anymore.
provide a function to let LFS and wapbl read the value of nbuf for now.

diffstat:

 sys/kern/vfs_bio.c       |  34 ++++++++++++++++++++++++----
 sys/kern/vfs_wapbl.c     |   6 ++--
 sys/sys/buf.h            |  23 +-----------------
 sys/ufs/lfs/lfs_balloc.c |   5 +--
 sys/ufs/lfs/lfs_bio.c    |  57 +++++++++++++----------------------------------
 sys/ufs/lfs/lfs_extern.h |   4 ++-
 sys/ufs/lfs/lfs_inode.h  |  13 +----------
 sys/ufs/lfs/lfs_subr.c   |  10 +++-----
 sys/ufs/lfs/ulfs_inode.h |   6 ++--
 9 files changed, 63 insertions(+), 95 deletions(-)

diffs (truncated from 354 to 300 lines):

diff -r 5e20db6ee959 -r 16c62c2ec2d4 sys/kern/vfs_bio.c
--- a/sys/kern/vfs_bio.c        Thu Jun 08 01:09:52 2017 +0000
+++ b/sys/kern/vfs_bio.c        Thu Jun 08 01:23:01 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_bio.c,v 1.273 2017/05/25 02:28:07 pgoyette Exp $   */
+/*     $NetBSD: vfs_bio.c,v 1.274 2017/06/08 01:23:01 chs Exp $        */
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -123,7 +123,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.273 2017/05/25 02:28:07 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.274 2017/06/08 01:23:01 chs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bufcache.h"
@@ -170,9 +170,23 @@
 u_int  bufpages = BUFPAGES;    /* optional hardwired count */
 u_int  bufcache = BUFCACHE;    /* max % of RAM to use for buffer cache */
 
+/*
+ * Definitions for the buffer free lists.
+ */
+#define        BQUEUES         3               /* number of free buffer queues */
+
+#define        BQ_LOCKED       0               /* super-blocks &c */
+#define        BQ_LRU          1               /* lru, useful buffers */
+#define        BQ_AGE          2               /* rubbish */
+
+struct bqueue {
+       TAILQ_HEAD(, buf) bq_queue;
+       uint64_t bq_bytes;
+       buf_t *bq_marker;
+};
+static struct bqueue bufqueues[BQUEUES];
+
 /* Function prototypes */
-struct bqueue;
-
 static void buf_setwm(void);
 static int buf_trim(void);
 static void *bufpool_page_alloc(struct pool *, int);
@@ -217,7 +231,6 @@
        (&bufhashtbl[(((long)(dvp) >> 8) + (int)(lbn)) & bufhash])
 LIST_HEAD(bufhashhdr, buf) *bufhashtbl, invalhash;
 u_long bufhash;
-struct bqueue bufqueues[BQUEUES];
 
 static kcondvar_t needbuffer_cv;
 
@@ -2136,3 +2149,14 @@
 
        return 0;
 }
+
+/*
+ * Nothing outside this file should really need to know about nbuf,
+ * but a few things still want to read it, so give them a way to do that.
+ */
+int
+buf_nbuf(void)
+{
+
+       return nbuf;
+}
diff -r 5e20db6ee959 -r 16c62c2ec2d4 sys/kern/vfs_wapbl.c
--- a/sys/kern/vfs_wapbl.c      Thu Jun 08 01:09:52 2017 +0000
+++ b/sys/kern/vfs_wapbl.c      Thu Jun 08 01:23:01 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_wapbl.c,v 1.96 2017/04/10 21:36:05 jdolecek Exp $  */
+/*     $NetBSD: vfs_wapbl.c,v 1.97 2017/06/08 01:23:01 chs Exp $       */
 
 /*-
  * Copyright (c) 2003, 2008, 2009 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #define WAPBL_INTERNAL
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_wapbl.c,v 1.96 2017/04/10 21:36:05 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_wapbl.c,v 1.97 2017/06/08 01:23:01 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/bitops.h>
@@ -612,7 +612,7 @@
 
        /* XXX maybe use filesystem fragment size instead of 1024 */
        /* XXX fix actual number of buffers reserved per filesystem. */
-       wl->wl_bufcount_max = (nbuf / 2) * 1024;
+       wl->wl_bufcount_max = (buf_nbuf() / 2) * 1024;
 
        wl->wl_brperjblock = ((1<<wl->wl_log_dev_bshift)
            - offsetof(struct wapbl_wc_blocklist, wc_blocks)) /
diff -r 5e20db6ee959 -r 16c62c2ec2d4 sys/sys/buf.h
--- a/sys/sys/buf.h     Thu Jun 08 01:09:52 2017 +0000
+++ b/sys/sys/buf.h     Thu Jun 08 01:23:01 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: buf.h,v 1.128 2017/04/10 19:52:38 jdolecek Exp $ */
+/*     $NetBSD: buf.h,v 1.129 2017/06/08 01:23:01 chs Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc.
@@ -257,26 +257,6 @@
 #define        BPRIO_TIMENONCRITICAL   0
 #define        BPRIO_DEFAULT           BPRIO_TIMELIMITED
 
-extern u_int nbuf;             /* The number of buffer headers */
-
-/*
- * Definitions for the buffer free lists.
- */
-#define        BQUEUES         4               /* number of free buffer queues */
-
-#define        BQ_LOCKED       0               /* super-blocks &c */
-#define        BQ_LRU          1               /* lru, useful buffers */
-#define        BQ_AGE          2               /* rubbish */
-#define        BQ_EMPTY        3               /* buffer headers with no memory */
-
-struct bqueue {
-       TAILQ_HEAD(, buf) bq_queue;
-       uint64_t bq_bytes;
-       buf_t *bq_marker;
-};
-
-extern struct bqueue bufqueues[BQUEUES];
-
 __BEGIN_DECLS
 /*
  * bufferio(9) ops
@@ -330,6 +310,7 @@
 void   buf_init(buf_t *);
 void   buf_destroy(buf_t *);
 int    bbusy(buf_t *, bool, int, kmutex_t *);
+int    buf_nbuf(void);
 
 void   biohist_init(void);
 
diff -r 5e20db6ee959 -r 16c62c2ec2d4 sys/ufs/lfs/lfs_balloc.c
--- a/sys/ufs/lfs/lfs_balloc.c  Thu Jun 08 01:09:52 2017 +0000
+++ b/sys/ufs/lfs/lfs_balloc.c  Thu Jun 08 01:23:01 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_balloc.c,v 1.92 2017/04/06 02:38:08 maya Exp $     */
+/*     $NetBSD: lfs_balloc.c,v 1.93 2017/06/08 01:23:01 chs Exp $      */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.92 2017/04/06 02:38:08 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.93 2017/06/08 01:23:01 chs Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -527,7 +527,6 @@
     top:
        if (bpp) {
                rw_enter(&fs->lfs_fraglock, RW_READER);
-               LFS_DEBUG_COUNTLOCKED("frag");
        }
 
        /* check if we actually have enough frags available */
diff -r 5e20db6ee959 -r 16c62c2ec2d4 sys/ufs/lfs/lfs_bio.c
--- a/sys/ufs/lfs/lfs_bio.c     Thu Jun 08 01:09:52 2017 +0000
+++ b/sys/ufs/lfs/lfs_bio.c     Thu Jun 08 01:23:01 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_bio.c,v 1.139 2017/04/17 08:32:01 hannken Exp $    */
+/*     $NetBSD: lfs_bio.c,v 1.140 2017/06/08 01:23:01 chs Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.139 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.140 2017/06/08 01:23:01 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -307,6 +307,20 @@
 }
 
 int
+lfs_max_bufs(void)
+{
+
+       return LFS_MAX_RESOURCE(buf_nbuf(), 1);
+}
+
+int
+lfs_wait_bufs(void)
+{
+
+       return LFS_WAIT_RESOURCE(buf_nbuf(), 1);
+}
+
+int
 lfs_bwrite(void *v)
 {
        struct vop_bwrite_args /* {
@@ -556,7 +570,6 @@
                }
                mountlist_iterator_destroy(iter);
        }
-       LFS_DEBUG_COUNTLOCKED("flush");
        wakeup(&lfs_subsys_pages);
 
     errout:
@@ -749,44 +762,6 @@
        putiobuf(bp);
 }
 
-/*
- * Count buffers on the "locked" queue, and compare it to a pro-forma count.
- * Don't count malloced buffers, since they don't detract from the total.
- */
-void
-lfs_countlocked(int *count, long *bytes, const char *msg)
-{
-       struct buf *bp;
-       int n = 0;
-       long int size = 0L;
-
-       mutex_enter(&bufcache_lock);
-       TAILQ_FOREACH(bp, &bufqueues[BQ_LOCKED].bq_queue, b_freelist) {
-               KASSERT(bp->b_iodone == NULL);
-               n++;
-               size += bp->b_bufsize;
-               KASSERTMSG((n <= nbuf),
-                   "lfs_countlocked: this can't happen: more"
-                   " buffers locked than exist");
-       }
-       /*
-        * Theoretically this function never really does anything.
-        * Give a warning if we have to fix the accounting.
-        */
-       if (n != *count) {
-               DLOG((DLOG_LLIST, "lfs_countlocked: %s: adjusted buf count"
-                     " from %d to %d\n", msg, *count, n));
-       }
-       if (size != *bytes) {
-               DLOG((DLOG_LLIST, "lfs_countlocked: %s: adjusted byte count"
-                     " from %ld to %ld\n", msg, *bytes, size));
-       }
-       *count = n;
-       *bytes = size;
-       mutex_exit(&bufcache_lock);
-       return;
-}
-
 int
 lfs_wait_pages(void)
 {
diff -r 5e20db6ee959 -r 16c62c2ec2d4 sys/ufs/lfs/lfs_extern.h
--- a/sys/ufs/lfs/lfs_extern.h  Thu Jun 08 01:09:52 2017 +0000
+++ b/sys/ufs/lfs/lfs_extern.h  Thu Jun 08 01:23:01 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_extern.h,v 1.111 2016/06/20 03:29:52 dholland Exp $        */
+/*     $NetBSD: lfs_extern.h,v 1.112 2017/06/08 01:23:01 chs Exp $     */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -149,6 +149,8 @@
 struct buf *lfs_newbuf(struct lfs *, struct vnode *, daddr_t, size_t, int);
 void lfs_countlocked(int *, long *, const char *);
 int lfs_reserve(struct lfs *, struct vnode *, struct vnode *, int);
+int lfs_max_bufs(void);
+int lfs_wait_bufs(void);
 
 /* lfs_debug.c */
 #ifdef DEBUG
diff -r 5e20db6ee959 -r 16c62c2ec2d4 sys/ufs/lfs/lfs_inode.h
--- a/sys/ufs/lfs/lfs_inode.h   Thu Jun 08 01:09:52 2017 +0000
+++ b/sys/ufs/lfs/lfs_inode.h   Thu Jun 08 01:23:01 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_inode.h,v 1.21 2017/06/05 07:47:32 maya Exp $      */
+/*     $NetBSD: lfs_inode.h,v 1.22 2017/06/08 01:23:01 chs Exp $       */
 /*  from NetBSD: ulfs_inode.h,v 1.5 2013/06/06 00:51:50 dholland Exp  */
 /*  from NetBSD: inode.h,v 1.72 2016/06/03 15:36:03 christos Exp  */
 
@@ -216,17 +216,6 @@
 
 # define LFS_IS_MALLOC_BUF(bp) ((bp)->b_iodone == lfs_callback)
 
-# ifdef DEBUG
-#  define LFS_DEBUG_COUNTLOCKED(m) do {                                        \
-       if (lfs_debug_log_subsys[DLOG_LLIST]) {                         \
-               lfs_countlocked(&locked_queue_count, &locked_queue_bytes, (m)); \
-               cv_broadcast(&locked_queue_cv);                         \
-       }                                                               \
-} while (0)
-# else
-#  define LFS_DEBUG_COUNTLOCKED(m)
-# endif
-
 /* log for debugging writes to the Ifile */
 # ifdef DEBUG



Home | Main Index | Thread Index | Old Index