Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Aug 1996 09:53:11 -0500 (EST)
From:      "John S. Dyson" <toor@dyson.iquest.net>
To:        nadav@barcode.co.il (Nadav Eiron)
Cc:        dwhite@resnet.uoregon.edu, scott@statsci.com, Eric.Berenguier@sycomore.fr, questions@FreeBSD.org
Subject:   Re: FreeBSD 2.1.0 CRASH!
Message-ID:  <199608311453.JAA00482@dyson.iquest.net>
In-Reply-To: <Pine.BSF.3.91.960831111413.10783B-100000@gatekeeper.barcode.co.il> from "Nadav Eiron" at Aug 31, 96 11:31:44 am

next in thread | previous in thread | raw e-mail | index | archive | help
> > 
> > > The size of the recommendation should change depending on whether or not
> > > the swap area is the total virtual address space or just an extension of
> > > the RAM (i.e.
> > > 
> > >   sizeof(virtual addr space) == sizeof(RAM)+ sizeof(swap)
> > > 
> > > instead of just
> > > 
> > >   sizeof(virtual addr space) == sizeof(swap)
> > 
> > FreeBSD uses method #1.  It's all the same to the VM system.
> > 
> 
> If we're bringing other OS's into the picture... (no flames please :-)). 
> All OS's I know of use method 1 (don't see a reason not to). The two 
> schools of swap space allocation differ in another point: global 
> replacement algorithms vs. local replacement algorithms. Global 
> replacement means that when deciding on a page to swap out, the OS 
> doesn't care about what process owns the page, and only looks at when it 
> is used.
>
That issue is somewhat orthogonal to the issue of how much virtual space
you have.  Once you have allocated space to a page on the swap space
in FreeBSD (and the other *BSD's AFAIK), that space is not generally
freed (there is some code in FreeBSD to mitigate that a little bit),
until the page is logically freed.

Both of the above are technically wrong, but to be conservative in the
worst case, #2 above is the most correct if you want to make sure that
the system never kills any processes or ever hangs.  This is of course,
assuming that no processes ever share memory.  But, #1 above is
definitely wrong and will not guarantee that the system will not hang
due to out of VM conditions!!!

On FreeBSD, if you need to trust the system, you MUST have enough swap
space for every non-text backed page.  That includes .bss, malloced
space and modified .data.  A more accurate (but perhaps not complete
formula follows):

	Sum of the following PEAK values (rounded up due to allocation
	issues):
		# of modified .data pages in the system +
		# of .bss pages in the system +
		# of malloced pages in the system +
		# of anonymous mmaped pages in the system +
		# of pageable pages allocated by the kernel +
		(maybe a few more magic pages)

	Of course the above is hard to calculate :-).
		
	Each of the pages above may be shared by processes
	either by virtue of fork() (in the case of .bss or malloced unmodified
	after the fork()) or exec() (in the case of .data unmodifed.)  .text
	does not normally need to be backed by swap (except in the case of
	debugged or gzipped binaries -- also other semi-bogus binary formats
	need some of the .text backed by swap.)  Ignoring special
	cases, .text and unmodified .data pages never need to be backed
	by swap space (they are already backed by a file.)

	Older 4.4BSD kernels had something known as the collapse
	problem.  This greatly increased the amount of required
	swap space.

	The rule of thumb that swap space should be 2X memory is
	usually ok, but simply a rule of thumb.  It is most accurate
	to say that the minimum amount of swap space, if you are going
	to swap at all, and you generally have enough memory to run
	your processes memory resident (but page once in a while)
	is swap > 1X memory + some small amount.  Swap == 2X memory is a
	heuristic that many people see that works well.  I have seen SVR4
	systems that require swap == 8-10X memory!!!  The same goes for
	FreeBSD.  The formula that I give above is closer to reality.  Note
	that the size of memory on the system does not come into play (except
	you must have swap > 1X memory, if you page much at all.)  The
	(non-.text backed) virtual address space and the amount of swap
	space needed are roughly the same.
	

John




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199608311453.JAA00482>