From: turner@capitol.com (Simmy Turner)
Newsgroups: alt.os.linux
Subject: linux/mm/memory.c
Date: 24 Jan 92 06:33:44 GMT
Organization: Capitol Disc Interactive


While trying to add swapping to files, I ran into the following problem that
I don't understand.  In the function copy_page_tables(), there is a call to
read_swap_page().  What is that called needed for?

Here is an excerpt from the code.

memory.c: line 149

		if (!(1 & this_page)) {
			if (!(new_page = get_free_page()))
				return -1;
>>>			read_swap_page(this_page>>1, (char *) new_page);
			*to_page_table = this_page;
			*from_page_table = new_page | (PAGE_DIRTY | 7);
			continue;
		}

From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: alt.os.linux
Subject: Re: linux/mm/memory.c
Date: 24 Jan 92 17:15:31 GMT
Organization: University of Helsinki

In article <1992Jan24.063344.726@capitol.com> turner@capitol.com (Simmy Turner) 
writes:
>
>While trying to add swapping to files, I ran into the following problem that
>I don't understand.  In the function copy_page_tables(), there is a call to
>read_swap_page().  What is that called needed for?

Right.  The natural thing to do would be just to copy the pointer to the
swapped out block, right? Wrong.  Now we have two pointers pointing to a
swapped out block, and when one of the processes causes a swap-in, the
bitmap entry for that swap-page gets set (indicating it's free), even
though another task is still using the page.  There are 2 solutions:

1 - have a swap-page counter: something like what is done for shared
pages that are in memory. 

2 - swap in the parent block with read_swap_page(), and put the
swap-page pointer only in the child.  Now we have just one pointer, and
the bitmap operations work fine again.  You can of course swap in the
page to the child memory, but usually the child does an exec right after
the fork, so the page would be of no use.

Linux uses (2) - sharing of swapped out dirty pages is highly unusual,
and happens /only/ after a fork, so the bitmap is the best bet 99% of
the time. Also, the current method allows us to use the "valid swap
blocks" bitmap found at the start of a swap-device (and created by
mkswap) to be used directly as a swap-page-bitmap.

		Linus

From: tytso@athena.mit.edu (Theodore Y. Ts'o)
Newsgroups: alt.os.linux
Subject: Re: linux/mm/memory.c
Date: 25 Jan 92 05:26:46 GMT
Organization: Massachusetts Institute of Technology
In-Reply-To: torvalds@klaava.Helsinki.FI's message of 24 Jan 92 17: 15:31 GMT
Nntp-Posting-Host: sos.mit.edu

In article <1992Jan24.171531.25053@klaava.Helsinki.FI> torvalds@klaava.Helsinki.FI 
(Linus Benedict Torvalds) writes:

>2 - swap in the parent block with read_swap_page(), and put the
>swap-page pointer only in the child.  Now we have just one pointer, and
>the bitmap operations work fine again.  You can of course swap in the
>page to the child memory, but usually the child does an exec right after
>the fork, so the page would be of no use.

Am I correct is suppose that a consequence of this is that every single
dirty page of the parent has to be swapped in during a fork()?  If so, I
wonder what sort of hit you will take when something like GNU emacs
fork()'s.  (My GNU emacs on my Vax 3100 workstation is currently
weighing in at 5.4 meg.)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Theodore Ts'o				bloom-beacon!mit-athena!tytso
308 High St., Medford, MA 02155		tytso@athena.mit.edu
   Everybody's playing the game, but nobody's rules are the same!

From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: alt.os.linux
Subject: Re: linux/mm/memory.c
Date: 25 Jan 92 10:54:53 GMT
Organization: University of Helsinki

In article <TYTSO.92Jan25002639@SOS.mit.edu> tytso@athena.mit.edu 
(Theodore Y. Ts'o) writes:
>
>Am I correct is suppose that a consequence of this is that every single
>dirty page of the parent has to be swapped in during a fork()?  If so, I
>wonder what sort of hit you will take when something like GNU emacs
>fork()'s.  (My GNU emacs on my Vax 3100 workstation is currently
>weighing in at 5.4 meg.)

Yes.  This is bad, but not /that/ bad: linux only swaps /dirty/ pages: I
doubt the GNU emacs eceutable pages get dirtied, and are thus just
reloaded by the demand-loading mechanism (and nothing happens at the
fork()).  But yes, when editing big files (where there are a lot of
dirty pages) will force a swap-in. 

Swapping was added as a quick hack: it wasn't really meant to extend
virtual memory to really big values - more just to get gcc working on a
2M machine, and have that small extra memory when your executables don't
quite fit. More like a temporary "panic-memory": it linux swaps on a
more regular basis the algorithms should be changed to something better
as well, they are rudimentary right now..

		Linus