Source-Changes-HG archive

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

[src/trunk]: src/sys/ufs Keep per-inode, per-fs, and subsystem-wide counts of...



details:   https://anonhg.NetBSD.org/src/rev/f956b9e6988e
branches:  trunk
changeset: 580347:f956b9e6988e
user:      perseant <perseant%NetBSD.org@localhost>
date:      Tue Apr 19 20:59:05 2005 +0000

description:
Keep per-inode, per-fs, and subsystem-wide counts of blocks allocated through
lfs_balloc(), and use that to estimate the number of dirty pages belonging
to LFS (subsystem or filesystem).  This is almost certainly wrong for
the case of a large mmap()ed region, but the accounting is tighter than
what we had before, and performs much better in the typical case of pages
dirtied through write().

diffstat:

 sys/ufs/lfs/lfs.h           |   9 ++++++---
 sys/ufs/lfs/lfs_alloc.c     |   5 +++--
 sys/ufs/lfs/lfs_balloc.c    |  12 ++++++++++--
 sys/ufs/lfs/lfs_bio.c       |  10 +++-------
 sys/ufs/lfs/lfs_segment.c   |  12 ++++++------
 sys/ufs/lfs/lfs_vfsops.c    |  26 +++++++++-----------------
 sys/ufs/lfs/lfs_vnops.c     |   8 ++------
 sys/ufs/ufs/ufs_readwrite.c |  14 ++------------
 8 files changed, 41 insertions(+), 55 deletions(-)

diffs (truncated from 329 to 300 lines):

diff -r 30c25da64250 -r f956b9e6988e sys/ufs/lfs/lfs.h
--- a/sys/ufs/lfs/lfs.h Tue Apr 19 20:14:29 2005 +0000
+++ b/sys/ufs/lfs/lfs.h Tue Apr 19 20:59:05 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs.h,v 1.84 2005/04/16 19:52:09 perseant Exp $        */
+/*     $NetBSD: lfs.h,v 1.85 2005/04/19 20:59:05 perseant Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -366,7 +366,8 @@
 
 /* Heuristic emptiness measure */
 #define VPISEMPTY(vp)   (LIST_EMPTY(&(vp)->v_dirtyblkhd) &&            \
-                         !((vp)->v_flag & VONWORKLST))
+                         !((vp)->v_flag & VONWORKLST) &&               \
+                         VTOI(vp)->i_lfs_nbtree == 0)
 
 /* XXX Shouldn't we use v_numoutput instead? */
 #define WRITEINPROG(vp) (!LIST_EMPTY(&(vp)->v_dirtyblkhd) &&           \
@@ -943,7 +944,7 @@
 };
 
 /*
- * List containing block numbers allocated through lfs_balloc.
+ * Splay tree containing block numbers allocated through lfs_balloc.
  */
 struct lbnentry {
        SPLAY_ENTRY(lbnentry) entry;
@@ -965,6 +966,7 @@
        daddr_t   lfs_hiblk;            /* Highest lbn held by inode */
 #ifdef _KERNEL
        SPLAY_HEAD(lfs_splay, lbnentry) lfs_lbtree; /* Tree of balloc'd lbns */
+       int       lfs_nbtree;           /* Size of tree */
 #endif
 };
 #define i_lfs_osize            inode_ext.lfs->lfs_osize
@@ -974,6 +976,7 @@
 #define i_lfs_iflags           inode_ext.lfs->lfs_iflags
 #define i_lfs_hiblk            inode_ext.lfs->lfs_hiblk
 #define i_lfs_lbtree           inode_ext.lfs->lfs_lbtree
+#define i_lfs_nbtree           inode_ext.lfs->lfs_nbtree
 
 /*
  * Macros for determining free space on the disk, with the variable metadata
diff -r 30c25da64250 -r f956b9e6988e sys/ufs/lfs/lfs_alloc.c
--- a/sys/ufs/lfs/lfs_alloc.c   Tue Apr 19 20:14:29 2005 +0000
+++ b/sys/ufs/lfs/lfs_alloc.c   Tue Apr 19 20:59:05 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_alloc.c,v 1.81 2005/04/16 17:35:58 perseant Exp $  */
+/*     $NetBSD: lfs_alloc.c,v 1.82 2005/04/19 20:59:05 perseant Exp $  */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.81 2005/04/16 17:35:58 perseant Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.82 2005/04/19 20:59:05 perseant Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -443,6 +443,7 @@
        ip->i_lfs = ump->um_lfs;
        ip->i_lfs_effnblks = 0;
        SPLAY_INIT(&ip->i_lfs_lbtree);
+       ip->i_lfs_nbtree = 0;
 #ifdef QUOTA
        for (i = 0; i < MAXQUOTAS; i++)
                ip->i_dquot[i] = NODQUOT;
