Re: [test patch] dirty shared mappings (was Re: ... fragmentation)

Linus Torvalds (torvalds@transmeta.com)
Thu, 8 Jan 1998 08:59:13 -0800 (PST)


On Wed, 7 Jan 1998, Craig Milo Rogers wrote:
>
> I'm afraid that I don't understand the underlying problem,
> though. I was familiar with the swapping and paging meachanisms in
> PDP-10 and PDP-11 operating systems, but haven't studied the Linux
> implementation of these functions.
>
> Why is a private anonymous segment any different from the
> "regular" writable memory space of a user-level process? Both need to
> be written to swap storage. Why should shared anonymous segments be
> any more different from private ones than shared executable code
> segments are from private executable code segments?

A shared anonymous map can be _writable_ - and it's initially zero-filled
only until the first user writes to it. Think of it as "anonymous shared
memory" rather than a normal anonymous page.

Personally I consider the whole concept to be rather distasteful - it's
against all the normal memory management rules and it has no security etc
etc at all. Which is why I'm _not_ willing to support it unless it becomes
so easy to do that I can just add it on as an after-thought and say "well,
here it is, use it if you really have to".

> Why does Alan's suggestion require a separate swap area?
> Couldn't his special device (/dev/anon? anonfs?) simply offer an
> anchoring inode, if one is truly needed, while the private or shared
> pages are swapped in the same manner as the regular writable pages of
> a process? If shared, non-private mapped memory segments are swapped
> to their inode-of-origin instead of to system swap space, couldn't
> /dev/anon cooperate with the regular swap space and redirect I/O
> for shared, anonymous requests to it?

Alan's suggestion doesn't _require_ a separate swap area, but the concept
of a anonymous shared area does require some way of managing the shared
pages.

In a true anonymous private page, all pages are interchangable: they
really _are_ anonymous. The memory management has to remember where it
puts the page when it swaps it out, but that's still purely "local"
information, in that the location is only relevant for the process that
does the swap-out and nobody else. Nobody else can access that page.

In a anonymous shared area this is no longer true. A specific offset into
the shared area is associated with a _specific_ page on the swap device,
and you have to keep track of that association some way. That's ok with a
regular file, because we naturally have to keep track of the offset into
the file anyway, but a swap device doesn't have that 1:1 offset mapping if
the swap device is also shared with the "real" anonymous paging activity.

That's why a separate area would make it so simple: then we could use the
same "offset -> page" 1:1 mapping that we use for regular file backing
store page-out. Having a common area would require some internal mapping
function.

Personally, I think we should just forget about the abomination unless
somebody comes up with something that makes it really simple and doesn't
impact the rest of the memory management code negatively. Almost nobody
really uses shared anonymous mappings - and I think the people who do are
seriously misguided.

Linus