Re: [RFC] Page table sharing

Linus Torvalds (torvalds@transmeta.com)
Sat, 16 Feb 2002 22:23:02 -0800 (PST)


On Sat, 16 Feb 2002, Daniel Phillips wrote:
> >
> > if (put_page_testzero(pmd_page)) {
> > .. free the actual page table entries ..
> > __free_pages_ok(pmd_page, 0);
> > }
> >
> > instead of using the free_page() logic. Maybe you do that already, I
> > didn't go through the patches _that_ closely.
>
> I do something similar in clear_page_tables->free_one_pmd, after the entries
> are all gone. I have to do something different in zap_page_range - it wants
> to free the pmd only if the count is *greater* than one, and can't tolerate
> two mms thinking that at the same time. I think I'd better lock the pmd page
> there.

But that's ok.

If you have the logic that

if (put_page_testzero(pmd_page)) {
... do the lower-level free ...
__free_pages_ok(pmd_page, 0);
}

then you automatically have exactly the behaviour you want, with no
locking at all (except for the "local" locking inherent in the atomic
decrement-and-test).

What you have is:
- _if_ the count was > 1, then you do nothing at all (except for
decrementing your count)
- for the last user (and for that _only_), where the count was 1 and goes
to zero, you'll do the inside of the "if ()" statement, and actually
clean up the page table and free the pmd.

So you not only get the optimization you want, you also quite naturally
get the "exclusive last user" case.

Linus

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