*BSD News Article 4214


Return to BSD News archive

Newsgroups: comp.unix.bsd
Path: sserve!manuel!munnari.oz.au!mips!mips!darwin.sura.net!haven.umd.edu!uunet!mcsun!sunic!aun.uninett.no!barsoom!barsoom!tih
From: tih@barsoom.nhh.no (Tom Ivar Helbekkmo)
Subject: 386BSD: buffer space allocation -- a small bugfix.
Message-ID: <tih.714982908@barsoom>
Sender: news@barsoom.nhh.no (USENET News System)
Organization: Norwegian School of Economics
Date: Fri, 28 Aug 1992 06:21:48 GMT
Lines: 63

Well, I guess it's my turn!  :-)  I'm now seeing the "kmem_map too
small" panic here, when I try to copy a large file (a 1.44Mb floppy
image) from an NFS-mounted device to a local hard disk.  I've tried
making the changes that have been suggested, but that didn't help.
(Sanity check in machdep.c, 500 to 1000 increase in vm_map.h.)

However, while looking at /sys/i386/i386/machdep.c, I discovered a
little bug in it.  (Fixing it hasn't solved my problem, either, but
at least it's a bug!)  Here's what I was looking at:

    /*
     * Determine how many buffers to allocate.
     * Use 10% of memory for the first 2 Meg, 5% of the remaining
     * memory. Insure a minimum of 16 buffers.
     * We allocate 1/2 as many swap buffer headers as file i/o buffers.
     */
    if (bufpages == 0)
            if (physmem < (2 * 1024 * 1024))
                    bufpages = physmem / 10 / CLSIZE;
            else
                    bufpages = ((2 * 1024 * 1024 + physmem) / 20) / CLSIZE;
    if (nbuf == 0) {
            nbuf = bufpages / 2;
            if (nbuf < 16)
                    nbuf = 16;
    }
    freebufspace = bufpages * NBPG;
    if (nswbuf == 0) {
            nswbuf = (nbuf / 2) &~ 1;       /* force even */
            if (nswbuf > 256)
                    nswbuf = 256;           /* sanity */
    }
    valloc(swbuf, struct buf, nswbuf);
    valloc(buf, struct buf, nbuf);

Bill Jolitz suggests a sanity check on the calculation of bufpages,
keeping it at a max of NKMEMCLUSTERS/2.  In my case, that's not the
problem, since the calculation doesn't come out higher than that.
(I only have 8Mb of RAM.)

However:  The comment in the above code says to allocate 10% of the
first 2 Meg, then 5% of whatever remains.  This is *not* what the
code itself does.  Since physmem et al do not count bytes, we're
sort of mixing apples and oranges here, and end up with 10% of the
entire physical memory, no matter what.  The following calculation,
however, does do what the comment says:

    if (bufpages == 0) {
            bufpages = min(physmem, btoc(2*1024*1024)) / 10 / CLSIZE;
            if (physmem > btoc(2*1024*1024))
                    bufpages += (physmem - btoc(2*1024*1024)) / 20 / CLSIZE;
    }

(Actually, I'm not too sure about the "/ CLSIZE", but since CLSIZE is
equal to 1, at least on my machine, it doesn't really matter...  :-))

I still can't copy large files from NFS to UFS disks -- but what the
heck, I'm sure that will come in due time!  :-)

-tih
--
Tom Ivar Helbekkmo, NHH, Bergen, Norway.  Telephone: +47-5-959205
Postmaster for domain nhh.no.   Internet mail: tih@barsoom.nhh.no