Source-Changes-HG archive

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

[src/trunk]: src/sys/ufs For synchronous writes, keep separate i/o counters f...



details:   https://anonhg.NetBSD.org/src/rev/586d0373ef55
branches:  trunk
changeset: 532834:586d0373ef55
user:      perseant <perseant%NetBSD.org@localhost>
date:      Sun Jun 16 00:13:15 2002 +0000

description:
For synchronous writes, keep separate i/o counters for each write, so
processes don't have to wait for one another to finish (e.g., nfsd seems
to be a little happier now, though I haven't measured the difference).
Synchronous checkpoints, however, must always wait for all i/o to finish.

Take the contents of the callback functions and have them run in thread
context instead (aiodoned thread).  lfs_iocount no longer has to be
protected in splbio(), and quite a bit less of the segment construction
loop needs to be in splbio() as well.

If lfs_markv is handed a block that is not the correct size according to
the inode, refuse to process it.  (Formerly it was extended to the "correct"
size.)  This is possibly more prone to deadlock, but less prone to corruption.

lfs_segclean now outright refuses to clean segments that appear to have live
bytes in them.  Again this may be more prone to deadlock but avoids
corruption.

Replace ufsspec_close and ufsfifo_close with LFS equivalents; this means
that no UFS functions need to know about LFS_ITIMES any more.  Remove
the reference from ufs/inode.h.

Tested on i386, test-compiled on alpha.

diffstat:

 sys/ufs/lfs/lfs.h          |    5 +-
 sys/ufs/lfs/lfs_cksum.c    |    5 +-
 sys/ufs/lfs/lfs_extern.h   |   56 +++++++++++-----------
 sys/ufs/lfs/lfs_segment.c  |  109 ++++++++++++++++++++++++++++----------------
 sys/ufs/lfs/lfs_subr.c     |   43 +++++++++++-----
 sys/ufs/lfs/lfs_syscalls.c |   39 +++++++++++----
 sys/ufs/lfs/lfs_vfsops.c   |    8 +--
 sys/ufs/lfs/lfs_vnops.c    |   64 +++++++++++++++++++++++--
 sys/ufs/ufs/inode.h        |   17 +------
 9 files changed, 222 insertions(+), 124 deletions(-)

diffs (truncated from 831 to 300 lines):

diff -r ef86c77a2247 -r 586d0373ef55 sys/ufs/lfs/lfs.h
--- a/sys/ufs/lfs/lfs.h Sat Jun 15 21:49:18 2002 +0000
+++ b/sys/ufs/lfs/lfs.h Sun Jun 16 00:13:15 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs.h,v 1.39 2002/05/14 20:03:53 perseant Exp $        */
+/*     $NetBSD: lfs.h,v 1.40 2002/06/16 00:13:15 perseant Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -765,6 +765,7 @@
 #define        SEGM_SYNC       0x04            /* wait for segment */
 #define        SEGM_PROT       0x08            /* don't inactivate at segunlock */
        u_int16_t seg_flags;            /* run-time flags for this segment */
+       u_int32_t seg_iocount;          /* number of ios pending */
 };
 
 struct lfs_cluster {
@@ -773,8 +774,10 @@
        size_t bufsize;        /* Size of kept data */
 #define LFS_CL_MALLOC  0x00000001
 #define LFS_CL_SHIFT   0x00000002
+#define LFS_CL_SYNC    0x00000004
        u_int32_t flags;       /* Flags */
        struct lfs *fs;        /* LFS that this belongs to */
+       struct segment *seg;   /* Segment structure, for LFS_CL_SYNC */
        void *saveaddr;        /* Original contents of saveaddr */
        char *olddata;          /* Original b_data, if LFS_CL_MALLOC */
 };
diff -r ef86c77a2247 -r 586d0373ef55 sys/ufs/lfs/lfs_cksum.c
--- a/sys/ufs/lfs/lfs_cksum.c   Sat Jun 15 21:49:18 2002 +0000
+++ b/sys/ufs/lfs/lfs_cksum.c   Sun Jun 16 00:13:15 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_cksum.c,v 1.19 2001/11/15 09:48:29 lukem Exp $     */
+/*     $NetBSD: lfs_cksum.c,v 1.20 2002/06/16 00:13:15 perseant Exp $  */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_cksum.c,v 1.19 2001/11/15 09:48:29 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_cksum.c,v 1.20 2002/06/16 00:13:15 perseant Exp $");
 
 #include <sys/param.h>
 #ifdef _KERNEL