diff -r 30c25da64250 -r f956b9e6988e sys/ufs/lfs/lfs_balloc.c
--- a/sys/ufs/lfs/lfs_balloc.c  Tue Apr 19 20:14:29 2005 +0000
+++ b/sys/ufs/lfs/lfs_balloc.c  Tue Apr 19 20:59:05 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_balloc.c,v 1.55 2005/04/16 17:35:58 perseant Exp $ */
+/*     $NetBSD: lfs_balloc.c,v 1.56 2005/04/19 20:59:05 perseant Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.55 2005/04/16 17:35:58 perseant Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.56 2005/04/19 20:59:05 perseant Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -530,9 +530,14 @@
                return;
        }
 
+       ++ip->i_lfs_nbtree;
        simple_lock(&fs->lfs_interlock);
        fs->lfs_favail += btofsb(fs, (1 << fs->lfs_bshift));
+       fs->lfs_pages += fs->lfs_bsize >> PAGE_SHIFT;
+       simple_lock(&lfs_subsys_lock);
        ++locked_fakequeue_count;
+       lfs_subsys_pages += fs->lfs_bsize >> PAGE_SHIFT;
+       simple_unlock(&lfs_subsys_lock);
        simple_unlock(&fs->lfs_interlock);
 }
 
@@ -541,14 +546,17 @@
 {
        ASSERT_MAYBE_SEGLOCK(fs);
 
+       --ip->i_lfs_nbtree;
        SPLAY_REMOVE(lfs_splay, &ip->i_lfs_lbtree, lbp);
        pool_put(&lfs_lbnentry_pool, lbp);
        simple_lock(&fs->lfs_interlock);
        if (fs->lfs_favail > btofsb(fs, (1 << fs->lfs_bshift)))
                fs->lfs_favail -= btofsb(fs, (1 << fs->lfs_bshift));
+       fs->lfs_pages -= fs->lfs_bsize >> PAGE_SHIFT;
        simple_lock(&lfs_subsys_lock);
        if (locked_fakequeue_count > 0)
                --locked_fakequeue_count;
+       lfs_subsys_pages -= fs->lfs_bsize >> PAGE_SHIFT;
        simple_unlock(&lfs_subsys_lock);
        simple_unlock(&fs->lfs_interlock);
 }
diff -r 30c25da64250 -r f956b9e6988e sys/ufs/lfs/lfs_bio.c
--- a/sys/ufs/lfs/lfs_bio.c     Tue Apr 19 20:14:29 2005 +0000
+++ b/sys/ufs/lfs/lfs_bio.c     Tue Apr 19 20:59:05 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_bio.c,v 1.83 2005/04/06 04:30:46 perseant Exp $    */
+/*     $NetBSD: lfs_bio.c,v 1.84 2005/04/19 20:59:05 perseant Exp $    */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.83 2005/04/06 04:30:46 perseant Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.84 2005/04/19 20:59:05 perseant Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -522,13 +522,9 @@
                return;
 
        simple_lock(&lfs_subsys_lock);
-       lfs_subsys_pages -= fs->lfs_pages; /* XXXUBC */
-       if (lfs_subsys_pages < 0)          /* XXXUBC */
-               lfs_subsys_pages = 0;      /* XXXUBC */
        if (lfs_dostats)
                ++lfs_stats.flush_invoked;
        simple_unlock(&lfs_subsys_lock);
-       fs->lfs_pages = 0; /* XXXUBC need a better way to count this */
 
        simple_unlock(&fs->lfs_interlock);
        lfs_writer_enter(fs, "fldirop");
@@ -561,7 +557,7 @@
        if (lfs_dostats)
                ++lfs_stats.write_exceeded;
        /* XXX should we include SEGM_CKP here? */
