tunefs

Chris Torek chris at mimsy.umd.edu
Mon Sep 3 00:33:18 AEST 1990


In article <25513 at boulder.Colorado.EDU> grunwald at foobar.colorado.edu
(Dirk Grunwald) writes:
>if I'm not going to be adding or deleting files often, does the [tunefs
>-m `minimum free space'] threshold really matter?

Free blocks (or lack thereof) matter only when a file needs a new block
or fragment.  UCB CSRG keep archives of particular releases of systems on
line sometimes; these go in file systems with a reserve of 0%, since they
are never modified after creation.

The code in question is in /sys/ufs/ufs_alloc.c (in recent BSDs).  Ideally
it never even uses the second approach; but in order to allocate the very
last block it will usually need the third.

/*
 * Implement the cylinder overflow algorithm.
 *
 * The policy implemented by this algorithm is:
 *   1) allocate the block in its requested cylinder group.
 *   2) quadradically rehash on the cylinder group number.
 *   3) brute force search for a free block.
 */
u_long
hashalloc(ip, cg, pref, size, allocator)
	struct inode *ip;
	int cg;
	long pref;
	int size;	/* size for data blocks, mode for inodes */
	u_long (*allocator)();
{
	register struct fs *fs;
	long result;
	int i, icg = cg;

	fs = ip->i_fs;
	/*
	 * 1: preferred cylinder group
	 */
	result = (*allocator)(ip, cg, pref, size);
	if (result)
		return (result);
	/*
	 * 2: quadratic rehash
	 */
	for (i = 1; i < fs->fs_ncg; i *= 2) {
		cg += i;
		if (cg >= fs->fs_ncg)
			cg -= fs->fs_ncg;
		result = (*allocator)(ip, cg, 0, size);
		if (result)
			return (result);
	}
	/*
	 * 3: brute force search
	 * Note that we start at i == 2, since 0 was checked initially,
	 * and 1 is always checked in the quadratic rehash.
	 */
	cg = (icg + 2) % fs->fs_ncg;
	for (i = 2; i < fs->fs_ncg; i++) {
		result = (*allocator)(ip, cg, 0, size);
		if (result)
			return (result);
		cg++;
		if (cg == fs->fs_ncg)
			cg = 0;
	}
	return (0);
}
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.admin mailing list