Source-Changes-HG archive

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

[src/trunk]: src/sys/ufs Allow the number of free segments reserved for the c...



details:   https://anonhg.NetBSD.org/src/rev/c17c687ee54a
branches:  trunk
changeset: 494153:c17c687ee54a
user:      perseant <perseant%NetBSD.org@localhost>
date:      Mon Jul 03 01:45:46 2000 +0000

description:
Allow the number of free segments reserved for the cleaner to be
parametrized in the filesystem, defaulting to MIN_FREE_SEGS = 2 but set
to something more reasonable at newfs_lfs time.

Note the number of blocks that have been scheduled for writing but which
are not yet on disk in an inode extension, i_lfs_effnblks.  Move
i_ffs_effnlink out of the ffs extension and onto the main inode, since
it's used all over the shared code and the lfs extension would clobber
it.

At inode write time, indirect blocks and inode-held blocks of inodes
that have i_lfs_effnblks != i_ffs_blocks are cleansed of UNWRITTEN disk
addresses, so that these never make it to disk.

diffstat:

 sys/ufs/lfs/lfs.h         |   12 +-
 sys/ufs/lfs/lfs_balloc.c  |    6 +-
 sys/ufs/lfs/lfs_bio.c     |   11 +-
 sys/ufs/lfs/lfs_inode.c   |   49 +++++++---
 sys/ufs/lfs/lfs_segment.c |  205 ++++++++++++++++++++++++++++++++-------------
 sys/ufs/lfs/lfs_vfsops.c  |    9 +-
 sys/ufs/ufs/inode.h       |   14 +-
 7 files changed, 208 insertions(+), 98 deletions(-)

diffs (truncated from 723 to 300 lines):

diff -r 6dfe7f06ac09 -r c17c687ee54a sys/ufs/lfs/lfs.h
--- a/sys/ufs/lfs/lfs.h Mon Jul 03 01:19:23 2000 +0000
+++ b/sys/ufs/lfs/lfs.h Mon Jul 03 01:45:46 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs.h,v 1.26 2000/06/27 20:57:11 perseant Exp $        */
+/*     $NetBSD: lfs.h,v 1.27 2000/07/03 01:45:46 perseant Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -85,7 +85,7 @@
  * Parameters and generic definitions
  */
 #define BW_CLEAN       1
-#define MIN_FREE_SEGS  4
+#define MIN_FREE_SEGS  2
 #define LFS_MAX_ACTIVE 10
 #define LFS_MAXDIROP   (desiredvnodes>>2)
 
@@ -221,7 +221,8 @@
        /* XXX this is 2 bytes only to pad to a quad boundary */
        u_int16_t dlfs_clean;     /* 322: file system is clean flag */
        u_int32_t dlfs_dmeta;     /* 324: total number of dirty summaries */
-        int8_t    dlfs_pad[180];  /* 328: round to 512 bytes */
+       u_int32_t dlfs_minfreeseg; /* 328: segs reserved for cleaner */
+        int8_t    dlfs_pad[176];  /* 332: round to 512 bytes */
 /* Checksum -- last valid disk field. */
         u_int32_t dlfs_cksum;     /* 508: checksum for superblock checking */
 };
@@ -281,6 +282,7 @@
 #define lfs_fsmnt lfs_dlfs.dlfs_fsmnt
 #define lfs_nclean lfs_dlfs.dlfs_nclean
 #define lfs_dmeta lfs_dlfs.dlfs_dmeta
+#define lfs_minfreeseg lfs_dlfs.dlfs_minfreeseg
 
 /* These fields are set at mount time and are meaningless on disk. */
        struct segment *lfs_sp;         /* current segment being written */
@@ -498,7 +500,7 @@
 };
 
 /*
- * Mecros for determining free space on the disk, with the variable metadata
+ * Macros for determining free space on the disk, with the variable metadata
  * of segment summaries and inode blocks taken into account.
  */
 /* Estimate number of clean blocks not available for writing */
@@ -507,7 +509,7 @@
                                      ((F)->lfs_nseg - (F)->lfs_nclean)))
 
 /* Estimate total size of the disk not including metadata */
-#define LFS_EST_NONMETA(F) ((F)->lfs_dsize - fsbtodb((F), MIN_FREE_SEGS *   \
+#define LFS_EST_NONMETA(F) ((F)->lfs_dsize - fsbtodb((F), (F)->lfs_minfreeseg *\
                                                     (F)->lfs_ssize) -      \
                            (F)->lfs_dmeta - LFS_EST_CMETA(F))
 
