Commit Graph

698 Commits

Author SHA1 Message Date
wiz 358ed3f6d4 Fix a typo, a KNF-nit, and simplify a printf format string. 2002-03-18 13:38:52 +00:00
chs 79c365e60e don't do any flush-behind for async mounts.
this matches the traditional behaviour.
2002-03-17 23:58:09 +00:00
chs c1d184702f when mounting a filesystem, read the last block in the filesystem
to verify that the device is at least as big as the superblock claims
the filesystem is supposed to be, and if it's not then fail the mount.
this should help reduce the type of confusion reported in PR 13228.
2002-03-17 00:02:34 +00:00
thorpej a180cee23b Pool deals fairly well with physical memory shortage, but it doesn't
deal with shortages of the VM maps where the backing pages are mapped
(usually kmem_map).  Try to deal with this:

* Group all information about the backend allocator for a pool in a
  separate structure.  The pool references this structure, rather than
  the individual fields.
* Change the pool_init() API accordingly, and adjust all callers.
* Link all pools using the same backend allocator on a list.
* The backend allocator is responsible for waiting for physical memory
  to become available, but will still fail if it cannot callocate KVA
  space for the pages.  If this happens, carefully drain all pools using
  the same backend allocator, so that some KVA space can be freed.
* Change pool_reclaim() to indicate if it actually succeeded in freeing
  some pages, and use that information to make draining easier and more
  efficient.
* Get rid of PR_URGENT.  There was only one use of it, and it could be
  dealt with by the caller.

From art@openbsd.org.
2002-03-08 20:48:27 +00:00
simonb 9a942a34e0 Don't use local extern declarations for the mountroot variable or
declare local prototypes for nfs_mountroot() or md_root_setconf().
2002-03-04 02:25:21 +00:00
pooka 360cafaddb Don't add fs->fs_pendingblocks to f_bavail twice. It's already included
in f_bfree, which is added to f_bavail.

Fixes problem with statfs reporting too much free space for filesystems
which have files pending to be freed by softdeps.
2002-02-28 21:59:23 +00:00
enami 70ca5d5195 Record some page cache related information into ubchist. 2002-02-22 08:23:16 +00:00
wiz c809c3243b Fix two problems with softdep_typenames (missing entry, wrong boundary check).
Okayed by fvdl.
2002-02-14 00:49:56 +00:00
perseant f41358613c Include the space taken by inodes in the count made by lfs_check();
make VOP_SETATTR call lfs_check.  This prevents large numbers of inode
changes (say, at the end of tar(1)) from filling the buffer cache.
2002-02-11 02:47:29 +00:00
chs 94cfc87907 bring in the change from FreeBSD's rev. 1.107 of this file:
date: 2002/02/07 00:54:32;  author: mckusick;  state: Exp;  lines: +10 -7
  Occationally deleted files would hang around for hours or days
  without being reclaimed. This bug was introduced in revision 1.95
  dealing with filenames placed in newly allocated directory blocks,
  thus is not present in 4.X systems. The bug is triggered when a
  new entry is made in a directory after the data block containing
  the original new entry has been written, but before the inode
  that references the data block has been written.

  Submitted by:   Bill Fenner <fenner@research.att.com>

This should fix NetBSD PR 15531.
2002-02-10 18:06:03 +00:00
lukem caa29fae38 #undef DIRBLKSIZ before #define-ing it 2002-02-06 15:44:49 +00:00
perseant 8ded9a2c7d Correct free list tail pointer, when adding blocks of new inodes to v2
filesystems.  Should fix PR #14408.
2002-02-04 03:32:16 +00:00
chs eecf9e208a fix PR 15299 by making MFS filesystems not be "async".
in the longer term, MFS needs to be made a lot more VM-friendly.
2002-02-03 03:51:57 +00:00
tv 880a2cf970 These sources are pulled into makefs(8), so we need config.h and protection
for __KERNEL_RCSID().
2002-01-31 19:19:22 +00:00
tv 5d28098c5b Revert previous. This is actually being done a better way. 2002-01-31 19:18:18 +00:00
tv 8ec192426e For makefs, only include <machine/bswap.h> if it exists. 2002-01-31 19:17:02 +00:00
tv af3dca1ea8 #undef MAXNAMLEN before defining it; this lets ufs/ufs/dir.h be used
properly on non-NetBSD hosts with makefs(8).
2002-01-31 19:16:34 +00:00
chs 1b454dbb4f fix an error case. 2002-01-26 08:32:05 +00:00
enami ac35ac58f5 - For CIRCLEQ, comparing the loop variable against NULL doesn't make sense.
- Minor KNF while I'm here.

