Source-Changes-HG archive

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

[src/trunk]: src/sys/ufs Clean up accounting of lfs_uinodes (dirty but unwrit...



details:   https://anonhg.NetBSD.org/src/rev/1f445a1caa25
branches:  trunk
changeset: 494354:1f445a1caa25
user:      perseant <perseant%NetBSD.org@localhost>
date:      Wed Jul 05 22:25:43 2000 +0000

description:
Clean up accounting of lfs_uinodes (dirty but unwritten inodes).

Make lfs_uinodes a signed quantity for debugging purposes, and set it to
zero as fs mount time.

Enclose setting/clearing of the dirty flags (IN_MODIFIED, IN_ACCESSED,
IN_CLEANING) in macros, and use those macros everywhere.  Make
LFS_ITIMES use these macros; updated the ITIMES macro in inode.h to know
about this.  Make ufs_getattr use ITIMES instead of FFS_ITIMES.

diffstat:

 sys/ufs/lfs/lfs.h          |  52 +++++++++++++++++++++++++++++++++++++++++----
 sys/ufs/lfs/lfs_alloc.c    |  20 ++++-------------
 sys/ufs/lfs/lfs_bio.c      |  39 +++++++++++++++++++++++----------
 sys/ufs/lfs/lfs_extern.h   |   7 +++++-
 sys/ufs/lfs/lfs_inode.c    |   7 +----
 sys/ufs/lfs/lfs_segment.c  |  47 +++++++++++++++--------------------------
 sys/ufs/lfs/lfs_syscalls.c |   6 +---
 sys/ufs/lfs/lfs_vfsops.c   |   3 +-
 sys/ufs/lfs/lfs_vnops.c    |  18 +++++++++++----
 sys/ufs/ufs/inode.h        |  15 ++++++++++++-
 sys/ufs/ufs/ufs_vnops.c    |   4 +-
 11 files changed, 137 insertions(+), 81 deletions(-)

diffs (truncated from 525 to 300 lines):

diff -r ff83273fff4e -r 1f445a1caa25 sys/ufs/lfs/lfs.h
--- a/sys/ufs/lfs/lfs.h Wed Jul 05 22:25:34 2000 +0000
+++ b/sys/ufs/lfs/lfs.h Wed Jul 05 22:25:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs.h,v 1.28 2000/07/04 22:30:37 perseant Exp $        */
+/*     $NetBSD: lfs.h,v 1.29 2000/07/05 22:25:43 perseant Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -91,22 +91,64 @@
 
 /* For convenience */
 #define IN_ALLMOD (IN_MODIFIED|IN_ACCESS|IN_CHANGE|IN_UPDATE|IN_ACCESSED|IN_CLEANING)
+#define LFS_SET_UINO(ip, flags) do {                                    \
+        if (((flags) & IN_ACCESSED) && !((ip)->i_flag & IN_ACCESSED))   \
+                ++(ip)->i_lfs->lfs_uinodes;                             \
+        if (((flags) & IN_CLEANING) && !((ip)->i_flag & IN_CLEANING))   \
+                ++(ip)->i_lfs->lfs_uinodes;                             \
+        if (((flags) & IN_MODIFIED) && !((ip)->i_flag & IN_MODIFIED))   \
+                ++(ip)->i_lfs->lfs_uinodes;                             \
+        (ip)->i_flag |= (flags);                                        \
+} while(0)
+
+#define LFS_CLR_UINO(ip, flags) do {                                    \
+        if (((flags) & IN_ACCESSED) && ((ip)->i_flag & IN_ACCESSED))    \
+                --(ip)->i_lfs->lfs_uinodes;                             \
+        if (((flags) & IN_CLEANING) && ((ip)->i_flag & IN_CLEANING))    \
+                --(ip)->i_lfs->lfs_uinodes;                             \
+        if (((flags) & IN_MODIFIED) && ((ip)->i_flag & IN_MODIFIED))    \
+                --(ip)->i_lfs->lfs_uinodes;                             \
+        (ip)->i_flag &= ~(flags);                                       \
+       if ((ip)->i_lfs->lfs_uinodes < 0) {                             \
+               panic("lfs_uinodes < 0");                               \
+       }                                                               \
+} while(0)
+
 
 #ifndef LFS_ATIME_IFILE
