From: csg203@cch.coventry.ac.uk (Bluebeard)
Newsgroups: comp.os.linux
Subject: Linux swapping
Date: 28 May 92 20:11:20 GMT
Organization: Elf Bashers Anonymous
Nntp-Posting-Host: cc_sysh


I have 2megs of memory and 4megs of swap.

Does this give me a total of 6megs or only 4 ?

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 ?

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.


Thanks for any info on the above.


-- 
***********************************************************************
* FLESH: Charlie Freckleton * JANET: csg203@uk.ac.cov.cck             * 
* ALIAS: Bluebeard          * or   : stliaise@uk.ac.cov.cck           * 
***********************************************************************

Newsgroups: comp.os.linux
From: james@netcom.com (James L. Paul)
Subject: Re: Linux swapping
Date: Fri, 29 May 92 15:05:25 GMT
Organization: Netcom 

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 ?
>
>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 ?
>
>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.
>
>
>Thanks for any info on the above.
>

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?

Most modern unixes page, not swap. Is linux among them?

BTW, My understanding is this: Swapping involves management at the
process level, and each active process must be fully in physical ram.
This limits efficiency, since memory available to be swapped out is
limited to that of inactive processes. Paging happens at a lower
level, and makes it possible (although slower) to keep only part of
an active process in physical ram. Since paging requires memory
management hardware to be effective, and Linux needs the 386 for
this, I'm guessing that Linux uses paging, not swapping. Do I have
this right? (And is demand paging different from paging? How?)


-- 
James L. Paul

Internet:    netcom!james@apple.com | AppleLink: D1231 | CompuServe: 72767,3436
UUCP:   {apple,amdahl}!netcom!james | GEnie:    J.PAUL | Voice:    607 776-3070
Packet: N6SIW@WB2PSI.#WNY.NY.USA.NA | Delphi:   JLPaul | Home Fax: 607 776-3070
America Online:   JLPaul or Memorex | BIX:      JLPaul | Prodigy:       PWTB41A

From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: comp.os.linux
Subject: Re: Linux swapping
Date: 29 May 92 17:12:14 GMT
Organization: University of Helsinki

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

Newsgroups: comp.os.linux
From: mleech@bnr.ca (Marcus Leech)
Subject: Re: Linux swapping
Nntp-Posting-Host: bwdlh529
Organization: Bell-Northern Research, Woodline Center
Date: Mon, 1 Jun 1992 13:45:01 GMT

In article <1992May29.171214.8939@klaava.Helsinki.FI>, torvalds@klaava.Helsinki.FI 
(Linus Benedict Torvalds) writes:
|> 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. 
A problem with this scheme is that your page-fault latency is limited by the
  efficiency of the filesystem.  Other OS/UNIX implementations that support
  "demand load" executables copy demand-loaded pages into the paging
  area after they've been faulted in. Once that's happened, subsequent
  faults for the same page come out of the paging area.  Paging-area 
  I/O is typically faster than filesystem I/O by quite a bit, which is 
  why it's done this way.

-- 
Marcus Leech, 4Y11             Bell-Northern Research  |opinions expressed
mleech@bnr.ca                  P.O. Box 3511, Stn. C   |are my own, and not
ml@ve3mdl.ampr.org             Ottawa, ON, CAN K1Y 4H7 |necessarily BNRs

From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: comp.os.linux
Subject: Re: Linux swapping
Date: 1 Jun 92 18:17:45 GMT
Organization: University of Helsinki

In article <1992Jun1.134501.3210@bwdls61.bnr.ca> mleech@bnr.ca (Marcus Leech) 
writes:
>In article <1992May29.171214.8939@klaava.Helsinki.FI>, torvalds@klaava.Helsinki.FI 
(Linus Benedict Torvalds) writes:
>|>			  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. 
>
>A problem with this scheme is that your page-fault latency is limited by the
>  efficiency of the filesystem.  Other OS/UNIX implementations that support
>  "demand load" executables copy demand-loaded pages into the paging
>  area after they've been faulted in. Once that's happened, subsequent
>  faults for the same page come out of the paging area.  Paging-area 
>  I/O is typically faster than filesystem I/O by quite a bit, which is 
>  why it's done this way.

Yes, paging from a dedicated page-partition is faster than reading in
the file from the filesystem, but there were a couple of compelling
reasons to do it the linux way. 

- less wasted resources: why write out the page to a swap-partition when
  we know it can be found on the filesystem anyway? With gcc and similar
  big programs, swap-space need is probably reduced a lot by not using
  swapping for clean pages. 

- Ease of programming: the linux mm is very simple (1300 lines of C),
  and I took shortcuts like not keeping track of old pages to get it
  that way.

- If the swapspace is a file, not a partition (which seems pretty usual:
  I have it set up that way myself), demand-loading is faster: no need
  to write out the pages, and loading is quite as fast/slow.

That said, the current memory manager might have other problems which
makes it non-optimal as well: not keeping track of pages very much also
means the page-replacement algorithm is somewhat limited (understatement
of the year).  I felt the simplicity made it worth it.

		Linus

Newsgroups: comp.os.linux
From: obz@sisd.kodak.com (Orest Zborowski COMP)
Subject: Re: Linux swapping
Organization: Printer Products Eastman Kodak
X-Newsreader: Tin 1.1 PL3
Date: Fri, 29 May 92 11:19:35 GMT

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 ?
>
>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 ?
>
>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.
>
>
>Thanks for any info on the above.
>
>
>-- 
>***********************************************************************
>* FLESH: Charlie Freckleton * JANET: csg203@uk.ac.cov.cck             * 
>* ALIAS: Bluebeard          * or   : stliaise@uk.ac.cov.cck           * 
>***********************************************************************

this is not true under linux. under bsd systems there are two memory
management schemes used which use the disk: swapping and paging. paging
is what linux uses: when there is no physical memory for a page, one
is evicted to the disk (our swap space) to make room. swapping is the
wholesale motion of a process to disk, and is done by the swapper process.
if your process doesn't do anything for a while the system decides its
better to hedge it bets and evict the whole thing to disk, betting on
locality of reference on a process granularity, i guess.

linux simply does paging, using as much swap as is available. if there
isn't any available, the program waits. linus, correct me if i'm wrong,
but this is what i remember when i hacked with it.

zorst
[obz@raster.kodak.com]
-- 
zorst (orest zborowski)
[obz@raster.Kodak.COM]