Re: Swap cache

Stephen C. Tweedie (sct@redhat.com)
Mon, 14 Dec 1998 20:56:46 GMT


Hi,

On 14 Dec 98 16:49:08 +0530, "Muthu"
<MOLAGAPP.IN.ORACLE.COM.ofcmail@in.oracle.com> said:

> I took a look at "kernel hackers guide". I have a basic doubt
> about "swap cache".

> In "kernel hackers guide" it is specified that use of swap cache
> is to "know if a page is already present in swap file or not". It also
> specfies that if a page is accessed for read and then write ,"two page
> faults will happen - one for loading the page in read-mode and another
> to invalidate 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
page.

Secondly, we need to take a page fault when the page is modified so that
we can deallocate the swap entry when that happens.

--Stephen

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/