# This doesn't fix real problems though.
2002-01-18 00:30:03 +00:00
enami 9ad4436bc2 Fix typo which prevents diagnostic test from working. 2002-01-16 08:33:12 +00:00
lukem 25ca00a979 Only pull in <sys/systm.h> #ifdef _KERNEL, since it's a kernel only header.
In the ! _KERNEL case, provide own prototype for panic() instead.
2002-01-09 23:51:00 +00:00
lukem 202e920175 revert part of rev 1.14 - #include <ufs/ufs/dinode.h> - because that
makes it MUCH more difficult to reference this file stand-alone.
2002-01-07 15:25:22 +00:00
thorpej fdb5b56e5f Do not compare an integer to NULL. 2001-12-31 21:37:22 +00:00
fvdl a833eaf1fe XXXX temporary measure: in the case of a softdep 'unmount pending error',
do not mark the filesystem clean, as this will mean that one or more
     files were likely not completely removed (will show up as unconnected
     in fsck). Prevents filesystems from being marked clean while they're
     not until this problem has been figured out.
2001-12-30 15:46:53 +00:00
fvdl d0f7c6fb96 Use softdep_change_linkcnt to note that the inode mode was set to 0.
From FreeBSD.
2001-12-27 01:48:38 +00:00
fvdl c9218f8686 The softdep code sometimes use vfs_vget .. vput. For removals, these
would result in a vop_inactive call for the vnode each time, resulting
in vinvalbuf->fsync. The original softdep code avoided the fsync
in vinvalbuf by not calling it if there were no dirty blocks. This
was changed in NetBSD. Also, flush_inodedeps was changed to mark
the inode as modified so that it would do an inode update and flush the
last one. This combination basically caused a sync write for each removed
file in an rm -rf (showing up delayed from the syncer a lot of the time).

If called from vinvalbuf (FSYNC_RECLAIM), and there were no dirty blocks
or pages to begin with, still do everything as normal, so that possible dirty
blocks in transit to disk are properly waited for, etc, but don't pass
UPDATE_WAIT to VOP_UPDATE, since there is no need for it in that case.
2001-12-27 01:44:59 +00:00
fvdl 2b5fe12a98 Pull over one missed fix from FreeBSD wrt. running out of quota. Also
reshuffle some code a bit to make it look more similar (no functional
change).
2001-12-27 01:29:05 +00:00
fvdl 08f29df58c As pointed out by mycroft and reflected in the comment, update the
directory inode before creating the new entry (not the freshly alloced
directory which isn't linked anywhere yet).
2001-12-23 16:16:59 +00:00
fvdl 983d322c7c Fix botch in my original softdep code merge: remove redundant (and
synchronous to boot) VOP_UPDATE call.
2001-12-23 14:00:21 +00:00
fvdl f1db177e10 Fix from FreeBSD that I missed: speed up handling of short-lived
files a bit.
2001-12-23 11:54:46 +00:00
chs 2ddcad30f6 process the delayed-free queue more often. 2001-12-23 08:53:46 +00:00
fvdl 68728c0901 ffs_reload may be called after an old fsck has run, and the pending*
fields may not be zero. Just reset them silently, it's not an error.
2001-12-19 15:20:19 +00:00
fvdl 3d8b2ffe36 Bring over fixes from FreeBSD that weren't incorporated yet, mainly
from Kirk McKusick. They implement taking pending block/inode frees
into account for the sake of correct statfs() numbers, and adding
a new softdep type (newdirblk) to correctly handle newly allocated
directory blocks.

Minor additional changes: 1) swap the newly introduced fs_pendinginodes
and fs_pendingblock fields in ffs_sb_swap, and 2) declare lkt_held
in the debug version of the softdep lock structure volatile, as it
can be modified from interrupt context #ifdef DEBUG.
2001-12-18 10:57:21 +00:00
chs 0d70d731c2 use the new compatibility routines to allow mmap() to work
(in the same non-coherent fashion that it worked pre-UBC)
until someone has time to do it the right way.
2001-12-18 07:51:16 +00:00
chs 03dd7ce1e8 when truncating a file, make sure the last block of the file is actually
allocated, since other parts of the code assume this.
2001-12-18 06:50:28 +00:00
chs 5a690c92a1 add a VOP_PUTPAGES method for all the filesystems that don't have pages,
just unlock the interlock.
2001-12-06 04:27:40 +00:00
chs a4f1bc813a pick up changes from ufs_balloc_range(). 2001-11-30 07:06:19 +00:00
chs 9958c29316 VOP_PUTPAGES() requires page-aligned offsets, so be sure to provide such.
fixes PR 14759.

