*BSD News Article 18496


Return to BSD News archive

Xref: sserve comp.os.linux:48244 comp.os.386bsd.questions:3858
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!elroy.jpl.nasa.gov!swrinde!cs.utexas.edu!uunet!mcsun!uknet!yorkohm!minster!forsyth
From: forsyth@minster.york.ac.uk
Newsgroups: comp.os.linux,comp.os.386bsd.questions
Subject: paging & swapping  (Was: SUMMARY 486DX2/66 ...)
Message-ID: <742760988.24491@minster.york.ac.uk>
Date: 15 Jul 1993 18:29:48 GMT
References: <21k903$3q4@GRAPEVINE.LCS.MIT.EDU> <PCG.93Jul12003233@decb.aber.ac.uk> <CA0zHp.CqK@unixhub.SLAC.Stanford.EDU> <21ra0tINNgeg@serv-200.dfki.uni-kl.de> <MUTS.93Jul13204727@muts.hacktic.nl>
Distribution: world
Organization: Department of Computer Science, University of York, England
Lines: 55

>>On 12 Jul 1993 09:14:05 GMT, malik@alvserv-2.dfki.uni-kl.de (Thomas Malik) said:
>>
>>  TM> Bullshit. Obviously, you don't know the difference between terms
>>  TM> 'swapping' and 'paging'. Swapping means swapping complete
>>  TM> process spaces to disk (what bsd does) , whereas paging means
>>  TM> putting some fixed size pieces of memory to disk (what linux
>>  TM> does). Obviously, the former is slower than the latter.

not necessarily.  it's important to distinguish several things:
	1. the page selection policy
	2. the method used to write dirty pages to disc
	3. global scheduling policy

page selection policy can be local or global: a process can decide
to page out some of its own pages to page some more in (a good approach
which makes it much easier to avoid thrashing);  alternatively, in
many systems a global process makes it its business to wander through
the memory page pool as a whole, discarding (say) pages that haven't
recently been accessed by any process in the system.

in either case, the page selector needn't immediately write the selected pages one at a time
to disc.  it can instead queue them for another process to clean.  (perhaps itself, after a scan.)
that process (or processes) can easily combine writes to adjacent
sectors.  there are different ways to do that depending on whether the
swap/paging files are shared or per-process.   some systems, for instance,
will simply write to a contiguous area on disc a suitable number from
the front of the list, regardless of whether or not they belong to the
same process.  others might only combine
write requests for pages from the same process (if the swap space allocated to them
was adjacent).  more elaborate versions will sort the list.

the page cleaning process might also only run only so often, or when when the queue builds up
to a certain level, allowing pages to be reclaimed from the list meanwhile.

global scheduling policy is slightly different.  it is indeed the function
performed by the old unix and bsd swappers, but it needn't actually write
anything to disc.  all the scheduler is trying to do is decide (when memory is very low)
which process or processes should make way for another.  having decided,
all it need to is either to page the process out, or (in message passing systems)
tell the process to page itself out.  `paging out' of a complete process
simply releases all its pages into either the clean or dirty page queues.
in the latter case, dirty pages that were adjacent in VM that are also
adjacent in swap space will also be adjacent in the pageout queue.
the page cleaning process can trivially combine those into big contiguous
writes to disc, if that's what you want.  the big advantage is that
the page cleaning process can write only as much of the process to disc
as is required to satisfy the current memory shortfall.  full image swapping
(as BSD vmunix used to do) takes ages on big processes, since even at 2Mb/sec
a 10 Mb process takes a while to swap.  furthermore, you probably only needed
space to run `ps' (to see why things were so slow).

by carefully separating the components of the system, you can produce
a paging system in which you can tune the local, global, and page cleaning
policies more easily.  (it's also MUCH easier to implement.)
it's also one of the keys to avoiding thrashing.