summaryrefslogtreecommitdiffstats
path: root/sys/ufs
diff options
context:
space:
mode:
Diffstat (limited to 'sys/ufs')
-rw-r--r--sys/ufs/ffs/ffs_alloc.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c
index cb0bfeda58a..249ac385938 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.111 2020/05/28 15:48:29 otto Exp $ */
+/* $OpenBSD: ffs_alloc.c,v 1.112 2020/05/29 06:46:15 otto Exp $ */
/* $NetBSD: ffs_alloc.c,v 1.11 1996/05/11 18:27:09 mycroft Exp $ */
/*
@@ -515,7 +515,7 @@ ffs_dirpref(struct inode *pip)
maxcontigdirs = 1;
/*
- * Limit number of dirs in one cg and reserve space for
+ * Limit number of dirs in one cg and reserve space for
* regular files, but only if we have no deficit in
* inodes or space.
*
@@ -524,16 +524,17 @@ ffs_dirpref(struct inode *pip)
* We scan from our preferred cylinder group forward looking
* for a cylinder group that meets our criterion. If we get
* to the final cylinder group and do not find anything,
- * we start scanning backwards from our preferred cylinder
- * group. The ideal would be to alternate looking forward
- * and backward, but tha tis just too complex to code for
- * the gain it would get. The most likely place where the
- * backward scan would take effect is when we start near
- * the end of the filesystem and do not find anything from
- * where we are to the end. In that case, scanning backward
- * will likely find us a suitable cylinder group much closer
- * to our desired location than if we were to start scanning
- * forward from the beginning for the filesystem.
+ * we start scanning forwards from the beginning of the
+ * filesystem. While it might seem sensible to start scanning
+ * backwards or even to alternate looking forward and backward,
+ * this approach fails badly when the filesystem is nearly full.
+ * Specifically, we first search all the areas that have no space
+ * and finally try the one preceding that. We repeat this on
+ * every request and in the case of the final block end up
+ * searching the entire filesystem. By jumping to the front
+ * of the filesystem, our future forward searches always look
+ * in new cylinder groups so finds every possible block after
+ * one pass over the filesystem.
*/
for (cg = prefcg; cg < fs->fs_ncg; cg++)
if (fs->fs_cs(fs, cg).cs_ndir < maxndir &&
@@ -542,7 +543,7 @@ ffs_dirpref(struct inode *pip)
if (fs->fs_contigdirs[cg] < maxcontigdirs)
goto end;
}
- for (cg = prefcg - 1; cg >= 0; cg--)
+ for (cg = 0; cg < prefcg; cg++)
if (fs->fs_cs(fs, cg).cs_ndir < maxndir &&
fs->fs_cs(fs, cg).cs_nifree >= minifree &&
fs->fs_cs(fs, cg).cs_nbfree >= minbfree) {
@@ -555,7 +556,7 @@ ffs_dirpref(struct inode *pip)
for (cg = prefcg; cg < fs->fs_ncg; cg++)
if (fs->fs_cs(fs, cg).cs_nifree >= avgifree)
goto end;
- for (cg = prefcg - 1; cg >= 0; cg--)
+ for (cg = 0; cg < prefcg; cg++)
if (fs->fs_cs(fs, cg).cs_nifree >= avgifree)
goto end;
end: