Subject: Re: unable to boot with 256MB of RAM
To: Wenchi Liao <wliao@midway.uchicago.edu>
From: Curt Sampson <cjs@cynic.net>
List: port-sparc
Date: 11/19/1999 11:59:13
On Fri, 19 Nov 1999, Wenchi Liao wrote:

> >options         MAXBSIZE=32768
> >options         NBUF=5120
> >options         BUFPAGES=14000
> 
> NBUF I can guess at: the number of buffers. MAXBSIZE would be
> size of a buffer (in bytes?). So what is a bufpage?

This is how I understand it; corrections are welcome.

MAXBSIZE is the size of a buffer, in bytes. This is how much address
space in the kernel is allocated for every buffer. When a buffer
is actually used, only as much of the address space as is really
needed is filled with physical RAM. So if you have a disk with 8K
blocks, and you need to buffer one of those blocks, 8K of physical
memory will be allocated to back the first 8K of address space in
a 32K buffer, and be filled with the data, leaving 24K of address
space unused.

NBUF is the number of logical buffers you my have. So with
MAXBSIZE=32768 and NBUF=5120, I am allocating 32K * 5120 = 160 MB
of address space in the kernel to the buffer cache.

BUFPAGES determines how many pages of physical memory are available
to back your buffers. In this case I have 14000 pages, which are
4K each on an SS20, so I have 56000K of physical memory dedicated
to disk buffering.

Now here's the interesting bit. Since all of my filesystems have
8K blocks, I know that most buffers, even though they have 32K of
address space (meaning that the can be up to, but not more than,
32K in size), won't be backed with more than 8K of memory. 14000
pages is 7000 8K chunks, which easily covers my 5120 buffers with
plenty to spare should I mount a disk with 16K blocks.  (I never
do, so really, I'm just wasting 1880 pages (470K) of memory.)

It's possible to have too little memory backing your buffers, too,
of course. For example, if all my filesystems had 32K blocks,
despite having 5120 buffers I'd only be able to use 1750 of them,
because after 1750 32K buffers backed with 32K of physical RAM, I
have no more BUFPAGES to back the rest of the buffers.

Really, for maximum efficient use of of my system, I should use

options 	MAXBSIZE=8192		# 32768 / 4
options		NBUF=20480		# 5120 * 4
options 	BUFPAGES=40960		# 20480 * (MAXBSIZE / PAGESIZE)

This would give me 160 MB dedicated to buffering, which would be
fully utilised unless I mounted a filesystem with 4K blocks.

As another note, someone suggested that we make a smaller MAXBSIZE
a default option on the Sparc. I'm not sure that this is a good
idea, but it might be ok. We couldn't do this on the 386 because
MAXBSIZE also determines the maximum block size of any filesystem
you mount, and some MS-DOS disks (which i386 users often want to
mount) have a blocksize of 64K.

My solution, which wasn't totally optimal but would make all machines
boot, is to check at boot time the amount of VM allocated to buffers
(MAXBSIZE * NBUF) and, if it's too large for the machine, reduce
NBUF until MAXBSIZE * NBUF is not too large.

cjs
--
Curt Sampson  <cjs@cynic.net>   917 532 4208   De gustibus, aut bene aut nihil.
The most widely ported operating system in the world: http://www.netbsd.org