diff -r 6dfe7f06ac09 -r c17c687ee54a sys/ufs/lfs/lfs_balloc.c
--- a/sys/ufs/lfs/lfs_balloc.c  Mon Jul 03 01:19:23 2000 +0000
+++ b/sys/ufs/lfs/lfs_balloc.c  Mon Jul 03 01:45:46 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_balloc.c,v 1.20 2000/06/28 14:16:41 mrg Exp $      */
+/*     $NetBSD: lfs_balloc.c,v 1.21 2000/07/03 01:45:48 perseant Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -195,7 +195,7 @@
                        frags = numfrags(fs, nsize);
                        bb = fragstodb(fs, frags);
                        *ap->a_bpp = bp = getblk(vp, lbn, nsize, 0, 0);
-                       ip->i_ffs_blocks += bb;
+                       ip->i_lfs_effnblks += bb;
                        ip->i_lfs->lfs_bfree -= bb;
                        ip->i_ffs_db[lbn] = bp->b_blkno = UNWRITTEN;
                } else {
@@ -233,7 +233,7 @@
        }
        if (ISSPACE(fs, bcount, ap->a_cred)) {
                ip->i_lfs->lfs_bfree -= bcount;
-               ip->i_ffs_blocks += bcount;
+               ip->i_lfs_effnblks += bcount;
        } else {
                return ENOSPC;
        }
diff -r 6dfe7f06ac09 -r c17c687ee54a sys/ufs/lfs/lfs_bio.c
--- a/sys/ufs/lfs/lfs_bio.c     Mon Jul 03 01:19:23 2000 +0000
+++ b/sys/ufs/lfs/lfs_bio.c     Mon Jul 03 01:45:46 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_bio.c,v 1.24 2000/06/27 20:57:13 perseant Exp $    */
+/*     $NetBSD: lfs_bio.c,v 1.25 2000/07/03 01:45:49 perseant Exp $    */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -159,9 +159,8 @@
 inline static int
 lfs_fits(struct lfs *fs, int db)
 {
-       if(((db + (fs->lfs_uinodes + INOPB((fs))) /
-            INOPB(fs) + fsbtodb(fs, 1) + LFS_SUMMARY_SIZE / DEV_BSIZE +
-            fs->lfs_segtabsz)) >= fs->lfs_avail)
+       if(((db + fsbtodb(fs, roundup(fs->lfs_uinodes,INOPB(fs)) + 1) +
+            btodb(LFS_SUMMARY_SIZE) + fs->lfs_segtabsz)) >= fs->lfs_avail)
        {
                return 0;
        }
@@ -174,7 +173,7 @@
         *
         * XXX the old lfs_markv did not have this problem.
         */
-       if (fs->lfs_nclean <= MIN_FREE_SEGS)
+       if (fs->lfs_nclean <= fs->lfs_minfreeseg)
                return 0;
 
        return 1;
@@ -228,7 +227,7 @@
                        {
                                printf("A");
                        }
-                       if (fs->lfs_nclean <= MIN_FREE_SEGS-1)
+                       if (fs->lfs_nclean < fs->lfs_minfreeseg)
                                printf("M");
                }
 #endif
diff -r 6dfe7f06ac09 -r c17c687ee54a sys/ufs/lfs/lfs_inode.c
--- a/sys/ufs/lfs/lfs_inode.c   Mon Jul 03 01:19:23 2000 +0000
+++ b/sys/ufs/lfs/lfs_inode.c   Mon Jul 03 01:45:46 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_inode.c,v 1.39 2000/06/28 14:16:42 mrg Exp $       */
+/*     $NetBSD: lfs_inode.c,v 1.40 2000/07/03 01:45:51 perseant Exp $  */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -99,7 +99,7 @@
 
 static int lfs_update_seguse(struct lfs *, long, size_t);
 static int lfs_indirtrunc (struct inode *, ufs_daddr_t, ufs_daddr_t,
-                          ufs_daddr_t, int, long *, long *, size_t *);
+                          ufs_daddr_t, int, long *, long *, long *, size_t *);
 static int lfs_blkfree (struct lfs *, daddr_t, size_t, long *, size_t *);
 static int lfs_vtruncbuf(struct vnode *, daddr_t, int, int);
 
@@ -118,8 +118,10 @@
                if (ldip->di_inumber == ino)
                        return (ldip);
        
-       printf("offset is %d (seg %d)\n", fs->lfs_offset, datosn(fs,fs->lfs_offset));
-       printf("block is %d (seg %d)\n", bp->b_blkno, datosn(fs,bp->b_blkno));
+       printf("offset is 0x%x (seg %d)\n", fs->lfs_offset,
+              datosn(fs,fs->lfs_offset));
+       printf("block is 0x%x (seg %d)\n", bp->b_blkno,
+              datosn(fs,bp->b_blkno));
        panic("lfs_ifind: dinode %u not found", ino);
        /* NOTREACHED */
 }
@@ -223,7 +225,7 @@
        struct lfs *fs;
        struct buf *bp;
        int offset, size, level;
-       long count, nblocks, blocksreleased = 0;
+       long count, rcount, nblocks, blocksreleased = 0, real_released = 0;
        int i;
        int aflags, error, allerror = 0;
        off_t osize;
@@ -374,14 +376,19 @@
                bn = oip->i_ffs_ib[level];
                if (bn != 0) {
                        error = lfs_indirtrunc(oip, indir_lbn[level],
-                           bn, lastiblock[level], level, &count, &lastseg, &bc);
+                                              bn, lastiblock[level],
+                                              level, &count, &rcount,
+                                              &lastseg, &bc);
                        if (error)
                                allerror = error;
