speed-ups using the new constants
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 10 Jan 1983 11:10:23 +0000 (03:10 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 10 Jan 1983 11:10:23 +0000 (03:10 -0800)
SCCS-vsn: sys/ufs/ffs/fs.h 4.7

usr/src/sys/ufs/ffs/fs.h

index e734816..caa8833 100644 (file)
@@ -1,4 +1,4 @@
-/*     fs.h    4.6     83/01/02        */
+/*     fs.h    4.7     83/01/09        */
 
 /*
  * Each disk drive contains some number of file systems.
 
 /*
  * Each disk drive contains some number of file systems.
 #define        ROOTINO         ((ino_t)2)      /* i number of all roots */
 #define LOSTFOUNDINO   (ROOTINO + 1)
 
 #define        ROOTINO         ((ino_t)2)      /* i number of all roots */
 #define LOSTFOUNDINO   (ROOTINO + 1)
 
-/*
- * MINFREE gives the minimum acceptable percentage of file system
- * blocks which may be free. If the freelist drops below this level
- * only the superuser may continue to allocate blocks. This may
- * be set to 0 if no reserve of free blocks is deemed necessary,
- * however severe performance degredations will be observed if the
- * file system is run at greater than 90% full; thus the default
- * value of fs_minfree is 10%.
- *
- * Empirically the best trade-off between block fragmentation and
- * overall disk utilization at a loading of 90% comes with a
- * fragmentation of 4, thus the default fragment size is a fourth
- * of the block size.
- */
-#define MINFREE                10
-#define DESFRAG                4
-
-/*
- * Under current technology, most 300MB disks have 32 sectors and
- * 16 tracks, thus these are the defaults used for fs_nsect and 
- * fs_ntrak respectively.
- */
-#define DFLNSECT       32
-#define DFLNTRAK       16
-
 /*
  * Cylinder group related limits.
  *
 /*
  * Cylinder group related limits.
  *
  * up with minimum rotational latency.  NRPOS is the number of rotational
  * positions which we distinguish.  With NRPOS 8 the resolution of our
  * summary information is 2ms for a typical 3600 rpm drive.
  * up with minimum rotational latency.  NRPOS is the number of rotational
  * positions which we distinguish.  With NRPOS 8 the resolution of our
  * summary information is 2ms for a typical 3600 rpm drive.
- *
- * ROTDELAY gives the minimum number of milliseconds to initiate
- * another disk transfer on the same cylinder. It is used in
- * determining the rotationally optimal layout for disk blocks
- * within a file; the default of fs_rotdelay is 2ms.
  */
 #define        NRPOS           8       /* number distinct rotational positions */
  */
 #define        NRPOS           8       /* number distinct rotational positions */
-#define ROTDELAY       2
 
 /*
 
 /*
- * Each file system has a number of inodes statically allocated.
- * We allocate one inode slot per NBPI bytes, expecting this
- * to be far more than we will ever need.
- *
  * MAXIPG bounds the number of inodes per cylinder group, and
  * is needed only to keep the structure simpler by having the
  * only a single variable size element (the free bit map).
  *
  * N.B.: MAXIPG must be a multiple of INOPB(fs).
  */
  * MAXIPG bounds the number of inodes per cylinder group, and
  * is needed only to keep the structure simpler by having the
  * only a single variable size element (the free bit map).
  *
  * N.B.: MAXIPG must be a multiple of INOPB(fs).
  */
-#define        NBPI            2048
 #define        MAXIPG          2048    /* max number inodes/cyl group */
 
 /*
 #define        MAXIPG          2048    /* max number inodes/cyl group */
 
 /*
  * and that MAXBSIZE must be >= MINBSIZE.
  */
 #define MINBSIZE       4096
  * and that MAXBSIZE must be >= MINBSIZE.
  */
 #define MINBSIZE       4096
-#define        DESCPG          16      /* desired fs_cpg */
 #define        MAXCPG          32      /* maximum fs_cpg */
 
 /*
 #define        MAXCPG          32      /* maximum fs_cpg */
 
 /*
@@ -178,15 +141,19 @@ struct    fs
        long    fs_bsize;               /* size of basic blocks in fs */
        long    fs_fsize;               /* size of frag blocks in fs */
        long    fs_frag;                /* number of frags in a block in fs */
        long    fs_bsize;               /* size of basic blocks in fs */
        long    fs_fsize;               /* size of frag blocks in fs */
        long    fs_frag;                /* number of frags in a block in fs */
+/* these are configuration parameters */
        long    fs_minfree;             /* minimum percentage of free blocks */
        long    fs_rotdelay;            /* num of ms for optimal next block */
        long    fs_rps;                 /* disk revolutions per second */
        long    fs_minfree;             /* minimum percentage of free blocks */
        long    fs_rotdelay;            /* num of ms for optimal next block */
        long    fs_rps;                 /* disk revolutions per second */
+/* these fields can be computed from the others */
        long    fs_bmask;               /* ``blkoff'' calc of blk offsets */
        long    fs_fmask;               /* ``fragoff'' calc of frag offsets */
        long    fs_bshift;              /* ``lblkno'' calc of logical blkno */
        long    fs_fshift;              /* ``numfrags'' calc number of frags */
        long    fs_bmask;               /* ``blkoff'' calc of blk offsets */
        long    fs_fmask;               /* ``fragoff'' calc of frag offsets */
        long    fs_bshift;              /* ``lblkno'' calc of logical blkno */
        long    fs_fshift;              /* ``numfrags'' calc number of frags */
+/* these are configuration parameters */
        long    fs_maxcontig;           /* max number of contiguous blks */
        long    fs_maxbpg;              /* max number of blks per cyl group */
        long    fs_maxcontig;           /* max number of contiguous blks */
        long    fs_maxbpg;              /* max number of blks per cyl group */
+/* these fields can be computed from the others */
        long    fs_fragshift;           /* block to frag shift */
        long    fs_fsbtodb;             /* fsbtodb and dbtofsb shift constant */
        long    fs_sbsize;              /* actual size of super block */
        long    fs_fragshift;           /* block to frag shift */
        long    fs_fsbtodb;             /* fsbtodb and dbtofsb shift constant */
        long    fs_sbsize;              /* actual size of super block */
@@ -234,8 +201,7 @@ struct      fs
  * N.B. This macro assumes that sizeof(struct csum) is a power of two.
  */
 #define fs_cs(fs, indx) \
  * N.B. This macro assumes that sizeof(struct csum) is a power of two.
  */
 #define fs_cs(fs, indx) \
-       fs_csp[(indx) / ((fs)->fs_bsize / sizeof(struct csum))] \
-       [(indx) % ((fs)->fs_bsize / sizeof(struct csum))]
+       fs_csp[(indx) >> (fs)->fs_csshift][(indx) & ~(fs)->fs_csmask]
 
 /*
  * MAXBPC bounds the size of the rotational layout tables and
 
 /*
  * MAXBPC bounds the size of the rotational layout tables and
@@ -280,14 +246,14 @@ struct    cg {
  * by the number of remaining bits.
  */
 #define        MAXBPG(fs) \
  * by the number of remaining bits.
  */
 #define        MAXBPG(fs) \
-       (NBBY * ((fs)->fs_bsize - (sizeof (struct cg))) / (fs)->fs_frag)
+       (NBBY * ((fs)->fs_bsize - (sizeof (struct cg))) >> (fs)->fs_fragshift)
 
 /*
  * Turn file system block numbers into disk block addresses.
  * This maps file system blocks to device size blocks.
  */
 
 /*
  * Turn file system block numbers into disk block addresses.
  * This maps file system blocks to device size blocks.
  */
-#define fsbtodb(fs, b) ((b) * ((fs)->fs_fsize / DEV_BSIZE))
-#define        dbtofsb(fs, b)  ((b) / ((fs)->fs_fsize / DEV_BSIZE))
+#define fsbtodb(fs, b) ((b) << (fs)->fs_fsbtodb)
+#define        dbtofsb(fs, b)  ((b) >> (fs)->fs_fsbtodb)
 
 /*
  * Cylinder group macros to locate things in cylinder groups.
 
 /*
  * Cylinder group macros to locate things in cylinder groups.
@@ -311,7 +277,7 @@ struct      cg {
 #define        itog(fs, x)     ((x) / (fs)->fs_ipg)
 #define        itod(fs, x) \
        ((daddr_t)(cgimin(fs, itog(fs, x)) + \
 #define        itog(fs, x)     ((x) / (fs)->fs_ipg)
 #define        itod(fs, x) \
        ((daddr_t)(cgimin(fs, itog(fs, x)) + \
-       (x) % (fs)->fs_ipg / INOPB(fs) * (fs)->fs_frag))
+       ((((x) % (fs)->fs_ipg) / INOPB(fs)) << (fs)->fs_fragshift)))
 
 /*
  * Give cylinder group number for a file system block.
 
 /*
  * Give cylinder group number for a file system block.
@@ -353,30 +319,30 @@ struct    cg {
  * Determining the size of a file block in the file system.
  */
 #define blksize(fs, ip, lbn) \
  * Determining the size of a file block in the file system.
  */
 #define blksize(fs, ip, lbn) \
-       (((lbn) >= NDADDR || (ip)->i_size >= ((lbn) + 1) * (fs)->fs_bsize) \
+       (((lbn) >= NDADDR || (ip)->i_size >= ((lbn) + 1) << (fs)->fs_bshift) \
            ? (fs)->fs_bsize \
            : (fragroundup(fs, blkoff(fs, (ip)->i_size))))
 #define dblksize(fs, dip, lbn) \
            ? (fs)->fs_bsize \
            : (fragroundup(fs, blkoff(fs, (ip)->i_size))))
 #define dblksize(fs, dip, lbn) \
-       (((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) * (fs)->fs_bsize) \
+       (((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->fs_bshift) \
            ? (fs)->fs_bsize \
            : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
 
 /*
  * Number of disk sectors per block; assumes DEV_BSIZE byte sector size.
  */
            ? (fs)->fs_bsize \
            : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
 
 /*
  * Number of disk sectors per block; assumes DEV_BSIZE byte sector size.
  */
-#define        NSPB(fs)        ((fs)->fs_bsize / DEV_BSIZE)
-#define        NSPF(fs)        ((fs)->fs_fsize / DEV_BSIZE)
+#define        NSPB(fs)        ((fs)->fs_nspf << (fs)->fs_fragshift)
+#define        NSPF(fs)        ((fs)->fs_nspf)
 
 /*
  * INOPB is the number of inodes in a secondary storage block.
  */
 
 /*
  * INOPB is the number of inodes in a secondary storage block.
  */
-#define        INOPB(fs)       ((fs)->fs_bsize / sizeof (struct dinode))
-#define        INOPF(fs)       ((fs)->fs_fsize / sizeof (struct dinode))
+#define        INOPB(fs)       ((fs)->fs_inopb)
+#define        INOPF(fs)       ((fs)->fs_inopb >> (fs)->fs_fragshift)
 
 /*
  * NINDIR is the number of indirects in a file system block.
  */
 
 /*
  * NINDIR is the number of indirects in a file system block.
  */
-#define        NINDIR(fs)      ((fs)->fs_bsize / sizeof (daddr_t))
+#define        NINDIR(fs)      ((fs)->fs_nindir)
 
 #ifdef KERNEL
 struct fs *getfs();
 
 #ifdef KERNEL
 struct fs *getfs();