History log of /freebsd-current/sbin/tunefs/tunefs.c
Revision Date Author Comments
# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


# 51e16cb8 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

sbin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 65f3be91 07-Jul-2023 Alfonso Gregory <gfunni234@gmail.com>

Mark usage function as __dead2 in programs where it does not return

In most cases, usage does not return, so mark them as __dead2. For the
cases where they do return, they have not been marked __dead2.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/735


# 906c312b 15-Jan-2023 Kirk McKusick <mckusick@FreeBSD.org>

Document the mntopts(3) functions.

The mntopts(3) functions support operations associated with a mount
point. The main purpose of this commit is to document the mntopts(3)
functions that now appear in 18 utilities in the base system. See
mntopts(3) for the documentation details.

The getmntopts() function appeared in 4.4BSD. The build_iovec(),
build_iovec_argf(), free_iovec(), checkpath(), and rmslashes()
functions were added with nmount(8) in FreeBSD 5.0. The getmntpoint()
and chkdoreload() functions are being added in this commit.

These functions should be in a library but for historic reasons are
in a file in the sources for the mount(8) program. Thus, to access
them the following lines need to be added to the Makefile of the
program wanting to use them:

SRCS+= getmntopts.c
MOUNT= ${SRCTOP}/sbin/mount
CFLAGS+= -I${MOUNT}
.PATH: ${MOUNT}

Once these changes have been MFC'ed to 13 they may be made into
a library.

Reviewed by: kib, gbe
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D37907


# 243a0eda 21-Oct-2022 Kirk McKusick <mckusick@FreeBSD.org>

Increase the maximum size of the journaled soft-updates journal.

The size of the journaled soft-updates journal should be big enough
to hold two minutes of filesystem metadata-update activity. The
maximum size of the soft updates journal was set in the 1990s. At
the time it was assummed that disk arrays would top out at 16 drives
and disk writes per drive would top out at 500 per second. Today's
I/O subsystems are considerably bigger and faster than those limits.
Thus this delta removes the hard upper limit and lets tunefs(8) and
newfs(8) set the upper bound based on the size of the filesystem and
its cylinder groups.

Sponsored by: The FreeBSD Foundation


# d485c77f 18-Feb-2021 Konstantin Belousov <kib@FreeBSD.org>

Remove #define _KERNEL hacks from libprocstat

Make sys/buf.h, sys/pipe.h, sys/fs/devfs/devfs*.h headers usable in
userspace, assuming that the consumer has an idea what it is for.
Unhide more material from sys/mount.h and sys/ufs/ufs/inode.h,
sys/ufs/ufs/ufsmount.h for consumption of userspace tools, with the
same caveat.

Remove unacceptable hack from usr.sbin/makefs which relied on sys/buf.h
being unusable in userspace, where it override struct buf with its own
definition. Instead, provide struct m_buf and struct m_vnode and adapt
code to use local variants.

Reviewed by: mckusick
Tested by: pho
Sponsored by: The FreeBSD Foundation
Differential revision: https://reviews.freebsd.org/D28679


# 6eb925f8 24-Oct-2020 Kirk McKusick <mckusick@FreeBSD.org>

Filesystem utilities that modify the filesystem (growfs(8), tunefs(8),
and fsirand(8)) should check the filesystem status and require that
fsck(8) be run if it is unclean. This requirement is not imposed on
fsdb(8) or clri(8) since they may be used to clean up a filesystem.

MFC after: 2 weeks
Sponsored by: Netflix


# 886e9f06 02-Mar-2019 Kirk McKusick <mckusick@FreeBSD.org>

The size of the UFS soft-updates journal must be a multiple of the
filesystem block size. When a size is specified with the -S flag
to tunefs(8), round it up to the filesystem block size.

Reported by: Peter Holm
Tested by: Peter Holm
Sponsored by: Netflix


# 1165591e 29-Jan-2019 Dmitry Morozovsky <marck@FreeBSD.org>

Allow dashes as a valid character in UFS labels.

Reviewed by: mckusick, imp, 0mp
MFC after: 2 weeks
Differential Revision: D18991


# cd29c58e 26-Jan-2019 Kirk McKusick <mckusick@FreeBSD.org>

Update tunefs and newfs error messages for the -L (volume label) option
to note that underscores are valid.