@@ -83,6 +83,7 @@
 #include <sys/mount.h>
 #include <ufs/ufs/inode.h>
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_extern.h>
 
 /*
  * Simple, general purpose, fast checksum.  Data must be short-aligned.
diff -r ef86c77a2247 -r 586d0373ef55 sys/ufs/lfs/lfs_extern.h
--- a/sys/ufs/lfs/lfs_extern.h  Sat Jun 15 21:49:18 2002 +0000
+++ b/sys/ufs/lfs/lfs_extern.h  Sun Jun 16 00:13:15 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_extern.h,v 1.30 2002/05/14 20:03:53 perseant Exp $ */
+/*     $NetBSD: lfs_extern.h,v 1.31 2002/06/16 00:13:15 perseant Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -204,32 +204,34 @@
 void lfs_itimes(struct inode *, struct timespec *, struct timespec *,
                struct timespec *);
 
-int lfs_balloc (void *);
-int lfs_valloc (void *);
-int lfs_vfree  (void *);
-int lfs_bwrite (void *);
-int lfs_update (void *);
-int lfs_truncate(void *);
-int lfs_blkatoff(void *);
-int lfs_fsync  (void *);
-int lfs_symlink        (void *);
-int lfs_mknod  (void *);
-int lfs_create (void *);
-int lfs_mkdir  (void *);
-int lfs_read   (void *);
-int lfs_remove (void *);
-int lfs_rmdir  (void *);
-int lfs_link   (void *);
-int lfs_rename (void *);
-int lfs_getattr        (void *);
-int lfs_setattr        (void *);
-int lfs_close  (void *);
-int lfs_inactive(void *);
-int lfs_reclaim        (void *);
-int lfs_write  (void *);
-int lfs_whiteout(void *);
-int lfs_getpages(void *);
-int lfs_putpages(void *);
+int lfs_balloc  (void *);
+int lfs_valloc  (void *);
+int lfs_vfree   (void *);
+int lfs_bwrite  (void *);
+int lfs_update  (void *);
+int lfs_truncate (void *);
+int lfs_blkatoff (void *);
+int lfs_fsync   (void *);
+int lfs_symlink         (void *);
+int lfs_mknod   (void *);
+int lfs_create  (void *);
+int lfs_mkdir   (void *);
+int lfs_read    (void *);
+int lfs_remove  (void *);
+int lfs_rmdir   (void *);
+int lfs_link    (void *);
+int lfs_rename  (void *);
+int lfs_getattr         (void *);
+int lfs_setattr         (void *);
+int lfs_close   (void *);
+int lfsspec_close(void *);
+int lfsfifo_close(void *);
+int lfs_inactive (void *);
+int lfs_reclaim         (void *);
+int lfs_write   (void *);
+int lfs_whiteout (void *);
+int lfs_getpages (void *);
+int lfs_putpages (void *);
 
 __END_DECLS
 extern int lfs_mount_type;
diff -r ef86c77a2247 -r 586d0373ef55 sys/ufs/lfs/lfs_segment.c
--- a/sys/ufs/lfs/lfs_segment.c Sat Jun 15 21:49:18 2002 +0000
+++ b/sys/ufs/lfs/lfs_segment.c Sun Jun 16 00:13:15 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_segment.c,v 1.78 2002/05/24 22:13:57 perseant Exp $        */
+/*     $NetBSD: lfs_segment.c,v 1.79 2002/06/16 00:13:15 perseant Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.78 2002/05/24 22:13:57 perseant Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.79 2002/06/16 00:13:15 perseant Exp $");
 
 #define ivndebug(vp,str) printf("ino %d: %s\n",VTOI(vp)->i_number,(str))
 
@@ -104,11 +104,15 @@
 #include <ufs/lfs/lfs.h>
 #include <ufs/lfs/lfs_extern.h>
 
+#include <uvm/uvm.h>
 #include <uvm/uvm_extern.h>
 
 extern int count_lock_queue(void);
 extern struct simplelock vnode_free_list_slock;                /* XXX */
 
+static void lfs_generic_callback(struct buf *, void (*)(struct buf *));
+static void lfs_super_aiodone(struct buf *);
+static void lfs_cluster_aiodone(struct buf *);
 static void lfs_cluster_callback(struct buf *);
 static struct buf **lookahead_pagemove(struct buf **, int, size_t *);
 
@@ -290,8 +294,9 @@
        }
 
        SET_FLUSHING(fs,vp);
