Commit Graph

65 Commits

Author SHA1 Message Date
dbj 43395bd5a8 Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ.  Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array.  Support is added for managing
the Apple UFS volume label.
2002-09-28 20:11:05 +00:00
mycroft f127f0f067 Some manual strength reduction. 2002-04-10 17:28:13 +00:00
mycroft 3bc20d3480 Remove debugging output. 2002-04-10 08:27:54 +00:00
mycroft 9eab713623 Use fs_fragshift more. Simplify a bunch of arithmetic involving NSPF(). 2002-04-10 08:27:23 +00:00
lukem 94243a4cd5 wrap some mfs specific code in #ifdef MFS 2002-01-18 08:59:18 +00:00
simonb ab5ccee692 Add the ability for the user, group and permissions of an MFS to be set
on the command line with the -u, -g and -p options respectively.
The old malloc() replacement (and related functions) didn't work with
the libc get{pw,gr}nam() functions so it was removed and a separate
memory allocation function added that is only called to allocate the
space for the MFS file system.
Also use a table for the usage flags instead of multiple fprintf()'s
with "if (mfs)" checks sprinkled through.
2002-01-07 12:00:09 +00:00
lukem 4c7a4f8eda don't bother printing a warning about the cylinder group size being
restricted if -c isn't given; it just confuses a user of newfs (and
the cpg info is printed as part of the display anyway), and prints an
unnecessary warning for mount_mfs.
2001-12-31 07:07:58 +00:00
lukem c00b68cf31 clamp bsize to MAXBSIZE 2001-12-13 06:31:31 +00:00
lukem 9f95bf0782 fix error reporting in rdfs() and wtfs() 2001-10-14 01:38:53 +00:00
lukem 058b690102 the change of calculation of inodes per group in rev 1.52 was far too
aggressive; rework to be a bit less susceptable to round-off error.
now it's likely that the density might not be obtained with a small
filesystem with a large number of inodes (e.g -s 4M -i 1k), but that's
an extremely unlikely corner case that can easily be rectified with
command-line arguments.
fixed provided in private email by Takao Shinohara <shin@sm.sony.co.jp>
should resolve PRs [bin/14049] and [bin/14046]
2001-09-24 08:21:44 +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 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 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 063df7cfb7 various calcipg() fixes:
- fix round-off errors when determining the number of inodes per group,
  which often resulted in the total number of inodes in the file system
  being less than what the density asked for.
  now you might get more inodes than requested for a given density,
  rather than less.
- if the new inodes/group is <= 0, ensure that it's at least 1, preventing
  a possible division by zero or other wacky problems
