Subject: Re: ABOUT - fork: Cannot allocate memory
To: Aaron Mildenstein <buh@mildenstein.net>
From: Bill Studenmund <wrstuden@netbsd.org>
List: port-macppc
Date: 04/11/2002 09:54:04
On Thu, 11 Apr 2002, Aaron Mildenstein wrote:

> I'm CC-ing this to port-macppc@netbsd.org to get any corrections or
> suggestions.  I try to disclaim what I know I do not know.  I do know what
> worked for me, and I'm pointing it out.
>
> I did find out something, which is more of a work-around than a fix.
> Before I explain what happened, catalog how much RAM and SWAP you have.  I
> have 512M of RAM, and a logical conclusion of 2x the RAM for SWAP, or 1G.

You don't need to stick with the swap == 2x RAM rule anymore. NetBSD's VM
system hasn't needed that since Mach VM went in (which was before NetBSD
0.9). You may want it, but you don't need it.

I usually go with swap == a few hunderd megs, or maybe 1x RAM. For
single-person work, that seems to do well. You only need lots of swap if
you're doing lots of jobs that will be running at once but mostly sleeping
(multiuser) or you want crash dumps (when you need swap >= RAM).

> I read of another problem, which I had, where in older G3 type machines,
> on first boot the machine would panic when it tried to turn on the swap,
> or it would hang or something.  I cheated, and manually added the swap
> before that part of the script (this was my second attempt at installing
> NetBSD), and the SWAP seemed to allocate ok.  After this, however, I got
> those annoying "fork: Cannot allocate memory" messages, in spite of the

You still ran into the same problem, just a little latter.

> fact that I had 439M of free memory.  What I found is that the kernel is
> trying to allocate SWAP, and because of some limitation somewhere (and its
> this part of the question I can't answer: Why the limit, and how much?) it

The problem is that the kernel can only have so much space allocated for
its own use at once, and you filled that up with swap mappings. The limit
is I believe 256 MB (one powerpc segment).

> was unable to allocate memory.  NetBSD has switched, or so I read, to a
> unified memory architecture, where it is no longer necessary to make
> monstrous amounts of swap space.  I don't pretend to fully understand it,

That's not quite it. There are two relevant changes: NetBSD current has
switched to UBC (Unified Buffer Cache), and the powerpc ports now are
using a new pmap implementation. This code is the part of the kernel that
understands and controlls the powerpc MMU. The new pmap code deals with
large memory systems much better. UBC keeps the data cache (of files on
disk) in unmanaged memory. That means that all of the cached data pages
are not in the kernel's limited KVA space.

> but perhaps the kernel understands the limits of the motherboard.  My

The mother board's limits don't apply to this.

> motherboard should be able to use 768M of RAM.  I have 512, but when you
> add 1G of swap, the total becomes 1.5G.  If the kernel can't handle more

Memory from swap != RAM. The motherboard only limits how much DRAM you can
add.

> than the motherboard's physical limits (I could be way wrong on this,
> haven't had a chance to test my theory), then that would explain a lot.
> Under this assumption, I could have a swap of 256M, bringing my memory
> total to the ceiling of 768M.

I'd susggest less swap. While I came at the numbers differently, 256 MB
would be fine. 512 MB might be fine too. My system has 416 MB ram and 200
MB swap.

> My workaround?  I just disabled swap in /etc/fstab and restarted the box.
> I still have over 400MB of free RAM when I run top, but I no longer have
> "fork: Cannot allocate memory" messages.  Hope that helps you out!

Take care,

Bill