-       if (fs->lfs_nactive > LFS_MAX_ACTIVE) {
-               error = lfs_segwrite(vp->v_mount, SEGM_SYNC|SEGM_CKP);
+       if (fs->lfs_nactive > LFS_MAX_ACTIVE ||
+           (fs->lfs_sp->seg_flags & SEGM_CKP)) {
+               error = lfs_segwrite(vp->v_mount, SEGM_CKP | SEGM_SYNC);
                CLR_FLUSHING(fs,vp);
                lfs_segunlock(fs);
                return error;
@@ -351,11 +356,9 @@
         * artificially incremented by lfs_seglock().
         */
        if (fs->lfs_seglock > 1) {
-               s = splbio();
                while (fs->lfs_iocount > 1)
                        (void)tsleep(&fs->lfs_iocount, PRIBIO + 1,
                                     "lfs_vflush", 0);
-               splx(s);
        }
        lfs_segunlock(fs);
 
@@ -692,8 +695,8 @@
         * Take the flags off of the segment so that lfs_segunlock
         * doesn't have to write the superblock either.
         */
-       if (did_ckp == 0) {
-               sp->seg_flags &= ~(SEGM_SYNC|SEGM_CKP);
+       if (do_ckp && !did_ckp) {
+               sp->seg_flags &= ~SEGM_CKP;
                /* if (do_ckp) printf("lfs_segwrite: no checkpoint\n"); */
        }
 
@@ -1443,12 +1446,20 @@
 
        cl = (struct lfs_cluster *)malloc(sizeof(*cl), M_SEGMENT, M_WAITOK);
        bpp = (struct buf **)malloc(n*sizeof(*bpp), M_SEGMENT, M_WAITOK);
-       memset(cl,0,sizeof(*cl));
+       memset(cl, 0, sizeof(*cl));
        cl->fs = fs;
        cl->bpp = bpp;
        cl->bufcount = 0;
        cl->bufsize = 0;
 
+       /* If this segment is being written synchronously, note that */
+       if (fs->lfs_sp->seg_flags & SEGM_SYNC) {
+               cl->flags |= LFS_CL_SYNC;
+               cl->seg = fs->lfs_sp;
+               ++cl->seg->seg_iocount;
+               /* printf("+ %x => %d\n", cl->seg, cl->seg->seg_iocount); */
+       }
+
        /* Get an empty buffer header, or maybe one with something on it */
        s = splbio();
        if((bp = bufqueues[BQ_EMPTY].tqh_first) != NULL) {
@@ -1791,7 +1802,6 @@
                /*
                 * Construct the cluster.
                 */
-               s = splbio();
                while (fs->lfs_iocount >= LFS_THROTTLE) {
 #ifdef DEBUG_LFS
                        printf("[%d]", fs->lfs_iocount);
@@ -1841,7 +1851,9 @@
                        bp->b_flags &= ~(B_ERROR | B_READ | B_DELWRI | B_DONE);
                        cl->bpp[cl->bufcount++] = bp;
                        vp = bp->b_vp;
+                       s = splbio();
                        ++vp->v_numoutput;
+                       splx(s);
 
                        /*
                         * Although it cannot be freed for reuse before the
@@ -1875,6 +1887,7 @@
                         * XXX KS - Shouldn't we set *both* if both types
                         * of blocks are present (traverse the dirty list?)
                         */
+                       s = splbio();
                        if ((i == 1 ||
                             (i > 1 && vp && *bpp && (*bpp)->b_vp != vp)) &&
                            (bp = LIST_FIRST(&vp->v_dirtyblkhd)) != NULL &&
@@ -1890,8 +1903,10 @@
                                else
                                        LFS_SET_UINO(ip, IN_MODIFIED);
                        }
+                       splx(s);
                        wakeup(vp);
                }
+               s = splbio();
                ++cbp->b_vp->v_numoutput;
                splx(s);
                /*
@@ -1967,8 +1982,8 @@
        vop_strategy_a.a_bp = bp;
        s = splbio();
        ++bp->b_vp->v_numoutput;
+       splx(s);
        ++fs->lfs_iocount;
-       splx(s);
        (strategy)(&vop_strategy_a);
 }
 
@@ -2030,8 +2045,8 @@
        lfs_freebuf(bp);
 }
 
-void
-lfs_supercallback(struct buf *bp)
+static void
+lfs_super_aiodone(struct buf *bp)
 {
        struct lfs *fs;
 
@@ -2044,13 +2059,13 @@
 }
 
 static void
-lfs_cluster_callback(struct buf *bp)
+lfs_cluster_aiodone(struct buf *bp)
 {
        struct lfs_cluster *cl;
        struct lfs *fs;
        struct buf *tbp;
        struct vnode *vp;
-       int error=0;
+       int s, error=0;
        char *cp;
        extern int locked_queue_count;
        extern long locked_queue_bytes;
@@ -2101,8 +2116,10 @@
                        tbp->b_flags |= B_INVAL;
                if(!(tbp->b_flags & B_CALL)) {
                        bremfree(tbp);
+                       s = splbio();
                        if(vp)
                                reassignbuf(tbp, vp);
+                       splx(s);
                        tbp->b_flags |= B_ASYNC; /* for biodone */
                }
 #ifdef DIAGNOSTIC



Home | Main Index | Thread Index | Old Index