PR: 235182
Reported by: Rodney W. Grimes (rgrimes@)
Sponsored by: Netflix


# 0cde0ab2 25-Jan-2019 Kirk McKusick <mckusick@FreeBSD.org>

Allow tunefs to include '_' as a legal character in label names
to make it consistent with newfs. Document the legality of '_'
in label names in both tunefs(8) and newfs(8).

PR: 235182
Submitted by: darius@dons.net.au
Reviewed by: Conrad Meyer
MFC after: 3 days
Sponsored by: Netflix


# 9fc5d538 13-Nov-2018 Kirk McKusick <mckusick@FreeBSD.org>

In preparation for adding inode check-hashes, clean up and
document the libufs interface for fetching and storing inodes.
The undocumented getino / putino interface has been replaced
with a new getinode / putinode interface.

Convert the utilities that had been using the undocumented
interface to use the new documented interface.

No functional change (as for now the libufs library does not
do inode check-hashes).

Reviewed by: kib
Tested by: Peter Holm
Sponsored by: Netflix


# 69b468b9 17-Oct-2018 Bjoern A. Zeeb <bz@FreeBSD.org>

Fix spelling of an error message and add warning to another error
case in tunefs(8).

Reviewed by: imp (2017 version of the same diff)
Approved by: re (gjb)
Differential Revision: https://reviews.freebsd.org/D10046


# d8ba45e2 16-Mar-2018 Ed Maste <emaste@FreeBSD.org>

Revert r313780 (UFS_ prefix)


# 1e2b9afc 16-Mar-2018 Ed Maste <emaste@FreeBSD.org>

Prefix UFS symbols with UFS_ to reduce namespace pollution

Followup to r313780. Also prefix ext2's and nandfs's versions with
EXT2_ and NANDFS_.

Reported by: kib
Reviewed by: kib, mckusick
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D9623


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 1dc349ab 15-Feb-2017 Ed Maste <emaste@FreeBSD.org>

prefix UFS symbols with UFS_ to reduce namespace pollution

Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Also prefix ext2's and nandfs's NDADDR and NIADDR with EXT2_ and NANDFS_

Reviewed by: kib, mckusick
Obtained from: NetBSD
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D9536


# 98acad14 21-Dec-2016 Brooks Davis <brooks@FreeBSD.org>

Convert tunefs use to nmount(2)

Reviewed by: jhb, emaste
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D8822


# f9c82108 07-Mar-2016 Ed Maste <emaste@FreeBSD.org>

tunefs: clear the entire previous label when setting a new one

strlcpy(3) null terminates but does not zero-fill the buffer, so would
leave beind any portion of the previous volume label longer than the
new one.

Note that tunefs only allows -L args up to a length of MAXVOLLEN-1, so
the stored label will be null-terminated (whether or not required by
UFS).

Reviewed by: imp
Sponsored by: The FreeBSD Foundation


# 1b83e8a3 16-May-2013 Xin LI <delphij@FreeBSD.org>

Constify string pointers.

Verified with: sha256(1)
MFC after: 2 weeks


# 244dccb7 23-Apr-2013 Kirk McKusick <mckusick@FreeBSD.org>

Fix error check.

Submitted by: Andrey Chernov (ache@)
MFC after: 3 days


# baa12a84 22-Mar-2013 Kirk McKusick <mckusick@FreeBSD.org>

The purpose of this change to the FFS layout policy is to reduce the
running time for a full fsck. It also reduces the random access time
for large files and speeds the traversal time for directory tree walks.

The key idea is to reserve a small area in each cylinder group
immediately following the inode blocks for the use of metadata,
specifically indirect blocks and directory contents. The new policy
is to preferentially place metadata in the metadata area and
everything else in the blocks that follow the metadata area.