(while I'm here, call VOP_PUTPAGES() directly instead of indirecting through
the UVM pager op vector.)
2001-11-30 07:05:53 +00:00
chs a106161b5a add spaces for KNF. confirmed to produce identical objects. 2001-11-23 21:44:25 +00:00
chs 3f9a8628df we need to hold the pageq lock while calling uvm_page_unbusy() on
pages that uvm_page_unbusy() will free.
2001-11-22 02:42:37 +00:00
lukem 4a269de9a1 fix compile error noted by itojun in [kern/14638] 2001-11-19 11:56:50 +00:00
lukem 5b0ef8ec1a be consistent and cache UFS_*NEEDSWAP results in more functions 2001-11-19 07:00:21 +00:00
simonb f809eb7333 Set `flags' before being used in the WRITE() function. 2001-11-17 07:22:34 +00:00
lukem 2ee0a3f232 move code to calculate size of direct for a given namlen to separate
DIRECTSIZ() macro, and use this to implement a (now shorter) DIRSIZ().
inspired by freebsd
2001-11-16 16:09:17 +00:00
lukem 2565646230 don't need <sys/types.h> when including <sys/param.h> 2001-11-15 09:47:59 +00:00
chs 4b4425d13b some callers of ufs_bmaparray() in LFS depend on *nump being set to 0 for
direct blocks, so restore that behaviour.
2001-11-13 06:23:17 +00:00
chs dc4cf974e0 track some changes in the ufs code:
update UVM's notion of the file size in *_write() rather than
*_balloc().
2001-11-10 17:48:02 +00:00
chs c237f81065 update to track ufs_bmap.c:
don't call ufs_getlbns() for direct blocks.
2001-11-10 17:46:23 +00:00
chs 9f52e62b73 fix the previous change: use the correct test for a block number
referring to a direct block.
2001-11-10 07:11:00 +00:00
chs 81625d675b the previous fix (in rev. 1.26) for hangs when the filesystem is full
was wrong, so fix it right this time.  undo the previous change and
instead, replace the troublesome VOP_FSYNC()s with code that just flushes
the particular indirect blocks that we allocated.  this resolves the
softdeps for those blocks.  then we can change the pointer for
the first indirect block we allocated to zero, write that, and finally
invalidate all the indirect blocks we've touched.  also, wait until
after we finish all this before freeing any blocks we allocated.
fixes PRs 14413 and 14423.
2001-11-08 05:27:25 +00:00
chs df71d3fadc in both paths that can cause fragments to be expanded (write and truncate-up),
deal with the fragment expansion separately before the rest of the operation.
this allows us to simplify ufs_balloc_range() by not worrying about implicit
fragment expansion.

call VOP_PUTPAGES() directly for vnodes instead of
going through the UVM pager "put" vector.
2001-11-08 05:24:52 +00:00
chs 0de5f1ba39 only call ufs_getlbns() for blocks which involve indirects, and assert
that this is so.  use a shift instead of a multiply in one place.
2001-11-08 05:00:51 +00:00
chs f57fce8e9e call VOP_PUTPAGES() directly for vnodes instead of
going through the UVM pager "put" vector.
2001-11-08 04:51:05 +00:00
lukem 6ff2f2f438 add RCSID. (note; this file gets #included) 2001-11-08 02:42:31 +00:00
lukem ec6245465a add RCSID 2001-11-08 02:39:06 +00:00
simonb c56d879335 Remove some variables that are set but never used. 2001-11-06 07:11:29 +00:00
simonb 915441c64b Use the sector size from the partition info, not a hard-coded value. 2001-11-06 07:09:39 +00:00
simonb ecf09baab6 Remove a variable that is set but never used. 2001-11-06 07:08:09 +00:00
simonb bb57e2c53c Remove some bogus checks for unsigned variables < 0. 2001-11-06 06:59:05 +00:00
simonb 6129c87d2e Remove superfluous semicolon. 2001-11-06 06:40:44 +00:00
lukem b3b9740195 add __KERNEL_RCSID() 2001-10-30 01:11:53 +00:00
lukem 80ac606906 ffs_sb_swap() fixes:
- calculate the offset and length of the postbl before byteswapping.
  problem noted by der Mouse.
- use offsetof() to determine # of fields to calculate in initial
  loop, rather than hard-coding in `52 fields'
