From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds) Subject: Re: Linux swapping Date: 29 May 1992 17:12:14 GMT
In article <235kl7h.james@netcom.com> james@netcom.com (James L. Paul) writes:
>In article <9spkbss6@cck.coventry.ac.uk> csg203@cch.coventry.ac.uk (Bluebeard) writes:
>>
>>I have 2megs of memory and 4megs of swap.
>>
>>Does this give me a total of 6megs or only 4 ?
It gives you 6MB of memory (but remember that 1MB is used by the kernel).
>>A unix expert, told me that the actual memory maps onto the swap, so only the
>>swap space above the system memory is available.
>>Is this true on linux ?
This is true on some unixes (I think SunOS does it that way), but linux
uses swap as /additional/ memory. (well, one page of the swap-space is
used for the good-page bitmap and the swapspace signature).
>>I'm considering upgrading to 4meg of RAM, but as I've only got a 40meg
>>partition, I wasn't intending to increase the swap space.
I'd sertainly suggest upgrading to 4MB ram and 4MB swap: you'll notice
everything is much snappier, especially compiles.
>As another Linux beginner, I'd like to hear the answer to this too.
>My question is, does Linux swap or page? The use of the term swap is
>prevalent in Linux (ie, swap space, swapon) but I also saw descriptions
>of swap space given in pages?
Linux does only paging, no swapping in the meaning "write out one whole
process to disk".
The reason I have called it swapping is that linux used paging for
memory management on a low level from the first version (0.01), but
didn't page to disk at all until version 0.12 (well, there was a
testversion out for 0.11, but 0.12 was the first version that did it
"officially"). So when paging to disk came along, I called it swapping
to distinguish it from the memory management paging linux has done all
along.
> And is demand paging different from paging? How?
Demand-paging is really "demand-loading of executables" and is totally
independent of the page-swapping algorithms, although they obviously
have similarities. When linux starts up a process, no actual code space
is loaded: I let the page exceptions load in the executable as needed.
Thus linux demand-loads the code and initialized data it needs.
Demand-loading has a couple of very good points: (1) it simplifies the
exec system call, (2) it means page-sharing between processes that have
executed the same file is easy to implement, and (3) it cuts down on the
amount of memory required. When linux runs out of real memory, it
starts to look for pages it can swap out: but if it notices that the
page is clean, it just forgets about it, and demand-loads it when it's
needed again. That means the swap-file isn't needed as much, especially
when running big binaries like gcc, where the code-pages can be
demand-loaded as you wish.
Point (3) means that even without any swapspace, you can usually run
slightly larger programs than your memory setup would actually permit.
I've noticed this while running X and doing a kernel compile + something
else when I've forgotten to turn on swapping: free reports 0 pages
available, but things still work, although performance is of course
slightly down..
Linus