+                       real_released += rcount;
                        blocksreleased += count;
                        if (lastiblock[level] < 0) {
+                               if (oip->i_ffs_ib[level] > 0)
+                                       real_released += nblocks;
+                               blocksreleased += nblocks;
                                oip->i_ffs_ib[level] = 0;
                                lfs_blkfree(fs, bn, fs->lfs_bsize, &lastseg, &bc);
-                               blocksreleased += nblocks;
                        }
                }
                if (lastiblock[level] >= 0)
@@ -397,10 +404,12 @@
                bn = oip->i_ffs_db[i];
                if (bn == 0)
                        continue;
+               bsize = blksize(fs, oip, i);
+               if (oip->i_ffs_db[i] > 0)
+                       real_released += btodb(bsize);
+               blocksreleased += btodb(bsize);
                oip->i_ffs_db[i] = 0;
-               bsize = blksize(fs, oip, i);
                lfs_blkfree(fs, bn, bsize, &lastseg, &bc);
-               blocksreleased += btodb(bsize);
        }
        if (lastblock < 0)
                goto done;
@@ -424,6 +433,7 @@
                        panic("itrunc: newspace");
                if (oldspace - newspace > 0) {
                        lfs_blkfree(fs, bn, oldspace - newspace, &lastseg, &bc);
+                       real_released += btodb(oldspace - newspace);
                        blocksreleased += btodb(oldspace - newspace);
                }
        }
@@ -446,7 +456,8 @@
         * Put back the real size.
         */
        oip->i_ffs_size = length;
-       oip->i_ffs_blocks -= blocksreleased;
+       oip->i_lfs_effnblks -= blocksreleased;
+       oip->i_ffs_blocks -= real_released;
        fs->lfs_bfree += blocksreleased;
 #ifdef DIAGNOSTIC
        if (oip->i_ffs_size == 0 && oip->i_ffs_blocks > 0) {
@@ -522,7 +533,7 @@
 static int
 lfs_indirtrunc(struct inode *ip, ufs_daddr_t lbn, daddr_t dbn,
               ufs_daddr_t lastbn, int level, long *countp,
-              long *lastsegp, size_t *bcp)
+              long *rcountp, long *lastsegp, size_t *bcp)
 {
        int i;
        struct buf *bp;
@@ -530,8 +541,8 @@
        ufs_daddr_t *bap;
        struct vnode *vp;
        ufs_daddr_t *copy = NULL, nb, nlbn, last;
-       long blkcount, factor;
-       int nblocks, blocksreleased = 0;
+       long blkcount, rblkcount, factor;
+       int nblocks, blocksreleased = 0, real_released = 0;
        int error = 0, allerror = 0;
 
        /*
@@ -571,7 +582,7 @@
        }
        if (error) {
                brelse(bp);
-               *countp = 0;
+               *countp = *rcountp = 0;
                return (error);
        }
 
@@ -598,12 +609,16 @@
                if (level > SINGLE) {
                        error = lfs_indirtrunc(ip, nlbn, nb,
                                               (ufs_daddr_t)-1, level - 1,
-                                              &blkcount, lastsegp, bcp);
+                                              &blkcount, &rblkcount,
+                                              lastsegp, bcp);
                        if (error)
                                allerror = error;
                        blocksreleased += blkcount;
+                       real_released += rblkcount;
                }
                lfs_blkfree(fs, nb, fs->lfs_bsize, lastsegp, bcp);
+               if (bap[i] > 0)
+                       real_released += nblocks;
                blocksreleased += nblocks;
        }
 
@@ -616,9 +631,10 @@
                if (nb != 0) {
                        error = lfs_indirtrunc(ip, nlbn, nb,
                                               last, level - 1, &blkcount,
-                                              lastsegp, bcp);
+                                              &rblkcount, lastsegp, bcp);
                        if (error)
                                allerror = error;
+                       real_released += rblkcount;
                        blocksreleased += blkcount;
                }
        }
@@ -631,6 +647,7 @@
        }
 
        *countp = blocksreleased;
+       *rcountp = real_released;
        return (allerror);
 }
 
diff -r 6dfe7f06ac09 -r c17c687ee54a sys/ufs/lfs/lfs_segment.c
--- a/sys/ufs/lfs/lfs_segment.c Mon Jul 03 01:19:23 2000 +0000
+++ b/sys/ufs/lfs/lfs_segment.c Mon Jul 03 01:45:46 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_segment.c,v 1.52 2000/06/27 20:57:15 perseant Exp $        */
+/*     $NetBSD: lfs_segment.c,v 1.53 2000/07/03 01:45:52 perseant Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -485,18 +485,21 @@
        
        fs = VFSTOUFS(mp)->um_lfs;
 
+       if (fs->lfs_ronly)
+               return EROFS;
+
        lfs_imtime(fs);
        



Home | Main Index | Thread Index | Old Index