Source-Changes-HG archive

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

[src/trunk]: src/libexec/lfs_cleanerd Don't try to coalesce files that have f...



details:   https://anonhg.NetBSD.org/src/rev/2e6ec0a52acf
branches:  trunk
changeset: 532738:2e6ec0a52acf
user:      perseant <perseant%NetBSD.org@localhost>
date:      Fri Jun 14 00:58:39 2002 +0000

description:
Don't try to coalesce files that have fewer than NDADDR blocks, due to
a potential problem with cleaning fragments at all.

Better sanity checks when selecting files to coalesce; in particular don't
shift too far left when comparing the number of discontinuities to the log2
of the number of total blocks.

Better log messages: note beginning of coalescing correctly; also take
the log message from add_segment out of "if (debug)" for symmetry with the
"finished segment" message.

Use lfs_bmapv to find the inode, rather than looking it up manually in
the ifile; this should give more up-to-date information, since trolling
through every inode in the fs could take some time.

diffstat:

 libexec/lfs_cleanerd/clean.h    |   7 ++-
 libexec/lfs_cleanerd/cleanerd.c |  16 +-----
 libexec/lfs_cleanerd/coalesce.c |  89 +++++++++++++++++++++++++++++++---------
 libexec/lfs_cleanerd/library.c  |  18 +++++---
 4 files changed, 89 insertions(+), 41 deletions(-)

diffs (truncated from 313 to 300 lines):

diff -r 50eb13546516 -r 2e6ec0a52acf libexec/lfs_cleanerd/clean.h
--- a/libexec/lfs_cleanerd/clean.h      Fri Jun 14 00:55:47 2002 +0000
+++ b/libexec/lfs_cleanerd/clean.h      Fri Jun 14 00:58:39 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clean.h,v 1.13 2002/06/06 00:56:49 perseant Exp $      */
+/*     $NetBSD: clean.h,v 1.14 2002/06/14 00:58:39 perseant Exp $      */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -147,6 +147,11 @@
 }
 
 __BEGIN_DECLS
+int             lfs_segwait(fsid_t *, struct timeval *);
+int             lfs_segclean(fsid_t *, u_long);
+int             lfs_bmapv(fsid_t *, BLOCK_INFO_15 *, int); 
+int             lfs_markv(fsid_t *, BLOCK_INFO_15 *, int);
+
 int             dump_summary(struct lfs *, SEGSUM *, u_long, daddr_t **, daddr_t);
 int             fs_getmntinfo(struct statfs **, char *, const char *);
 void            get(int, off_t, void *, size_t);
diff -r 50eb13546516 -r 2e6ec0a52acf libexec/lfs_cleanerd/cleanerd.c
--- a/libexec/lfs_cleanerd/cleanerd.c   Fri Jun 14 00:55:47 2002 +0000
+++ b/libexec/lfs_cleanerd/cleanerd.c   Fri Jun 14 00:58:39 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cleanerd.c,v 1.38 2002/06/06 00:56:49 perseant Exp $   */
+/*     $NetBSD: cleanerd.c,v 1.39 2002/06/14 00:58:40 perseant Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)cleanerd.c 8.5 (Berkeley) 6/10/95";
 #else
-__RCSID("$NetBSD: cleanerd.c,v 1.38 2002/06/06 00:56:49 perseant Exp $");
+__RCSID("$NetBSD: cleanerd.c,v 1.39 2002/06/14 00:58:40 perseant Exp $");
 #endif
 #endif /* not lint */
 
@@ -109,12 +109,6 @@
 
 #define        CLEAN_BYTES     0x1
 
