summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgluk <gluk@openbsd.org>2001-04-19 16:22:16 +0000
committergluk <gluk@openbsd.org>2001-04-19 16:22:16 +0000
commitbe7bc953ae67f1855e630223de113ec44e55ee96 (patch)
tree98675bc68f6bcd522e1f9201983c715d1bebcf01
parentundo change which breaks the alpha. I did not see this change and approve it during tree lock. Grrr (diff)
downloadwireguard-openbsd-be7bc953ae67f1855e630223de113ec44e55ee96.tar.xz
wireguard-openbsd-be7bc953ae67f1855e630223de113ec44e55ee96.zip
Cleanup dirpref and synhronize superblock with freebsd.
From FreeBSD with little changes. art@ ok.
-rw-r--r--sbin/fsck_ffs/setup.c8
-rw-r--r--sbin/newfs/mkfs.c17
-rw-r--r--sbin/newfs/newfs.c18
-rw-r--r--sys/ufs/ffs/ffs_alloc.c26
-rw-r--r--sys/ufs/ffs/ffs_vfsops.c6
-rw-r--r--sys/ufs/ffs/fs.h24
6 files changed, 67 insertions, 32 deletions
diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c
index 1852b6fdbf5..1918820f7f3 100644
--- a/sbin/fsck_ffs/setup.c
+++ b/sbin/fsck_ffs/setup.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: setup.c,v 1.10 2001/04/13 02:39:05 gluk Exp $ */
+/* $OpenBSD: setup.c,v 1.11 2001/04/19 16:22:17 gluk Exp $ */
/* $NetBSD: setup.c,v 1.27 1996/09/27 22:45:19 christos Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)setup.c 8.5 (Berkeley) 11/23/94";
#else
-static char rcsid[] = "$OpenBSD: setup.c,v 1.10 2001/04/13 02:39:05 gluk Exp $";
+static char rcsid[] = "$OpenBSD: setup.c,v 1.11 2001/04/19 16:22:17 gluk Exp $";
#endif
#endif /* not lint */
@@ -457,13 +457,15 @@ readsb(listerr)
altsblock.fs_rotdelay = sblock.fs_rotdelay;
altsblock.fs_maxbpg = sblock.fs_maxbpg;
memcpy(altsblock.fs_ocsp, sblock.fs_ocsp, sizeof sblock.fs_ocsp);
+ altsblock.fs_contigdirs = sblock.fs_contigdirs;
altsblock.fs_csp = sblock.fs_csp;
altsblock.fs_maxcluster = sblock.fs_maxcluster;
- altsblock.fs_contigdirs = sblock.fs_contigdirs;
altsblock.fs_avgfilesize = sblock.fs_avgfilesize;
altsblock.fs_avgfpdir = sblock.fs_avgfpdir;
memcpy(altsblock.fs_fsmnt, sblock.fs_fsmnt,
sizeof sblock.fs_fsmnt);
+ memcpy(altsblock.fs_snapinum, sblock.fs_snapinum,
+ sizeof sblock.fs_snapinum);
memcpy(altsblock.fs_sparecon, sblock.fs_sparecon,
sizeof sblock.fs_sparecon);
/*
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index aacecf48349..947382b6e5d 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkfs.c,v 1.17 2001/04/13 02:39:06 gluk Exp $ */
+/* $OpenBSD: mkfs.c,v 1.18 2001/04/19 16:22:17 gluk Exp $ */
/* $NetBSD: mkfs.c,v 1.25 1995/06/18 21:35:38 cgd Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)mkfs.c 8.3 (Berkeley) 2/3/94";
#else
-static char rcsid[] = "$OpenBSD: mkfs.c,v 1.17 2001/04/13 02:39:06 gluk Exp $";
+static char rcsid[] = "$OpenBSD: mkfs.c,v 1.18 2001/04/19 16:22:17 gluk Exp $";
#endif
#endif /* not lint */
@@ -105,6 +105,8 @@ extern int maxbpg; /* maximum blocks per file in a cyl group */
extern int nrpos; /* # of distinguished rotational positions */
extern int bbsize; /* boot block size */
extern int sbsize; /* superblock size */
+extern int avgfilesize; /* expected average file size */
+extern int avgfilesperdir; /* expected number of files per directory */
extern int quiet; /* quiet flag */
extern u_long memleft; /* virtual memory available */
extern caddr_t membase; /* start address of memory based filesystem */
@@ -206,6 +208,17 @@ recalc:
if (sblock.fs_nsect <= 0)
printf("preposterous nsect %d\n", sblock.fs_nsect), exit(15);
/*
+ * collect and verify the filesystem density info
+ */
+ sblock.fs_avgfilesize = avgfilesize;
+ sblock.fs_avgfpdir = avgfilesperdir;
+ if (sblock.fs_avgfilesize <= 0)
+ printf("illegal expected average file size %d\n",
+ sblock.fs_avgfilesize), exit(14);
+ if (sblock.fs_avgfpdir <= 0)
+ printf("illegal expected number of files per directory %d\n",
+ sblock.fs_avgfpdir), exit(15);
+ /*
* collect and verify the block and fragment sizes
*/
sblock.fs_bsize = bsize;
diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c
index 77d72a36ba3..301173b9335 100644
--- a/sbin/newfs/newfs.c
+++ b/sbin/newfs/newfs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: newfs.c,v 1.26 2001/04/14 03:15:54 gluk Exp $ */
+/* $OpenBSD: newfs.c,v 1.27 2001/04/19 16:22:18 gluk Exp $ */
/* $NetBSD: newfs.c,v 1.20 1996/05/16 07:13:03 thorpej Exp $ */
/*
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)newfs.c 8.8 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: newfs.c,v 1.26 2001/04/14 03:15:54 gluk Exp $";
+static char rcsid[] = "$OpenBSD: newfs.c,v 1.27 2001/04/19 16:22:18 gluk Exp $";
#endif
#endif /* not lint */
@@ -175,6 +175,8 @@ int maxcontig = 8; /* max contiguous blocks to allocate */
int rotdelay = ROTDELAY; /* rotational delay between blocks */
int maxbpg; /* maximum blocks per file in a cyl group */
int nrpos = NRPOS; /* # of distinguished rotational positions */
+int avgfilesize = AVFILESIZ;/* expected average file size */
+int avgfilesperdir = AFPDIR;/* expected number of files per directory */
int bbsize = BBSIZE; /* boot block size */
int sbsize = SBSIZE; /* superblock size */
int mntflags = MNT_ASYNC; /* flags to be passed to mount */
@@ -218,7 +220,7 @@ main(argc, argv)
opstring = mfs ?
"NT:a:b:c:d:e:f:i:m:o:s:" :
- "NOS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:qr:s:t:u:x:z:";
+ "NOS:T:a:b:c:d:e:f:g:h:i:k:l:m:n:o:p:qr:s:t:u:x:z:";
while ((ch = getopt(argc, argv, opstring)) != -1) {
switch (ch) {
case 'N':
@@ -263,6 +265,14 @@ main(argc, argv)
if ((fsize = atoi(optarg)) <= 0)
fatal("%s: bad fragment size", optarg);
break;
+ case 'g':
+ if ((avgfilesize = atoi(optarg)) <= 0)
+ fatal("%s: bad average file size", optarg);
+ break;
+ case 'h':
+ if ((avgfilesperdir = atoi(optarg)) <= 0)
+ fatal("%s: bad average files per dir", optarg);
+ break;
case 'i':
if ((density = atoi(optarg)) <= 0)
fatal("%s: bad bytes per inode\n", optarg);
@@ -728,6 +738,8 @@ struct fsoptions {
{ "-d rotational delay between contiguous blocks", 1 },
{ "-e maximum blocks per file in a cylinder group", 1 },
{ "-f frag size", 1 },
+ { "-g average file size", 0 },
+ { "-h average files per directory", 0 },
{ "-i number of bytes per inode", 1 },
{ "-k sector 0 skew, per track", 0 },
{ "-l hardware sector interleave", 0 },
diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c
index c323def393f..c473c617942 100644
--- a/sys/ufs/ffs/ffs_alloc.c
+++ b/sys/ufs/ffs/ffs_alloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_alloc.c,v 1.27 2001/04/06 20:43:31 gluk Exp $ */
+/* $OpenBSD: ffs_alloc.c,v 1.28 2001/04/19 16:22:16 gluk Exp $ */
/* $NetBSD: ffs_alloc.c,v 1.11 1996/05/11 18:27:09 mycroft Exp $ */
/*
@@ -636,13 +636,15 @@ noinodes:
/*
* Find a cylinder group to place a directory.
*
- * The policy implemented by this algorithm is to allocate inode
- * in the same cylinder group as a parent directory in, but also
- * reserve space for file's data and inodes. Restrict number of
- * directories which may be allocated one after another in a same
- * cg without intervening by files.
+ * The policy implemented by this algorithm is to allocate a
+ * directory inode in the same cylinder group as its parent
+ * directory, but also to reserve space for its files inodes
+ * and data. Restrict the number of directories which may be
+ * allocated one after another in the same cylinder group
+ * without intervening allocation of files.
+ *
* If we allocate a first level directory then force allocation
- * in another cg.
+ * in another cylinder group.
*/
static ino_t
ffs_dirpref(pip)
@@ -710,8 +712,6 @@ ffs_dirpref(pip)
#endif
cgsize = fs->fs_fsize * fs->fs_fpg;
dirsize = fs->fs_avgfilesize * fs->fs_avgfpdir;
- if (dirsize <= 0)
- dirsize = 16384 * 64;
curdirsize = avgndir ? (cgsize - avgbfree * fs->fs_bsize) / avgndir : 0;
if (dirsize < curdirsize)
dirsize = curdirsize;
@@ -733,8 +733,6 @@ ffs_dirpref(pip)
fs->fs_cs(fs, cg).cs_nbfree >= minbfree) {
if (fs->fs_contigdirs[cg] < maxcontigdirs)
goto end;
- else
- continue;
}
for (cg = 0; cg < prefcg; cg++)
if (fs->fs_cs(fs, cg).cs_ndir < maxndir &&
@@ -742,10 +740,10 @@ ffs_dirpref(pip)
fs->fs_cs(fs, cg).cs_nbfree >= minbfree) {
if (fs->fs_contigdirs[cg] < maxcontigdirs)
goto end;
- else
- continue;
}
- /* This work when we have deficit in space */
+ /*
+ * This is a backstop when we have deficit in space.
+ */
for (cg = prefcg; cg < fs->fs_ncg; cg++)
if (fs->fs_cs(fs, cg).cs_nifree >= avgifree)
goto end;
diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c
index cbeee670a6c..88fcc43e0fd 100644
--- a/sys/ufs/ffs/ffs_vfsops.c
+++ b/sys/ufs/ffs/ffs_vfsops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_vfsops.c,v 1.39 2001/04/15 23:46:29 gluk Exp $ */
+/* $OpenBSD: ffs_vfsops.c,v 1.40 2001/04/19 16:22:17 gluk Exp $ */
/* $NetBSD: ffs_vfsops.c,v 1.19 1996/02/09 22:22:26 christos Exp $ */
/*
@@ -807,6 +807,10 @@ ffs_oldfscompat(fs)
fs->fs_qbmask = ~fs->fs_bmask; /* XXX */
fs->fs_qfmask = ~fs->fs_fmask; /* XXX */
} /* XXX */
+ if (fs->fs_avgfilesize <= 0) /* XXX */
+ fs->fs_avgfilesize = AVFILESIZ; /* XXX */
+ if (fs->fs_avgfpdir <= 0) /* XXX */
+ fs->fs_avgfpdir = AFPDIR; /* XXX */
return (0);
}
diff --git a/sys/ufs/ffs/fs.h b/sys/ufs/ffs/fs.h
index e8e9f0bf3c1..2d8ed8abdc0 100644
--- a/sys/ufs/ffs/fs.h
+++ b/sys/ufs/ffs/fs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: fs.h,v 1.11 2001/04/13 02:39:04 gluk Exp $ */
+/* $OpenBSD: fs.h,v 1.12 2001/04/19 16:22:16 gluk Exp $ */
/* $NetBSD: fs.h,v 1.6 1995/04/12 21:21:02 mycroft Exp $ */
/*
@@ -117,7 +117,7 @@
* and the third points to an array that tracks the creation of new
* directories.
*/
-#define NOCSPTRS ((128 / sizeof(void *)) - 2)
+#define NOCSPTRS ((128 / sizeof(void *)) - 3)
/*
* A summary of contiguous blocks of various sizes is maintained
@@ -143,6 +143,16 @@
#define DEFAULTOPT FS_OPTTIME
/*
+ * The directory preference algorithm(dirpref) can be tuned by adjusting
+ * the following parameters which tell the system the average file size
+ * and the average number of files per directory. These defaults are well
+ * selected for typical filesystems, but may need to be tuned for odd
+ * cases like filesystems being used for sqiud caches or news spools.
+ */
+#define AVFILESIZ 16384 /* expected average file size */
+#define AFPDIR 64 /* expected number of files per directory */
+
+/*
* Per cylinder group information; summarized in blocks allocated
* from first cylinder group data blocks. These blocks have to be
* read in from fs_csaddr (size fs_cssize) in addition to the
@@ -228,19 +238,15 @@ struct fs {
/* these fields retain the current block allocation info */
int32_t fs_cgrotor; /* last cg searched */
void *fs_ocsp[NOCSPTRS]; /* padding; was list of fs_cs buffers */
+ u_int8_t *fs_contigdirs; /* # of contiguously allocated dirs */
struct csum *fs_csp; /* cg summary info buffer for fs_cs */
int32_t *fs_maxcluster; /* max cluster in each cyl group */
int32_t fs_cpc; /* cyl per cycle in postbl */
int16_t fs_opostbl[16][8]; /* old rotation block list head */
-#if LONG_BIT == 64
- int32_t fs_sparecon[45]; /* reserved for future constants */
-#else
- int32_t fs_sparecon[46]; /* reserved for future constants */
-#endif
-/* these fields used in dirpref routine for optimization */
- u_int8_t *fs_contigdirs; /* # of contiguously allocated dirs */
+ int32_t fs_snapinum[20]; /* reserved for snapshot inode nums */
int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */
+ int32_t fs_sparecon[27]; /* reserved for future constants */
time_t fs_fscktime; /* last time fsck(8)ed */
int32_t fs_contigsumsize; /* size of cluster summary array */
int32_t fs_maxsymlinklen; /* max length of an internal symlink */