-       if (lfs_writing && !(flags & (SEGM_SYNC | SEGM_WRITERD))) {
+       if (lfs_writing && !(flags & SEGM_SYNC)) {
                DLOG((DLOG_FLUSH, "lfs_flush: not flushing because another flush is active\n"));
                return;
        }
diff -r 30c25da64250 -r f956b9e6988e sys/ufs/lfs/lfs_segment.c
--- a/sys/ufs/lfs/lfs_segment.c Tue Apr 19 20:14:29 2005 +0000
+++ b/sys/ufs/lfs/lfs_segment.c Tue Apr 19 20:59:05 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_segment.c,v 1.161 2005/04/18 23:03:08 perseant Exp $       */
+/*     $NetBSD: lfs_segment.c,v 1.162 2005/04/19 20:59:05 perseant Exp $       */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.161 2005/04/18 23:03:08 perseant Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.162 2005/04/19 20:59:05 perseant Exp $");
 
 #ifdef DEBUG
 # define vndebug(vp, str) do {                                         \
@@ -1109,12 +1109,12 @@
        /* Insert into the buffer list, update the FINFO block. */
        bp->b_flags |= B_GATHERED;
 
-       /* This block's accounting moves from lfs_favail to lfs_avail */
-       lfs_deregister_block(sp->vp, bp->b_lblkno);
-
        *sp->cbpp++ = bp;
-       for (j = 0; j < blksinblk; j++)
+       for (j = 0; j < blksinblk; j++) {
                sp->fip->fi_blocks[sp->fip->fi_nblocks++] = bp->b_lblkno + j;
+               /* This block's accounting moves from lfs_favail to lfs_avail */
+               lfs_deregister_block(sp->vp, bp->b_lblkno + j);
+       }
 
        sp->sum_bytes_left -= sizeof(int32_t) * blksinblk;
        sp->seg_bytes_left -= bp->b_bcount;
diff -r 30c25da64250 -r f956b9e6988e sys/ufs/lfs/lfs_vfsops.c
--- a/sys/ufs/lfs/lfs_vfsops.c  Tue Apr 19 20:14:29 2005 +0000
+++ b/sys/ufs/lfs/lfs_vfsops.c  Tue Apr 19 20:59:05 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_vfsops.c,v 1.175 2005/04/16 18:10:12 perseant Exp $        */
+/*     $NetBSD: lfs_vfsops.c,v 1.176 2005/04/19 20:59:05 perseant Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.175 2005/04/16 18:10:12 perseant Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.176 2005/04/19 20:59:05 perseant Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -196,7 +196,7 @@
 
        simple_lock(&lfs_subsys_lock);
        for (;;) {
-               ltsleep(&lfs_writer_daemon, PVM | PNORELOCK, "lfswriter", 0,
+               ltsleep(&lfs_writer_daemon, PVM | PNORELOCK, "lfswriter", hz/10,
                    &lfs_subsys_lock);
 
                /*
@@ -234,7 +234,7 @@
                 */
                simple_lock(&lfs_subsys_lock);
                loopcount = 0;
-               while (lfs_do_flush || locked_queue_count > LFS_MAX_BUFS ||
+               if (lfs_do_flush || locked_queue_count > LFS_MAX_BUFS ||
                        locked_queue_bytes > LFS_MAX_BYTES ||
                        lfs_subsys_pages > LFS_MAX_PAGES) {
 
@@ -252,19 +252,6 @@
 
                        lfs_flush(NULL, SEGM_WRITERD, 0);
                        lfs_do_flush = 0;
-                       if (++loopcount > 10) {
-                               printf("lfs_writer_daemon: livelock: "
-                                       "lqc = %lld (of %lld), "
-                                       "lqb = %lld (of %lld), "
-                                       "lsp = %lld (of %lld)\n",
-                                       (long long)locked_queue_count,
-                                       (long long)LFS_MAX_BUFS,
-                                       (long long)locked_queue_bytes,
-                                       (long long)LFS_MAX_BYTES,
-                                       (long long)lfs_subsys_pages,
-                                       (long long)LFS_MAX_PAGES);
-                               break;
-                       }
                }
        }
        /* NOTREACHED */
@@ -1424,6 +1411,11 @@
            ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
        vput(ump->um_devvp);
 
+       /* Complain about page leakage */
+       if (fs->lfs_pages > 0)
+               printf("lfs_unmount: still claim %d pages (%d in subsystem)\n",
+                       fs->lfs_pages, lfs_subsys_pages);
+
        /* Free per-mount data structures */
        free(fs->lfs_suflags[0], M_SEGMENT);
        free(fs->lfs_suflags[1], M_SEGMENT);
diff -r 30c25da64250 -r f956b9e6988e sys/ufs/lfs/lfs_vnops.c
--- a/sys/ufs/lfs/lfs_vnops.c   Tue Apr 19 20:14:29 2005 +0000
+++ b/sys/ufs/lfs/lfs_vnops.c   Tue Apr 19 20:59:05 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_vnops.c,v 1.146 2005/04/18 17:36:46 perseant Exp $ */
+/*     $NetBSD: lfs_vnops.c,v 1.147 2005/04/19 20:59:05 perseant Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.146 2005/04/18 17:36:46 perseant Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.147 2005/04/19 20:59:05 perseant Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1528,10 +1528,6 @@
                        if (dirty) {
                                pg->flags &= ~PG_CLEAN;
                                if (flags & PGO_FREE) {
-                                       /* XXXUBC need better way to update */
-                                       simple_lock(&lfs_subsys_lock);
-                                       lfs_subsys_pages += MIN(1, pages_per_block);
-                                       simple_unlock(&lfs_subsys_lock);
                                        /*
                                         * Wire the page so that
                                         * pdaemon doesn't see it again.
diff -r 30c25da64250 -r f956b9e6988e sys/ufs/ufs/ufs_readwrite.c
--- a/sys/ufs/ufs/ufs_readwrite.c       Tue Apr 19 20:14:29 2005 +0000
+++ b/sys/ufs/ufs/ufs_readwrite.c       Tue Apr 19 20:59:05 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_readwrite.c,v 1.62 2005/04/01 21:59:47 perseant Exp $      */
+/*     $NetBSD: ufs_readwrite.c,v 1.63 2005/04/19 20:59:05 perseant Exp $      */



Home | Main Index | Thread Index | Old Index