- improve comments.
2001-10-29 11:26:35 +00:00
lukem 6f39841c03 - pull in ufsmount.h after inode.h, because the latter pulls in
quota.h which the former needs, and this makes the usage consistent
  with other files anyway
- expand the details in a few panic strings
2001-10-26 06:37:55 +00:00
lukem 99147a7648 remove #include <ufs/ufs/quota.h> where it was just to appease
<ufs/ufs/inode.h>, since the latter now includes the former.  leave the former
in source that obviously uses specific bits of it (for completeness.)
2001-10-26 05:56:06 +00:00
lukem d0dc904dae this needs <ufs/ufs/quota.h>, so pull it in 2001-10-26 05:46:57 +00:00
lukem a9439165d0 rename inclusion protection define from _QUOTA_ to _UFS_UFS_QUOTA_H_ 2001-10-26 05:44:29 +00:00
chs a2e3e57398 initialize the vnode's copy of the size in lfs_ialloc(). 2001-10-14 19:06:16 +00:00
chs eaa7f39f23 in ufs_balloc_range(), if we extend a fragment and need to write the
fragment synchronously, update the vnode's size before doing the flush.
otherwise we might only write part of the data and cause softdep's
accounting to get out of sync.  fixes PR 14201.
many thanks to enami for figuring out what was going on.
2001-10-10 06:37:53 +00:00
chs 8b8f98cdbe don't do any flush-behind for async mounts.
this matches the traditional behaviour.
2001-10-03 05:02:46 +00:00
chs d4406ff8c9 in ffs_balloc(), clean up page cache state to avoid hangs when we
get ENOSPC. as a result of this, we now skip some of the normal cleanup
in ufs_balloc_range() in the error case.
2001-09-30 02:54:42 +00:00
chs 9f02fbe7a7 process one block at a time even when we're using the write fast path
that avoids zeroing pages.  this avoids a mess when we get ENOSPC and
softdeps are enabled.
2001-09-30 02:50:35 +00:00
chs 80373b7e54 don't depend on other headers to include sys/proc.h for us. 2001-09-28 11:59:51 +00:00
chs 299934b2ed handle allocation errors in truncate-up case. 2001-09-28 11:43:23 +00:00
chs d288111138 undo the part of the previous revision about skipping
the put if there are no pages, that seems to cause some problem.
fix another problem with missing an splx(), spotted by enami.
2001-09-26 06:20:50 +00:00
chs e8be8c6351 be sure to call the pager put with page-aligned offsets.
spotted by Nathan Williams.