The size of this area can be set when creating a filesystem using
newfs(8) or changed in an existing filesystem using tunefs(8).
Both utilities use the `-k held-for-metadata-blocks' option to
specify the amount of space to be held for metadata blocks in each
cylinder group. By default, newfs(8) sets this area to half of
minfree (typically 4% of the data area).

This work was inspired by a paper presented at Usenix's FAST '13:
www.usenix.org/conference/fast13/ffsck-fast-file-system-checker

Details of this implementation appears in the April 2013 of ;login:
www.usenix.org/publications/login/april-2013-volume-38-number-2.
A copy of the April 2013 ;login: paper can also be downloaded
from: www.mckusick.com/publications/faster_fsck.pdf.

Reviewed by: kib
Tested by: Peter Holm
MFC after: 4 weeks


# 14951d42 27-Feb-2013 Peter Holm <pho@FreeBSD.org>

The .journal file needs to reside on the ROOTINO which must not extend
beyond direct blocks. A typo caused this check to fail.


# 05d43d98 28-Oct-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Declare functions as static and move global variables to the top;
no functional changes.


# e25a029e 27-Sep-2012 Matthew D Fleming <mdf@FreeBSD.org>

Fix sbin/ build with a 64-bit ino_t.

Original code by: Gleb Kurtsou


# 14f6494f 09-Jan-2012 Eitan Adler <eadler@FreeBSD.org>

Fix warning when compiling with gcc46:
error: variable 'Sflag' set but not used

Approved by: dim
MFC after: 3 days


# 1efe3c6b 04-Nov-2011 Ed Schouten <ed@FreeBSD.org>

Add missing static keywords for global variables to tools in sbin/.

These tools declare global variables without using the static keyword,
even though their use is limited to a single C-file, or without placing
an extern declaration of them in the proper header file.


# 8ee53ea3 11-Oct-2011 Kirk McKusick <mckusick@FreeBSD.org>

After creating a filesystem using newfs -j the time stamps are all
zero and thus report as having been made in January 1970. Apart
from looking a bit silly, it also triggers alarms from scripts
that detect weird time stamps. This update sets all 4 (or 3, in
the case of UFS1) time stamps to the current time when enabling
journaling during newfs or later when enabling it with tunefs.

Reported by: Hans Ottevanger <hans@beastielabs.net>
MFC after: 1 week


# e605011a 12-Feb-2011 Konstantin Belousov <kib@FreeBSD.org>

When creating a directory entry for the journal, always read at least
the fragment, and write the full block. Reading less might not work
due to device sector size bigger then size of direntries in the
last directory fragment.

Reported by: bz
In collaboration with: pho
Reviewed by: jeff
Tested by: bz, pho


# a738d4cf 28-Dec-2010 Konstantin Belousov <kib@FreeBSD.org>

Add support for FS_TRIM to user-mode UFS utilities.

Reviewed by: mckusick, pjd, pho
Tested by: pho
MFC after: 1 month


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 53053595 17-May-2010 Jeff Roberson <jeff@FreeBSD.org>

- Round up the journal size to the block size so we don't confuse fsck.

Reported by: Mikolaj Golub <to.my.trociny@gmail.com>

- Only require 256k of blocks per-cg when trying to allocate contiguous
journal blocks. The storage may not actually be contiguous but is at
least within one cg.
- When disabling SUJ leave SU enabled and report this to the user. It
is expected that users will upgrade SU filesystems to SUJ and want
a similar downgrade path.


# 727c1288 01-May-2010 Edwin Groothuis <edwin@FreeBSD.org>

Improve usage of tunefs:

Document -j switch in usage() to reflect recent SUJ work.

Submitted by: Alastair Hogge
MFC after: 1 week


# a6e09ef1 29-Apr-2010 Jeff Roberson <jeff@FreeBSD.org>

- Use the path to the filesystem mountpoint to look up the statfs
structure so that we correctly reload. Note that tunefs doesn't
properly detect the need to reload if the disk device is specified
for a read-only mounted filesystem.
- Lessen the contiguity requirement for the journal so that it is more
likely to succeed.


# 113db2dd 24-Apr-2010 Jeff Roberson <jeff@FreeBSD.org>

- Merge soft-updates journaling from projects/suj/head into head. This
brings in support for an optional intent log which eliminates the need
for background fsck on unclean shutdown.

Sponsored by: iXsystems, Yahoo!, and Juniper.
With help from: McKusick and Peter Holm


# 0718d64d 18-Apr-2010 Edward Tomasz Napierala <trasz@FreeBSD.org>

MFC r200796:

Implement NFSv4 ACL support for UFS.

Reviewed by: rwatson


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 4179ce18 26-Feb-2010 Kirk McKusick <mckusick@FreeBSD.org>

MFC of 203763, 203764, 203768, 203769, 203770, 203782, and 203784.

These fixes correct a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

These fixes also update newfs to ensure that it will never create a
filesystem with more than 2^32 inodes.

They also update libufs, tunefs, and growfs so that they properly
handle inode numbers as unsigned.

Reported by: Scott Burns, John Kilburg, and Bruce Evans
Followup by: Jeff Roberson
PR: 133980


# a6cc0cf6 10-Feb-2010 Kirk McKusick <mckusick@FreeBSD.org>

Quiet spurious warnings.


# 9340fc72 21-Dec-2009 Edward Tomasz Napierala <trasz@FreeBSD.org>

Implement NFSv4 ACL support for UFS.

Reviewed by: rwatson


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 868c68ed 31-Oct-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Add -J flag to both newfs(8) and tunefs(8) which allows to enable gjournal
support.
I left -j flag for UFS journal implementation which we may gain at some
point.

Sponsored by: home.pl


# 4c723140 09-Apr-2004 Mark Murray <markm@FreeBSD.org>

Remove advertising clause from University of California Regent's license,
per letter dated July 22, 1999.

Approved by: core, imp


# 76444424 26-Mar-2004 Bruce Evans <bde@FreeBSD.org>

Fixed some style bugs in the residue of rev.1.14 (mainly initialization in
declarations, uncuddled elses and excessive braces).


# 29f9611d 26-Mar-2004 Bruce Evans <bde@FreeBSD.org>

Fixed some style bugs in or related to rev.1.13 (mainly misindentation of
the getopt() case statement).


# c69284ca 03-May-2003 David E. O'Brien <obrien@FreeBSD.org>

Use __FBSDID() to quiet GCC 3.3 warnings.


# 1f6a4631 22-Feb-2003 Ruslan Ermilov <ru@FreeBSD.org>

Sort options.


# c715b047 31-Jan-2003 Gordon Tetlow <gordon@FreeBSD.org>

Bring in support for volume labels to the filesystem utilities.

Reviewed by: mckusick


# 907db4dd 27-Jan-2003 Juli Mallett <jmallett@FreeBSD.org>

Fix problems with how libufs was used, with regard to mounted/active fs's,
in the new world order of libufs, where we also do statfs, and add a missing
close.


# b1f0fda0 20-Jan-2003 Juli Mallett <jmallett@FreeBSD.org>

Make tunefs use libufs, it seems to do well enough for printing / setting
things.


# e0328ede 17-Jan-2003 Juli Mallett <jmallett@FreeBSD.org>

Consistentify output whitespace.


# ada981b2 26-Nov-2002 Kirk McKusick <mckusick@FreeBSD.org>

Create a new 32-bit fs_flags word in the superblock. Add code to move
the old 8-bit fs_old_flags to the new location the first time that the
filesystem is mounted by a new kernel. One of the unused flags in
fs_old_flags is used to indicate that the flags have been moved.
Leave the fs_old_flags word intact so that it will work properly if
used on an old kernel.

Change the fs_sblockloc superblock location field to be in units
of bytes instead of in units of filesystem fragments. The old units
did not work properly when the fragment size exceeeded the superblock
size (8192). Update old fs_sblockloc values at the same time that
the flags are moved.

Suggested by: BOUWSMA Barry <freebsd-misuser@netscum.dyndns.dk>
Sponsored by: DARPA & NAI Labs.


# 273500c2 15-Oct-2002 Robert Watson <rwatson@FreeBSD.org>

s/clear/cleared/ for consistency (sigh)

Reported by: dd


# c2cd97a3 15-Oct-2002 Robert Watson <rwatson@FreeBSD.org>

Spell 'set' as 'cleared' where appropriate.


# 81dc101c 15-Oct-2002 Robert Watson <rwatson@FreeBSD.org>

Teach tunefs to print the ACL and multilabel flag information when
inspecting a superblock.

Obtained from: TrustedBSD Project
Sponsored by: DARPA, Network Associates Laboratories


# a2325efe 15-Oct-2002 Robert Watson <rwatson@FreeBSD.org>

Correct some of the style problems in this file:

I introduced a style problem when I sorted 'a' before 'A'; our
preferred order sorts 'A' first. Correct.

Use .Cm instead of .Ar.

Submitted by: bde


# 289e09ee 14-Oct-2002 Robert Watson <rwatson@FreeBSD.org>

Introduce -a [enable|disable] and -l [enable|disable] flags to the tunefs
command, permitting it to set FS_ACLS and FS_MULTILABEL administrative
flags on UFS file systems.

Obtained from: TrustedBSD Project
Sponsored by: DARPA, Network Associates Laboratories


# 23d8e031 06-Sep-2002 Bruce Evans <bde@FreeBSD.org>

Removed vestiges of the -a and -d options.

Fixed other bugs in the usage message so that it matches the man page.


# a9098c89 06-Sep-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Remove the -a maxcontig option, the kernel doesn't inspect fs_maxcontig
anymore.

Sponsored by: DARPA & NAI Labs.


# ce66ddb7 21-Aug-2002 Tom Rhodes <trhodes@FreeBSD.org>

s/filesystem/file system/g as discussed on -developers


# 1c85e6a3 21-Jun-2002 Kirk McKusick <mckusick@FreeBSD.org>

This commit adds basic support for the UFS2 filesystem. The UFS2
filesystem expands the inode to 256 bytes to make space for 64-bit
block pointers. It also adds a file-creation time field, an ability
to use jumbo blocks per inode to allow extent like pointer density,
and space for extended attributes (up to twice the filesystem block
size worth of attributes, e.g., on a 16K filesystem, there is space
for 32K of attributes). UFS2 fully supports and runs existing UFS1
filesystems. New filesystems built using newfs can be built in either
UFS1 or UFS2 format using the -O option. In this commit UFS1 is
the default format, so if you want to build UFS2 format filesystems,
you must specify -O 2. This default will be changed to UFS2 when
UFS2 proves itself to be stable. In this commit the boot code for
reading UFS2 filesystems is not compiled (see /sys/boot/common/ufsread.c)
as there is insufficient space in the boot block. Once the size of the
boot block is increased, this code can be defined.

Things to note: the definition of SBSIZE has changed to SBLOCKSIZE.
The header file <ufs/ufs/dinode.h> must be included before
<ufs/ffs/fs.h> so as to get the definitions of ufs2_daddr_t and
ufs_lbn_t.

Still TODO:
Verify that the first level bootstraps work for all the architectures.
Convert the utility ffsinfo to understand UFS2 and test growfs.
Add support for the extended attribute storage. Update soft updates
to ensure integrity of extended attribute storage. Switch the
current extended attribute interfaces to use the extended attribute
storage. Add the extent like functionality (framework is there,
but is currently never used).

Sponsored by: DARPA & NAI Labs.
Reviewed by: Poul-Henning Kamp <phk@freebsd.org>


# 3468b317 15-May-2002 Tom Rhodes <trhodes@FreeBSD.org>

more file system > filesystem


# 75766e17 12-May-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Sigh, more BBSIZE related breakage.

Sponsored by: DARPA & NAI Labs.


# d476a036 21-Mar-2002 Warner Losh <imp@FreeBSD.org>

o remove __P
o remove main prototype


# 47f07d95 30-Sep-2001 Ian Dowse <iedowse@FreeBSD.org>

Don't require that the special/filesystem argument translates into
a block or character device; the rest of tunefs works just fine on
filesystem images in regular files. Instead, if getfsfile() failed
and if the specified filesystem is a directory then print a more
useful "unknown file system" error.

Also, _PATH_DEV already contains a trailing slash, so don't add
another one when constructing a device path, and use errx() instead
of err() in a case where errno is meangingless.


# 55fd28c8 24-Jul-2001 Kris Kennaway <kris@FreeBSD.org>

sprintf -> snprintf

Obtained from: OpenBSD
MFC After: 1 week


# c33fa91f 14-Jul-2001 Dima Dorfman <dd@FreeBSD.org>

Constify, de-register-ify, and set WARNS=2.

Submitted by: Mike Barcroft <mike@q9media.com>


# 1c2665d8 13-Apr-2001 Kirk McKusick <mckusick@FreeBSD.org>

Do not allow the soft updates flag to be set if the filesystem is dirty.
Because the kernel will allow the mounting of unclean filesystems when
the soft updates flag is set, it is important that only soft updates
style inconsistencies (missing blocks and inodes) be present. Otherwise
a panic may ensue. It is also important that the filesystem be in a clean
state when the soft updates flag is set because the background fsck uses
the fact that the flag is set to indicate that it is safe to run. If
background fsck encounters non-soft updates style inconsistencies, it
will exit with unexpected inconsistencies.


# a61ab64a 10-Apr-2001 Kirk McKusick <mckusick@FreeBSD.org>

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>


# e50fa3d2 29-Jan-2001 Ben Smithurst <ben@FreeBSD.org>

Fix 'tunefs -p'

Reviewed by: sheldonh


# 77edab90 10-Dec-2000 Philippe Charnier <charnier@FreeBSD.org>

The tunefs code assumed that the last argument was the device specification.
We need to parse the arguments first, then open the device (if
specified) and then apply the changes. This change will disallow the
(undocumented) use of multiple instances of the same argument on the
same command line for the sack of a better error message.

Other changes are:
1) the softupdates (-n) now issue a warning about remaining unchanged
2) the usage and man page is changed to specify "space | time" instead of
"optimization preference".

PR: bin/23335
Submitted by:Mark Peek <mark@whistle.com>


# 2af14b60 28-Nov-2000 Philippe Charnier <charnier@FreeBSD.org>

Remove .Op when arg is required (special | filesystem). Document that at
least one flag is required and check this in the code. Make use of getopt(3).
Generalyze printing `... remains unchanged ...'.


