Re: swap cache

Stephen C. Tweedie (sct@redhat.com)
Thu, 17 Dec 1998 13:06:21 GMT


Hi,

On 17 Dec 98 11:25:13 +0530, "Muthu"
<MOLAGAPP.IN.ORACLE.COM.ofcmail@in.oracle.com> said:

> Yes, it's right. If fork() takes care of COW, then why swap-cache
> should be used?.

Fork obviously does _not_ take care of COW. Fork just creates a COW
sharing in the first place. The actual "taking care of" such COW pages
comes later, when processes start to take page faults on them or try to
swap them out. That's why we have the swap cache. It lets us treat
these COW anonymous pages as in-memory copies of the swap-entry on disk,
so that the separate processes paging that data can do so independently.

The real benefit of the swap cache is this: say we have a shared COW
page on swap, and one process reads in that page. All other processes
sharing that page still have references to the original entry on disk in
their page tables. However, the swap cache lets us record the fact that
the on-disk entry is now located in physical memory. As long as it
remains in core, any other process accessing that same page will take a
soft page fault and will find the existing page in memory rather than
trying to read the page in from disk again. In other words, the two
processes which originally shared the swap page on disk now share the
swap cache page in memory.

The swap cache is therefore *critical* to the maintainance of the COW
pages created by fork.

--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/