- use long long instead of quad_t
2001-08-25 01:42:46 +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
lukem 8a6a290e5a revert rev 1.48 for now, until i'm sure the malloc (et al) rename is
safe (since there's two separate mallocs using sbrk(2) in that case)

XXX: local malloc provided for mfs memory store allocation; need to
investigate if system (phk) malloc can be used instead.
2001-07-31 01:31:26 +00:00
lukem 2b2279d9a5 - constify mkfs()'s first arg
- slightly reorder steps in -F image creation
2001-07-30 07:45:08 +00:00
lukem 852833fff1 rename and hide: malloc->Malloc, calloc->Calloc, free->Free. (remove realloc) 2001-07-30 07:13:58 +00:00
lukem c67d40dc35 improve message describing MAXCSBUFS overflow 2001-07-27 15:19:33 +00:00
lukem bc1974136c s/filesystem/file system/ 2001-07-27 06:41:02 +00:00
lukem 8a54ab244e clean up for WARNS=2 by renaming some local variables that shadow globals 2001-07-26 22:59:57 +00:00
lukem b6172cb606 - check return value of calloc() in mkfs()
- in replacement malloc(), if sbrk(2) returns (void *)-1, convert to NULL
  before returning
- in replacement calloc(), check return value of malloc() before zeroing result
2001-07-26 16:53:39 +00:00
lukem 91d95899b4 remove unnecessary duplicate initialisation of sblock.fs_clean 2001-07-26 03:46:57 +00:00
enami 2f0c4425ee Don't swap clustersum[0]. It's not a cluster summery but block free bitmap. 2000-12-23 12:32:12 +00:00
scw 222e7ea5ea Fix a bug introduced by 4.4-Lite:
Don't try to subtract the address of "acg.cg_firstfield" from
"acg.cg_nextfreeoff", as it's already relative to the start of "&acg".
This always worked because the result of the subtraction was
always negative, thus could never be > "sblock.fs_cgsize" ...
2000-12-04 09:59:48 +00:00
simonb b234617a20 Put extern variable declarations in "extern.h". 2000-12-01 12:03:27 +00:00
simonb 06cbcf7494 ANSIfy. 2000-12-01 11:52:54 +00:00
bouyer bacd71f681 Check the number of cylinder group summary area against MAXCSBUFS. fsck and
the kernel will happilly trash data after fs_csp[] in the superblock with
a large number of cylinder group.
2000-05-22 10:33:45 +00:00
wrstuden 398c91fa04 Adjust column-sizing code to keep output in 76 character lines, so output
doesn't wrap in sysinst.
1999-07-30 17:44:01 +00:00
wrstuden 6735cc1a4c Make newfs's spare superblock output nicer. Figure out how wide the
largest block number will be, and make the columns wide enough for it. Then
make enough columns to fit in an 80 character window.

Samples: small end & faked up values:

super-block backups (for fsck -b #) at:
   32,  176,  272,  416,  512,  656,  752,  896,  992, 1136, 1232, 1376, 1472,
 1616, 1712, 1856, 1952, 2096, 2192, 2336, 2432, 2576, 2672, 2816, 2912, 3056,
 3152, 3296, 3392, 3536, 3632, 3776, 3872, 4016, 4112, 4256, 4352, 4496, 4592,

For a 155 GB fs we have:

super-block backups (for fsck -b #) at:
       128,     65792,    131456,    197120,    262784,    328448,    394112,
    459776,    525440,    591104,    656768,    722432,    788096,    853760,
    919424,    985088,   1050752,   1116416,   1182080,   1247744,   1313408,
   1379072,   1444736,   1510400,   1576064,   1641728,   1707392,   1773056,
...
 317462144, 317527808, 317593472, 317659136, 317724800, 317790464, 317856128,
 317921792, 317987456, 318053120, 318118784, 318184448, 318250112, 318315776,
 318381440, 318447104, 318512768, 318578432,

Now it actually looks like someone's thought about making large fs's. :-)
1999-05-14 22:36:50 +00:00
wrstuden f2c170eda0 Modify newfs so that the root node (and lost+found dir, if created)
of the new fs has uid.gid equal to the euid.egid of the process
which made it. This change permits users who have write access to
a device (say a floppy) to create a filesystem that, when mounted,
they have write access to.

This change closes PR bin/5990 from jbernard@ox.mines.edu, and is also the
change requested in PR bin/6276 from "Charles M. Hannum" <mycroft@netbsd.org>
1999-03-16 21:52:34 +00:00
wrstuden 988bdf8e19 Modify how the byteswapping of the cylinder summaries is handled. If we
need to swap, allocate a buffer for the swapped summaries rather than using
writebuf. The latter is fixed at 64k, which is only enough room to hold
4096 summaries. Creating an fs with more results in a buffer overrun.

First noted by Matt Jacob mjacob@netbsd.org, and fixed by Albeaus
Bayucan, bayucan@nas.nasa.gov. Minor mods by me.
1999-03-11 20:23:58 +00:00
simonb 00c4adc933 Explicitly zero "node" before we start using it. 1998-11-03 18:14:55 +00:00
thorpej a2d370bc46 Use DINODE_SIZE instead of sizeof(struct dinode). Also, eliminate some
unnecessary pointer casts.
1998-10-23 00:39:15 +00:00
kleink 31e5ddfa12 Need <time.h> for time() prototype. 1998-04-01 15:28:12 +00:00
bouyer 15c41b2f72 Allow creation of non-native byteorder FFS (via the '-B' option). 1998-03-18 17:10:15 +00:00
drochner 55f4357866 Make "mount_mfs" behave synchronously - don't exit before the mount is
done. This has 2 advantages:
-The calling process can rely on the mounted filesystem.
-We get error messages if the mount system call fails.
1997-11-01 18:25:46 +00:00
jeremy f83ae6979b Quell gcc 2.7.2 initialization warning. 1997-09-21 08:32:04 +00:00
lukem ec31f79470 * resolve conflicts from lite-2 import
* use int32_t instead of long
1997-09-16 14:05:39 +00:00
christos bec3b005c5 Fix compiler warnings. 1997-06-30 22:20:30 +00:00
cgd 93a2f4ea60 update for posixified stat structure 1995-06-18 21:35:33 +00:00
mycroft ae16273156 Back out previous change. 1995-06-11 05:16:04 +00:00
cgd 788733b7a9 typeof(timeval.tv_sec) != time_t 1995-06-07 17:14:21 +00:00
jtc 2d709c7062 flush stdout instead of stderr, so that each block number is displayed
as it is printed.  From PR 989.
1995-05-06 06:55:34 +00:00
mycroft 5a76ea02ce Set the `clean' flag. 1995-04-12 21:24:31 +00:00
cgd 0cc5c1886a short -> int16_t in a couple of places 1995-03-21 01:28:05 +00:00
cgd 0114e805ce convert to new RCS Id conventions; reduce my headache 1995-03-18 14:54:19 +00:00
cgd 909eb54fbb calculate the 'offset' argument to lseek() in a prettier way, more
consistent with the way fsck(8) does it.  no functional change.
1995-03-18 07:02:29 +00:00
cgd f9b9202a22 flush stdout after printing each alternate superblock location. 1995-03-04 06:28:20 +00:00
cgd 4c02b41140 fix up inconsisten uses of lseek(). (three uses. one hard-coded 'whence'
as a number, one used an L_ constant and the other used a SEEK_ constant!)
1995-03-04 06:10:39 +00:00