# 060ac658 14-Mar-2000 Sheldon Hearn <sheldonh@FreeBSD.org>

Open the device read-only initially and re-open read-write if necessary
later. This allows tunefs -p on mounted filesystems.

Side-effects:
Use K&R prototypes.
Use definitions from fcntl.h for the flags argument to open(2).

There are cosmetic differences between this and the submitted patch.

PR: 17143
Reported by: Peter Edwards <peter.edwards@ireland.com>
Submitted by: luoqi


# 51003344 29-Jan-2000 Luoqi Chen <luoqi@FreeBSD.org>

Remove unused #include and prototype declaration.


# b20ae6a0 29-Jan-2000 Luoqi Chen <luoqi@FreeBSD.org>

Typo fix. While I am at it, remove the name translation from block to raw
device, they are equivalent now (or more accurately we no longer have block
devices).

Submitted by: Gregory Sutter <gsutter@pobox.com>


# 7f3dea24 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 9ea6e95e 19-Jul-1999 Luoqi Chen <luoqi@FreeBSD.org>

Check if an fs is mounted before checking if it is mounted read-only.
Pointed out by: Mike Smith <msmith@freebsd.org>


# 7382c45a 19-Jan-1999 Luoqi Chen <luoqi@FreeBSD.org>

Allow tuning of read-only mounted file system.

