Re: 'disposable' dirty pages [was: Out Of Memory in v. 2.1]

Jamie Lokier (lkd@tantalophile.demon.co.uk)
Fri, 9 Oct 1998 15:51:36 +0100


On Thu, Oct 08, 1998 at 02:11:28PM -0400, Kenneth Albanowski wrote:
> Alan Cox wrote:
> > When you discard a page you will need to put something back on a fault
> > in. Thats going to be the zero page so the cost is basically nil.
>
> I'm thinking of the common case, the page is marked discardable, but is
> then touched (read or write) before being discarded. Should the touch
> automatically zero the page? That would result in identical semantics
> whether or not the page had been discarded.

No it should NOT zero the page if it isn't discarded. The point is to
avoid the COW zeroing overhead -- otherwise what we're talking about is
an ordinary zero mapping which we have already, and _isn't_ worth
calling from free() precisely because of the overhead.

> OK, that answers the question. This (and what mingo adds) suggests that
> the original content will be useful if the page has not been discarded.

That too is easy enough (have a flag in the page, it gets zeroed by
virtue of the page getting discarded).

> That means if you want to use discardable pages as a method of zeroing
> pages, you'll need to zero the page yourself before discarding it.

You can do this already, just zero-map the page. It doesn't add to the
VMA list because malloc() memory is already in a zero-map VMA.

> (There's no reason malloc _has_ to do this, it's just a matter of
> providing a deterministic environment to placate buggy code.)

Good point, but it can do this already with existing mechanisms.
It has zeroing overhead -- the point is to avoid that.

> As for the pixmap cache idea: I thought for a moment that there would be
> race conditions, but since the first touch will clear the discardable
> flag, this doesn't feel like a problem. Some non-zero data in the page
> will be sufficient to recognize that the page is still present. The only
> issue is whether a pixmap (or whatever) cache is any use if individual
> pages can drop out.

Sounds like that would need a VMA all its own, such that if the kernel
discards any pages in the VMA it has to discard all of them (or
optimally just the first one, etc.; all quite yucky).

> And an aging mechanism also needs to be tied in, so that the least used
> pages will be harvested in preference to the most used.

Aging will still work as usual.

Marking a page discardable doesn't make it any older, and it stays
mapped -- touching is detected in the usual processor-specific way. So
the mechanism is quite efficient in the case that the page is not
discarded or when you repeatedly mark a page used but then touch it
quite soon afterwards.

-- Jamie

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