-# define LFS_ITIMES(ip, acc, mod, cre) FFS_ITIMES((ip),(acc),(mod),(cre))
+#define        LFS_ITIMES(ip, acc, mod, cre) {                                 \
+       if ((ip)->i_flag & IN_ACCESS) {                                 \
+               (ip)->i_ffs_atime = (acc)->tv_sec;                      \
+               (ip)->i_ffs_atimensec = (acc)->tv_nsec;                 \
+               LFS_SET_UINO(ip, IN_ACCESSED);                          \
+       }                                                               \
+       if ((ip)->i_flag & (IN_CHANGE | IN_UPDATE)) {                   \
+               if ((ip)->i_flag & IN_UPDATE) {                         \
+                       (ip)->i_ffs_mtime = (mod)->tv_sec;              \
+                       (ip)->i_ffs_mtimensec = (mod)->tv_nsec;         \
+                       (ip)->i_modrev++;                               \
+               }                                                       \
+               if ((ip)->i_flag & IN_CHANGE) {                         \
+                       (ip)->i_ffs_ctime = (cre)->tv_sec;              \
+                       (ip)->i_ffs_ctimensec = (cre)->tv_nsec;         \
+               }                                                       \
+               LFS_SET_UINO(ip, IN_MODIFIED);                          \
+       }                                                               \
+       (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);           \
+}
 #else
 # define LFS_ITIMES(ip, acc, mod, cre) {                                \ 
        struct buf *ibp;                                                \
        IFILE *ifp;                                                     \
                                                                        \
         if ((ip)->i_flag & IN_ACCESS) {                                \
-       LFS_IENTRY(ifp, ip->i_lfs, ip->i_number, ibp);                  \
+               LFS_IENTRY(ifp, ip->i_lfs, ip->i_number, ibp);          \
                        ifp->if_atime = (mod);                                  \
                        VOP_BWRITE(bp);                                         \
                (ip)->i_flag &= ~IN_ACCESS;                             \
         }                                                              \
         if ((ip)->i_flag & (IN_CHANGE | IN_UPDATE)) {                  \
-                (ip)->i_flag |= IN_MODIFIED;                            \
+               LFS_SET_UINO(ip, IN_MODIFIED);                          \
                 if ((ip)->i_flag & IN_UPDATE) {                         \
                         (ip)->i_ffs_mtime = (mod)->tv_sec;             \
                         (ip)->i_ffs_mtimensec = (mod)->tv_nsec;         \
@@ -175,7 +217,7 @@
         u_int32_t dlfs_bfree;     /* 36: number of free disk blocks */
         u_int32_t dlfs_nfiles;    /* 40: number of allocated inodes */
         int32_t   dlfs_avail;     /* 44: blocks available for writing */
-        u_int32_t dlfs_uinodes;   /* 48: inodes in cache not yet on disk */
+        int32_t   dlfs_uinodes;   /* 48: inodes in cache not yet on disk */
         ufs_daddr_t  dlfs_idaddr; /* 52: inode file disk address */
         u_int32_t dlfs_ifile;     /* 56: inode file inode number */
         ufs_daddr_t  dlfs_lastseg; /* 60: address of last segment written */
diff -r ff83273fff4e -r 1f445a1caa25 sys/ufs/lfs/lfs_alloc.c
--- a/sys/ufs/lfs/lfs_alloc.c   Wed Jul 05 22:25:34 2000 +0000
+++ b/sys/ufs/lfs/lfs_alloc.c   Wed Jul 05 22:25:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_alloc.c,v 1.41 2000/07/03 08:20:58 perseant Exp $  */
+/*     $NetBSD: lfs_alloc.c,v 1.42 2000/07/05 22:25:43 perseant Exp $  */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -287,7 +287,6 @@
        vp->v_data = ip;
        ip->i_vnode = vp;
        ip->i_devvp = ump->um_devvp;
-       ip->i_flag = IN_MODIFIED;
        ip->i_dev = ump->um_dev;
        ip->i_number = ip->i_din.ffs_din.di_inumber = ino;
        ip->i_lfs = ump->um_lfs;
@@ -301,7 +300,8 @@
        ip->i_ffs_size = 0;
        ip->i_ffs_blocks = 0;
        ip->i_lfs_effnblks = 0;
-       ++ump->um_lfs->lfs_uinodes;
+       ip->i_flag = 0;
+       LFS_SET_UINO(ip, IN_MODIFIED);
 }
 
 /* Free an inode. */
@@ -354,19 +354,9 @@
                ip->i_flag &= ~IN_ADIROP;
        }
 