Reviewed by: Bruce Evans <bde@zeta.org.au>


# 8679b1b4 03-Aug-1998 Philippe Charnier <charnier@FreeBSD.org>

Document -n (soft-update) flag.
Add rcsid, remove unused #includes. Sync usage() and SYNOPSIS.


# b1897c19 08-Mar-1998 Julian Elischer <julian@FreeBSD.org>

Reviewed by: dyson@freebsd.org (john Dyson), dg@root.com (david greenman)
Submitted by: Kirk McKusick (mcKusick@mckusick.com)
Obtained from: WHistle development tree


# 25e43cba 01-Jul-1997 Bruce Evans <bde@FreeBSD.org>

Import Lite2's src/sbin, except for XNSrouted and routed. All relevant
files in src/sbin are off the vendor branch, so this doesn't change the
active versions.


# 49d430cc 19-Jun-1997 Philippe Charnier <charnier@FreeBSD.org>

Cosmetic in usage string.


# 16a7269e 25-Jun-1995 Joerg Wunsch <joerg@FreeBSD.org>

When tuneing filesystems with tunefs, it is not obvious what the current
parameters are. You can use dumpfs, but that's not obvious which settings
are tuneable, and is far from clear to the non-guru (it's like using a
hexdump of a tar archive to get a table-of-contents).

There is also an undocumented option in the man page that can be dangerous.
Suppose your disk driver decides to scramble all writes while you tell
tunefs to update all backup superblocks.

This suggested change adds a '-p' (print) switch to bring it in
line with some SVR4 systems.

(Slightly changed by me, mostly for optics. - joerg)

Submitted by: peter@haywire.dialix.com


# 5ebc7e62 30-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


# 8fae3551 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite sbin Sources

Note: XNSrouted and routed NOT imported here, they shall be imported with
usr.sbin.