-/* function prototypes for system calls; not sure where they should go */
-int     lfs_segwait(fsid_t *, struct timeval *);
-int     lfs_segclean(fsid_t *, u_long);
-int     lfs_bmapv(fsid_t *, BLOCK_INFO_15 *, int);
-int     lfs_markv(fsid_t *, BLOCK_INFO_15 *, int);
-
 /* function prototypes */
 int     bi_tossold(const void *, const void *, const void *);
 int     choose_segments(FS_INFO *, struct seglist *, 
@@ -687,9 +681,8 @@
        error = 0;
        tba = NULL;
 
-       if (debug)
-               syslog(LOG_DEBUG, "adding segment %d: contains %lu bytes", id,
-                   (unsigned long)sp->su_nbytes);
+       syslog(LOG_DEBUG, "adding segment %d: contains %lu bytes", id,
+              (unsigned long)sp->su_nbytes);
 
        /* XXX could add debugging to verify that segment is really empty */
        if (sp->su_nbytes == 0) {
@@ -914,7 +907,6 @@
        }
        /* If we're writing more than we're saving, try coalescing */
        if (ebytes + nbytes > fsp->fi_lfs.lfs_fsize * fsp->fi_lfs.lfs_fsbpseg * sbp->nsegs) {
-               syslog(LOG_NOTICE, "starting coalescing process");
                fork_coalesce(fsp);
        }
 
diff -r 50eb13546516 -r 2e6ec0a52acf libexec/lfs_cleanerd/coalesce.c
--- a/libexec/lfs_cleanerd/coalesce.c   Fri Jun 14 00:55:47 2002 +0000
+++ b/libexec/lfs_cleanerd/coalesce.c   Fri Jun 14 00:58:39 2002 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: coalesce.c,v 1.1 2002/06/06 00:56:50 perseant Exp $  */
+/*      $NetBSD: coalesce.c,v 1.2 2002/06/14 00:58:40 perseant Exp $  */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -62,18 +62,27 @@
 
 #include "clean.h"
 
-int    lfs_bmapv(fsid_t *, BLOCK_INFO_15 *, int);
-int    lfs_markv(fsid_t *, BLOCK_INFO_15 *, int);
-
-extern int debug;
+extern int debug, do_mmap;
 
 static int
 tossdead(const void *client, const void *a, const void *b)
 {
-       return (((BLOCK_INFO_15 *)a)->bi_daddr == LFS_UNUSED_DADDR ||
+       return (((BLOCK_INFO_15 *)a)->bi_daddr <= 0 ||
                ((BLOCK_INFO_15 *)a)->bi_size == 0);
 }
 
+static int log2int(int n)
+{
+       int log;
+
+       log = 0;
+       while (n > 0) {
+               ++log;
+               n /= 2;
+       }
+       return log - 1;
+}
+
 /*
  * Find out if this inode's data blocks are discontinuous; if they are,
  * rewrite them using lfs_markv.  Return the number of inodes rewritten.
@@ -81,10 +90,9 @@
 int clean_inode(struct fs_info *fsp, ino_t ino)
 {
        int i, error;
-       IFILE *ifp;
        BLOCK_INFO_15 *bip, *tbip;
        struct dinode *dip;
-       int nb, noff;
+       int nb, onb, noff;
        ufs_daddr_t toff;
        struct lfs *lfsp;
        int bps;
@@ -97,12 +105,24 @@
                return 0;
 
        /* Compute file block size, set up for lfs_bmapv */
-       nb = btofsb(lfsp, dip->di_size);
+       onb = nb = btofsb(lfsp, dip->di_size);
+
+       /* XXX for now, don't do any file small enough to have fragments */
+       if (nb < NDADDR)
+               return 0;
+
+       /* Sanity checks */
+       if (dip->di_size < 0) {
+               syslog(LOG_WARNING, "ino %d, negative size (%lld)",
+                       ino, (long long)dip->di_size);
+               return -1;
+       }
        if (nb > dip->di_blocks) {
                syslog(LOG_WARNING, "ino %d, computed blocks %d > held blocks %d",
                        ino, nb, dip->di_blocks);
                return -1;
        }
+
        bip = (BLOCK_INFO_15 *)malloc(sizeof(BLOCK_INFO_15) * nb);
        if (bip == NULL) {
                syslog(LOG_WARNING, "ino %d, %d blocks: %m", ino, nb);
@@ -112,11 +132,11 @@
                memset(bip + i, 0, sizeof(BLOCK_INFO_15));
                bip[i].bi_inode = ino;
                bip[i].bi_lbn = i;
-               bip[i].bi_version = ifp->if_version;
+               bip[i].bi_version = dip->di_gen;
                /* Don't set the size, but let lfs_bmap fill it in */
        }
        if ((error = lfs_bmapv(&fsp->fi_statfsp->f_fsid, bip, nb)) < 0) { 
-                syslog(LOG_WARNING, "lfs_bmapv");
+                syslog(LOG_WARNING, "lfs_bmapv: %m");
                free(bip);
                return -1;
        }
@@ -134,8 +154,8 @@
          * files will be broken among segments and medium-sized files
          * can have a break or two and it's okay.
         */
-       if (nb <= 1 || noff == 0 || (1 << (noff + 1)) < nb ||
-           segtod(lfsp, noff) * 2< nb) {
+       if (nb <= 1 || noff == 0 || noff < log2int(nb) ||
+           segtod(lfsp, noff) * 2 < nb) {
                free(bip);
                return 0;
        } else if (debug)
@@ -164,14 +184,25 @@
                return 0;
        }
 
+#if 0
        /*
-        * If we're going to write more blocks than half of the available
-        * segments, don't do it.
+        * Double-check that we've tossed everything invalid. (wtf?!)
         */
-       if (segtod(lfsp, fsp->fi_cip->clean - 1) / 2 < nb) {
-               syslog(LOG_WARNING, "not rewriting ino %d, "
-                       "not enough free segments", ino);
-               free(bip);
+       for (i = 0; i < nb; i++) {
+               if (bip[i].bi_daddr <= 0) {
+                       syslog(LOG_ERR, "negative daddr not tossed, bombing");
+                       free(bip);
+                       return 0;
+               }
+       }
+#endif
+
+       /*
+        * We may have tossed enough blocks that it is no longer worthwhile
+        * to rewrite this inode.
+        */
+       if ((1 << (onb - nb)) > onb) {
+               syslog(LOG_DEBUG, "too many blocks tossed, not rewriting");
                return 0;
        }
 
@@ -186,9 +217,18 @@
        if (debug)
                syslog(LOG_DEBUG, "ino %d markv %d blocks", ino, nb);
 
-       /* Write in segment-sized chunks */
+       /*
+        * Write in segment-sized chunks.  If at any point we'd write more
+        * than half of the available segments, sleep until that's not
+        * true any more.
+        */
        bps = segtod(lfsp, 1);
        for (tbip = bip; tbip < bip + nb; tbip += bps) {
+               while (fsp->fi_cip->clean < 4) {
+                       lfs_segwait(&fsp->fi_statfsp->f_fsid, NULL);
+                       reread_fs_info(fsp, do_mmap);
+                       /* XXX start over? */
+               }
                lfs_markv(&fsp->fi_statfsp->f_fsid, tbip,
                           (tbip + bps < bip + nb ? bps : nb % bps));
        }
@@ -221,6 +261,9 @@
 int fork_coalesce(struct fs_info *fsp)
 {
        static pid_t childpid;
+       int num;
+
+       reread_fs_info(fsp, do_mmap);
 
        if (childpid) {
                if (waitpid(childpid, NULL, WNOHANG) == childpid)
@@ -228,6 +271,8 @@
        }
        if (childpid && kill(childpid, 0) >= 0) {
                /* already running a coalesce process */
+               if (debug)
+                       syslog(LOG_DEBUG, "coalescing already in progress");
                return 0;
        }
        childpid = fork();
@@ -235,7 +280,9 @@
                syslog(LOG_ERR, "fork: %m");
                return 0;
        } else if (childpid == 0) {
-               clean_all_inodes(fsp);
+               syslog(LOG_NOTICE, "new coalescing process (%d)", childpid);
+               num = clean_all_inodes(fsp);
+               syslog(LOG_NOTICE, "coalesced %d discontiguous inodes", num);
                exit(0);
        }
        return 0;
diff -r 50eb13546516 -r 2e6ec0a52acf libexec/lfs_cleanerd/library.c
--- a/libexec/lfs_cleanerd/library.c    Fri Jun 14 00:55:47 2002 +0000
+++ b/libexec/lfs_cleanerd/library.c    Fri Jun 14 00:58:39 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: library.c,v 1.27 2002/06/06 00:56:50 perseant Exp $    */
+/*     $NetBSD: library.c,v 1.28 2002/06/14 00:58:40 perseant Exp $    */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)library.c  8.3 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: library.c,v 1.27 2002/06/06 00:56:50 perseant Exp $");
+__RCSID("$NetBSD: library.c,v 1.28 2002/06/14 00:58:40 perseant Exp $");
 #endif
 #endif /* not lint */
 
@@ -188,7 +188,7 @@
         struct dinode *dip, *dib;
         struct lfs *lfsp;
        char rdev[MNAMELEN];
-        IFILE *ifp;
+       BLOCK_INFO_15 bi;
 
         lfsp = &fsp->fi_lfs;
 
@@ -196,7 +196,13 @@
         * Locate the inode block and find the inode.
         * Use this to know how large the file is.
         */
-       ifp = IFILE_ENTRY(lfsp, fsp->fi_ifilep, ino);
+       memset(&bi, 0, sizeof(bi));
+       bi.bi_inode = ino;
+       bi.bi_lbn = LFS_UNUSED_LBN; /* We want the inode */
+       if (lfs_bmapv(&fsp->fi_statfsp->f_fsid, &bi, 1) < 0)
+               return NULL;
+       if (bi.bi_daddr <= 0)
+               return NULL;
 
        if (dev_fd <= 0) {



Home | Main Index | Thread Index | Old Index