[lkml]   [1998]   [Dec]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: swap cache

>> To my knowledge, this can be implemented in page-table entry.
>> page-table entry contains a "dirty" bit which specifies if the page
>> is modified or not.
>> Hence, load the page from swap file in read & write mode. If the
>> page is modified, then "dirty" bit is set. This means, the page has
>> to be written to swap file else it is present in swap file already.

>No, we can't do that. The swap cache allows us to have multiple
>processes sharing the same page of swap (think of a process which gets
>partially swapped out and which then forks). The whole point of loading
>the pages read-only in the first instance is so that if we do have such
>sharing of the page, any attempt by one process to write to the page
>causes a page fault and gives that process a new, private copy of the

What I am saying is based on the SVR4 unix implementation and not linux in
particular. I have the following comments:

The pages that go to the swap are anonymous pages (stack, heap, data et
al) and the way two procceses share these pages is when they
are a parent-child pair. Based on how traditional fork() works,
all such anonymous pages are shared by the parent and child on COW
basis. That is, during fork() all anonymous pages are made
Read-Only ( on the page tables of parent and child, irrespective of
whether the page is in memory or not) for both parent and child and
hence they share the same swap till one of them writes to it. When one
of them writes to it a new page is allocated and new swap is also
allocated for it. A read access may or may not generate a fault and is

This to me looks like a cleaner implemetation, where fork takes care of
COW functionality and hence sharing of clean swap pages.


On Mon, Dec 14, 1998 at 05:48:42PM +0330, Muthu wrote:
> It mentions that swap cache usage it to avoid one more writing if it
> is already present in swap file. Can't this information derived from
> "dirty" bit of PTE (page table entires)?

>Stephen Tweedie and all the others will explain better than I will, but
>anyway: the swap cache allows *clean* pages to be in swap and memory at
>the same time.

I think all swap pages start off as dirty. eg first time one writes to
malloc()ed memory, a physical page is allocated along with its backing
swap. So once this dirty page is written to the swap, it becomes
clean. Further writes make it dirty again. The point is the dirty bit is
always sufficient to figure out whether the page needs to go to disk or

As far as sharing of clean swap pages goes, fork takes care of it.

>Without the swap cache, when we wanted to evict a *clean* page, we'd
>have to write it to the swap file. With the cache, it may be present in
>the swap file already and we just discard it from memory.

I think Muthu's basic doubt of not using the dirty bit to decide on
evicting a page remains.

Solaris has a new way of dealing with swap, where there is no one-to-one
correspondence between an anonymous page and its backing store on disk.
Also a part of RAM is used as swap file. I am not sure if linux also
supports such implementation.

"If seven maids with seven mops, Swept it for half a
Prasun Kapoor year, do you suppose" the Walrus said, "That they
Wipro Infotech Ltd. could get it clear"."I doubt it" said the Carpenter,
Ph. 2241730 Extn. 3312 and shed a bitter tear

"Through the looking glass and what alice found
there" - Alice in Wonderland -

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:46    [W:0.608 / U:3.712 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site