while I'm here, move an splbio() so that we don't return without
splx()ing it if there's an error, and don't bother calling the
pager put if the vnode has no pages.
2001-09-26 05:25:03 +00:00
chs a29a7b1934 when creating a symlink, set the vnode's copy of the size also. 2001-09-23 05:28:23 +00:00
chs 520b477a5a check early for reads beyond EOF. 2001-09-22 22:44:08 +00:00
sommerfeld 181c4513dc Add fifo_putpages() placebo so that the vnode's uobj is unlocked. 2001-09-22 22:35:18 +00:00
chs 3be896ac31 we can't assert that the inode and vnode sizes are consistent at the start
of ffs_truncate() since there are cases (eg. when ffs_write() gets ENOSPC)
where they should be different.  move the assert to the end instead.
2001-09-20 08:25:59 +00:00
lukem 9c5c77ae54 - ffs_blkpref() changes:
- don't both updating fs->fs_cgrotor, since it's actually not used in
	  the kernel. from Manuel Bouyer in [kern/3389]
	- when examining cylinder groups from startcg to startcg-1 (wrapping
	  at fs->fs_ncg), there's no need to check startcg at the end as well
	  as the start...
- highlight in the struct fs declaration that fs_cgrotor is UNUSED
2001-09-19 01:38:16 +00:00
chs 9699742484 make LFS work again. 2001-09-16 13:57:56 +00:00
jdolecek 68aacb8f70 add softdep_reinitialize() stub 2001-09-16 13:51:45 +00:00
chs 64c6d1d2dc a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps.  this is
   required now, since I've removed the globals that expose the address range.
   pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
   no longer any need to special-case it.
 - eliminate struct uvm_vnode by moving its fields into struct vnode.
 - rewrite the pageout path.  the pager is now responsible for handling the
   high-level requests instead of only getting control after a bunch of work
   has already been done on its behalf.  this will allow us to UBCify LFS,
   which needs tighter control over its pages than other filesystems do.
   writing a page to disk no longer requires making it read-only, which
   allows us to write wired pages without causing all kinds of havoc.
 - use a new PG_PAGEOUT flag to indicate that a page should be freed
   on behalf of the pagedaemon when it's unlocked.  this flag is very similar
   to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
   pageout fails due to eg. an indirect-block buffer being locked.
   this allows us to remove the "version" field from struct vm_page,
   and together with shrinking "loan_count" from 32 bits to 16,
   struct vm_page is now 4 bytes smaller.
 - no longer use PG_RELEASED for swap-backed pages.  if the page is busy
   because it's being paged out, we can't release the swap slot to be
   reallocated until that write is complete, but unlike with vnodes we
   don't keep a count of in-progress writes so there's no good way to
   know when the write is done.  instead, when we need to free a busy
   swap-backed page, just sleep until we can get it busy ourselves.
 - implement a fast-path for extending writes which allows us to avoid
   zeroing new pages.  this substantially reduces cpu usage.
 - encapsulate the data used by the genfs code in a struct genfs_node,
   which must be the first element of the filesystem-specific vnode data
   for filesystems which use genfs_{get,put}pages().
 - eliminate many of the UVM pagerops, since they aren't needed anymore
   now that the pager "put" operation is a higher-level operation.
 - enhance the genfs code to allow NFS to use the genfs_{get,put}pages
   instead of a modified copy.
 - clean up struct vnode by removing all the fields that used to be used by
   the vfs_cluster.c code (which we don't use anymore with UBC).
 - remove kmem_object and mb_object since they were useless.
   instead of allocating pages to these objects, we now just allocate
   pages with no object.  such pages are mapped in the kernel until they
   are freed, so we can use the mapping to find the page to free it.
   this allows us to remove splvm() protection in several places.

The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-15 20:36:31 +00:00
chs 5d3eefe245 use pools for allocating most softdep datastructures. since we want to
allocate memory from kernel_map but some of the objects are freed from
interrupt context, we put objects on a queue instead of freeing them
immediately.  then in softdep_process_worklist() (which is called at
least once per second from the syncer), we process that queue and
free all the objects.  allocating from kernel_map instead of from kmem_map
allows us to have a much larger number of softdeps pending even in
configurations where kmem_map is relatively small.
2001-09-15 16:33:53 +00:00
chs adf5d360a7 add a new VFS op, vfs_reinit, which is called when desiredvnodes is
adjusted via sysctl.  file systems that have hash tables which are
sized based on the value of this variable now resize those hash tables
using the new value.  the max number of FFS softdeps is also recalculated.

convert various file systems to use the <sys/queue.h> macros for
their hash tables.
2001-09-15 16:12:54 +00:00
lukem 5c2ee5861d Incorporate the enhanced ffs_dirpref() by Grigoriy Orlov, as found in
FreeBSD (three commits; the initial work, man page updates, and a fix
to ffs_reload()), with the following differences:
- Be consistent between newfs(8) and tunefs(8) as to the options which
  set and control the tuning parameters for this work (avgfilesize & avgfpdir)
- Use u_int16_t instead of u_int8_t to keep track of the number of
  contiguous directories (suggested by Chuck Silvers)
- Work within our FFS_EI framework
- Ensure that fs->fs_maxclusters and fs->fs_contigdirs don't point to
  the same area of memory

The new algorithm has a marked performance increase, especially when
performing tasks such as untarring pkgsrc.tar.gz, etc.

The original FreeBSD commit messages are attached:

=====
mckusick    2001/04/10 01:39:00 PDT
  Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
  His description of the problem and solution follow. My own tests show
  speedups on typical filesystem intensive workloads of 5% to 12% which
  is very impressive considering the small amount of code change involved.

  ------

    One day I noticed that some file operations run much faster on
  small file systems then on big ones. I've looked at the ffs
  algorithms, thought about them, and redesigned the dirpref algorithm.

    First I want to describe the results of my tests. These results are old
  and I have improved the algorithm after these tests were done. Nevertheless
  they show how big the perfomance speedup may be. I have done two file/directory
  intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
  The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
  The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
  It contains 6596 directories and 13868 files. The test systems are:

  1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
     test is at wd1. Size of test file system is 8 Gb, number of cg=991,
     size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
     from Dec 2000 with BUFCACHEPERCENT=35

  2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
     at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
     number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
     OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50

  You can get more info about the test systems and methods at:
  http://www.ptci.ru/gluk/dirpref/old/dirpref.html

                                Test Results

               tar -xzf ports.tar.gz               rm -rf ports
    mode  old dirpref new dirpref speedup old dirprefnew dirpref speedup
                               First system
   normal     667         472      1.41       477        331       1.44
   async      285         144      1.98       130         14       9.29
   sync       768         616      1.25       477        334       1.43
   softdep    413         252      1.64       241         38       6.34
                               Second system
   normal     329         81       4.06       263.5       93.5     2.81
   async      302         25.7    11.75       112          2.26   49.56
   sync       281         57.0     4.93       263         90.5     2.9
   softdep    341         40.6     8.4        284          4.76   59.66

  "old dirpref" and "new dirpref" columns give a test time in seconds.
  speedup - speed increasement in times, ie. old dirpref / new dirpref.

  ------

  Algorithm description

  The old dirpref algorithm is described in comments:

  /*
   * Find a cylinder to place a directory.
   *
   * The policy implemented by this algorithm is to select from
   * among those cylinder groups with above the average number of
   * free inodes, the one with the smallest number of directories.
   */

  A new directory is allocated in a different cylinder groups than its
  parent directory resulting in a directory tree that is spreaded across
  all the cylinder groups. This spreading out results in a non-optimal
  access to the directories and files. When we have a small filesystem
  it is not a problem but when the filesystem is big then perfomance
  degradation becomes very apparent.

  What I mean by a big file system ?

    1. A big filesystem is a filesystem which occupy 20-30 or more percent
       of total drive space, i.e. first and last cylinder are physically
       located relatively far from each other.
    2. It has a relatively large number of cylinder groups, for example
       more cylinder groups than 50% of the buffers in the buffer cache.

  The first results in long access times, while the second results in
  many buffers being used by metadata operations. Such operations use
  cylinder group blocks and on-disk inode blocks. The cylinder group
  block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
  It is 2k in size for the default filesystem parameters. If new and
  parent directories are located in different cylinder groups then the
  system performs more input/output operations and uses more buffers.
  On filesystems with many cylinder groups, lots of cache buffers are
  used for metadata operations.

  My solution for this problem is very simple. I allocate many directories
  in one cylinder group. I also do some things, so that the new allocation
  method does not cause excessive fragmentation and all directory inodes
  will not be located at a location far from its file's inodes and data.
  The algorithm is:
  /*
   * Find a cylinder group to place a directory.
   *
   * 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 cylinder group.
   */

    My early versions of dirpref give me a good results for a wide range of
  file operations and different filesystem capacities except one case:
  those applications that create their entire directory structure first
  and only later fill this structure with files.

    My solution for such and similar cases is to limit a number of
  directories which may be created one after another in the same cylinder
  group without intervening file creations. For this purpose, I allocate
  an array of counters at mount time. This array is linked to the superblock
  fs->fs_contigdirs[cg]. Each time a directory is created the counter
  increases and each time a file is created the counter decreases. A 60Gb
  filesystem with 8mb/cg requires 10kb of memory for the counters array.

    The maxcontigdirs is a maximum number of directories which may be created
  without an intervening file creation. I found in my tests that the best
  performance occurs when I restrict the number of directories in one cylinder
  group such that all its files may be located in the same cylinder group.
  There may be some deterioration in performance if all the file inodes
  are in the same cylinder group as its containing directory, but their
  data partially resides in a different cylinder group. The maxcontigdirs
  value is calculated to try to prevent this condition. Since there is
  no way to know how many files and directories will be allocated later
  I added two optimization parameters in superblock/tunefs. They are:

          int32_t  fs_avgfilesize;   /* expected average file size */
          int32_t  fs_avgfpdir;      /* expected # of files per directory */

  These parameters have reasonable defaults but may be tweeked for special
  uses of a filesystem. They are only necessary in rare cases like better
  tuning a filesystem being used to store a squid cache.

  I have been using this algorithm for about 3 months. I have done
  a lot of testing on filesystems with different capacities, average
  filesize, average number of files per directory, and so on. I think
  this algorithm has no negative impact on filesystem perfomance. It
  works better than the default one in all cases. The new dirpref
  will greatly improve untarring/removing/coping of big directories,
  decrease load on cvs servers and much more. The new dirpref doesn't
  speedup a compilation process, but also doesn't slow it down.

  Obtained from:	Grigoriy Orlov <gluk@ptci.ru>
=====

=====
iedowse     2001/04/23 17:37:17 PDT
  Pre-dirpref versions of fsck may zero out the new superblock fields
  fs_contigdirs, fs_avgfilesize and fs_avgfpdir. This could cause
  panics if these fields were zeroed while a filesystem was mounted
  read-only, and then remounted read-write.

  Add code to ffs_reload() which copies the fs_contigdirs pointer
  from the previous superblock, and reinitialises fs_avgf* if necessary.

  Reviewed by:	mckusick
=====

=====
nik         2001/04/10 03:36:44 PDT
  Add information about the new options to newfs and tunefs which set the
  expected average file size and number of files per directory.  Could do
  with some fleshing out.
=====
2001-09-06 02:16:00 +00:00
lukem c50eb8cc85 deprecate fs_fscktime; we never used it.
in an effort to maintain compatibility with freebsd/openbsd/whatever,
i'm attempting to get the superblock format in sync, and freebsd uses
the int32_t at this position for `fs_pendinginodes'.

if we ever decide to implement fscktime functionality, we'll:
a) make sure to liaise with the other projects to reserve the same
   spare field
b) actually implement the code this time ...

(this is also preparing us for other changes, like the new dirpref code)
2001-09-03 14:52:17 +00:00
lukem e3ba61f9f3 Incorporate fix by iedowse @ FreeBSD to allow disks with large numbers of
cylinder groups to work correctly, with minor modifications by me to work
with our FFS_EI code.  From the FreeBSD commit message:

	The ffs superblock includes a 128-byte region for use by temporary
	in-core pointers to summary information. An array in this region
	(fs_csp) could overflow on filesystems with a very large number of
	cylinder groups (~16000 on i386 with 8k blocks). When this happens,
	other fields in the superblock get corrupted, and fsck refuses to
	check the filesystem.

	Solve this problem by replacing the fs_csp array in 'struct fs'
	with a single pointer, and add padding to keep the length of the
	128-byte region fixed. Update the kernel and userland utilities
	to use just this single pointer.

	With this change, the kernel no longer makes use of the superblock
	fields 'fs_csshift' and 'fs_csmask'. Add a comment to newfs/mkfs.c
	to indicate that these fields must be calculated for compatibility
	with older kernels.

	Reviewed by:    mckusick
2001-09-02 01:58:30 +00:00
lukem 563fb2d03f no need to cast arg to lblktosize() any more 2001-08-31 03:38:45 +00:00
lukem 2bfd8a2678 More fixes from FreeBSD (with changes):
- Cast blk argument to lblktosize() to (off_t), to prevent 32 bit overflow.
  whilst almost every use in ffs used this for small blknos, there are
  potential issues, and it's safer this way.  (as discussed with chuq)
- Use 64bit (off_t) math to calculate if we have hit our freespace() limit.
  Necessary for coherent results on filesystems bigger than 0.5Tb.
- Use lblktosize() in blksize() and dblksize(), to make it obvious what's
  happening
- Remove sblksize() - nothing uses it
2001-08-31 03:15:45 +00:00
lukem 0cf1d74c5b be consistent when casting arg to lblktosize() in UVM_PAGE_TRKOWN debug code 2001-08-30 15:17:28 +00:00
lukem c56418af73 some improvements from freebsd/openbsd
- replace the unused fs_headswitch and fs_trkseek with fs_id[2], bringing
  our struct fs closer to that in freebsd & openbsd (& solaris FWIW)
- dumpfs: improve warning message when cpc == 0
2001-08-30 14:37:25 +00:00
lukem c535133897 - minor whitespace and comments cleanup
- replace "filesystem" with "file system"
- fix spelo (from freebsd)
2001-08-30 08:31:25 +00:00
chs 1de4b3e2e0 min() -> MIN() (on general principles) 2001-08-30 03:55:42 +00:00
chs eccd469cf7 min() -> MIN() 2001-08-30 03:47:53 +00:00
wiz 251b3464be heirarchy -> hierarchy 2001-08-24 10:24:45 +00:00
chs cb3b720183 disable mmap() for LFS until it is fixed. 2001-08-24 06:42:46 +00:00
wiz 1e378c4c12 precede, not preceed. 2001-08-20 12:00:46 +00:00
chs f0af9f581b add getpages/putpages entries for spec vnodes. 2001-08-17 05:54:36 +00:00
lukem 1b81d6353d remove third argument (`int ns') from ffs_sb_swap(), and let ffs_sb_swap()
determine the endianness of the `struct fs *o' superblock from o->fs_magic
and set needswap as necessary, rather than trusting the caller to get
it right.  invariably, almost every caller of ffs_sb_swap() was calling it
with ns set to the wrong value for ns anyway!
ansi KNF ffs_bswap.c declarations whilst here.

this fixes all sorts of problems when trying to use other-endian file systems,
notably the kernel trying to access memory *way* off, possibly corrupting or
panicing, and userland programs SEGVing and/or corrupting things (e.g,
"fsck_ffs -B"  to swap a file system endianness).

whilst the previous rev of ffs_bswap.c (1.10, 2000/12/23) made this problem
worse, i suspect that the problem was always there and previous versions
just happened not to trash things at the wrong time.

FFS_EI should now be a lot more stable.
2001-08-17 02:18:46 +00:00