-       if (ip->i_flag & IN_CLEANING) {
-               --fs->lfs_uinodes;
-       }
-       if (ip->i_flag & (IN_MODIFIED | IN_ACCESSED)) {
-               --fs->lfs_uinodes;
-       }
+       LFS_CLR_UINO(ip, IN_ACCESSED|IN_CLEANING|IN_MODIFIED);
        ip->i_flag &= ~IN_ALLMOD;
-#ifdef DEBUG_LFS       
-       if((int32_t)fs->lfs_uinodes<0) {
-               printf("U1");
-               fs->lfs_uinodes=0;
-       }
-#endif
+
        /*
         * Set the ifile's inode entry to unused, increment its version number
         * and link it into the free chain.
diff -r ff83273fff4e -r 1f445a1caa25 sys/ufs/lfs/lfs_bio.c
--- a/sys/ufs/lfs/lfs_bio.c     Wed Jul 05 22:25:34 2000 +0000
+++ b/sys/ufs/lfs/lfs_bio.c     Wed Jul 05 22:25:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_bio.c,v 1.25 2000/07/03 01:45:49 perseant Exp $    */
+/*     $NetBSD: lfs_bio.c,v 1.26 2000/07/05 22:25:43 perseant Exp $    */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -159,9 +159,17 @@
 inline static int
 lfs_fits(struct lfs *fs, int db)
 {
-       if(((db + fsbtodb(fs, roundup(fs->lfs_uinodes,INOPB(fs)) + 1) +
-            btodb(LFS_SUMMARY_SIZE) + fs->lfs_segtabsz)) >= fs->lfs_avail)
-       {
+       int needed;
+
+       needed = db + btodb(LFS_SUMMARY_SIZE) +
+               fsbtodb(fs, howmany(fs->lfs_uinodes, INOPB(fs)) +
+                           fs->lfs_segtabsz + 1);
+       if (needed >= fs->lfs_avail) {
+#ifdef DEBUG_LFS
+               printf("lfs_fits: no fit: db = %d, uinodes = %d, "
+                      "needed = %d, avail = %d\n",
+                      db, fs->lfs_uinodes, needed, fs->lfs_avail);
+#endif
                return 0;
        }
 
@@ -187,6 +195,8 @@
        struct lfs *fs;
        struct inode *ip;
        int db, error, s;
+       struct buf *cbp;
+       CLEANERINFO *cip;
        
        /*
         * Don't write *any* blocks if we're mounted read-only.
@@ -232,8 +242,17 @@
                }
 #endif
                while (!lfs_fits(fs, db) && !CANT_WAIT(bp,flags)) {
-                       /* Out of space, need cleaner to run */
-                       
+                       /*
+                        * Out of space, need cleaner to run.
+                        * Update the cleaner info, then wake it up.
+                        * Note the cleanerinfo block is on the ifile
+                        * so it CANT_WAIT.
+                        */
+                       LFS_CLEANERINFO(cip, fs, cbp);
+                       cip->bfree = fs->lfs_bfree;
+                       cip->avail = fs->lfs_avail;
+                       (void) VOP_BWRITE(cbp);
+
                        wakeup(&lfs_allclean_wakeup);
                        wakeup(&fs->lfs_nextseg);
                        error = tsleep(&fs->lfs_avail, PCATCH | PUSER,
@@ -247,13 +266,9 @@
                
                ip = VTOI(bp->b_vp);
                if (bp->b_flags & B_CALL) {
-                       if(!(ip->i_flag & IN_CLEANING))
-                               ++fs->lfs_uinodes;
-                       ip->i_flag |= IN_CLEANING;
+                       LFS_SET_UINO(ip, IN_CLEANING);
                } else {
-                       if(!(ip->i_flag & (IN_MODIFIED | IN_ACCESSED)))
-                               ++fs->lfs_uinodes;
-                       ip->i_flag |= IN_CHANGE | IN_MODIFIED | IN_UPDATE;
+                       LFS_SET_UINO(ip, IN_CHANGE | IN_MODIFIED | IN_UPDATE);
                }
                fs->lfs_avail -= db;
                ++locked_queue_count;
diff -r ff83273fff4e -r 1f445a1caa25 sys/ufs/lfs/lfs_extern.h
--- a/sys/ufs/lfs/lfs_extern.h  Wed Jul 05 22:25:34 2000 +0000
+++ b/sys/ufs/lfs/lfs_extern.h  Wed Jul 05 22:25:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_extern.h,v 1.19 2000/06/30 20:45:39 fvdl Exp $     */
+/*     $NetBSD: lfs_extern.h,v 1.20 2000/07/05 22:25:43 perseant Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -70,6 +70,9 @@
  *     @(#)lfs_extern.h        8.6 (Berkeley) 5/8/95
  */
 
+/* Copied from ext2fs for ITIMES.  XXX This is a bogus use of v_tag. */
+#define IS_LFS_VNODE(vp)   (vp->v_tag == VT_LFS)
+
 /*
  * Sysctl values for LFS.
  */
@@ -183,6 +186,8 @@
 
 /* lfs_vnops.c */
 void lfs_unmark_vnode __P((struct vnode *));
+void lfs_itimes __P((struct inode *, struct timespec *, struct timespec *,
+                    struct timespec *));
 
 int lfs_balloc         __P((void *));
 int lfs_valloc         __P((void *));
diff -r ff83273fff4e -r 1f445a1caa25 sys/ufs/lfs/lfs_inode.c
--- a/sys/ufs/lfs/lfs_inode.c   Wed Jul 05 22:25:34 2000 +0000
+++ b/sys/ufs/lfs/lfs_inode.c   Wed Jul 05 22:25:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_inode.c,v 1.41 2000/07/04 22:30:37 perseant Exp $  */
+/*     $NetBSD: lfs_inode.c,v 1.42 2000/07/05 22:25:43 perseant Exp $  */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
                                  } */ *ap = v;
        struct inode *ip;
        struct vnode *vp = ap->a_vp;
-       int mod, oflag;
+       int oflag;
        struct timespec ts;
        struct lfs *fs = VFSTOUFS(vp->v_mount)->um_lfs;
        
@@ -161,14 +161,11 @@
 #endif
                tsleep(vp, (PRIBIO+1), "lfs_update", 0);
        }
-       mod = ip->i_flag & (IN_MODIFIED | IN_ACCESSED);
        oflag = ip->i_flag;
        TIMEVAL_TO_TIMESPEC(&time, &ts);
        LFS_ITIMES(ip,
                   ap->a_access ? ap->a_access : &ts,
                   ap->a_modify ? ap->a_modify : &ts, &ts);
-       if (!mod && (ip->i_flag & (IN_MODIFIED | IN_ACCESSED)))
-               ip->i_lfs->lfs_uinodes++;
        if ((ip->i_flag & (IN_MODIFIED | IN_ACCESSED | IN_CLEANING)) == 0) {
                return (0);
        }
diff -r ff83273fff4e -r 1f445a1caa25 sys/ufs/lfs/lfs_segment.c
--- a/sys/ufs/lfs/lfs_segment.c Wed Jul 05 22:25:34 2000 +0000
+++ b/sys/ufs/lfs/lfs_segment.c Wed Jul 05 22:25:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_segment.c,v 1.55 2000/07/04 22:30:37 perseant Exp $        */
+/*     $NetBSD: lfs_segment.c,v 1.56 2000/07/05 22:25:44 perseant Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -197,11 +197,9 @@
 #ifdef DEBUG_LFS
                ivndebug(vp,"vflush/in_cleaning");
 #endif
-               ip->i_flag &= ~IN_CLEANING;
-               if(ip->i_flag & (IN_MODIFIED | IN_ACCESSED)) {
-                       fs->lfs_uinodes--;
-               } else
-                       ip->i_flag |= IN_MODIFIED;
+               LFS_CLR_UINO(ip, IN_CLEANING);
+               LFS_SET_UINO(ip, IN_MODIFIED);
+
                /*
                 * Toss any cleaning buffers that have real counterparts
                 * to avoid losing new data
@@ -259,10 +257,8 @@
                        }
                }
                splx(s);
-               if(ip->i_flag & IN_CLEANING)



Home | Main Index | Thread Index | Old Index