Re: [PATCH 0/13] maps: pagemap, kpagemap, and related cleanups

Andrew Morton
2007-04-13T01:22:20Z

On Fri, 13 Apr 2007 11:14:20 +1000 Nick Piggin <nickpiggin@yahoo.com.au> wrote:

> Andrew Morton wrote:
> > On Fri, 13 Apr 2007 10:15:24 +1000 Nick Piggin <nickpiggin@yahoo.com.au> wrote:
>
> >>>>+ for (; i < 2 * chunk / KPMSIZE; i += 2, pfn++) {
> >>>>+ ppage = pfn_to_page(pfn);
> >>>>+ if (!ppage) {
> >>>>+ page[i] = 0;
> >>>>+ page[i + 1] = 0;
> >>>>+ } else {
> >>>>+ page[i] = ppage->flags;
> >>>>+ page[i + 1] = atomic_read(&ppage->_count);
> >>>>+ }
> >>>>+ }
> >>>
> >>>
> >>>Not a good idea to expose raw flags in this manner - it changes at the drop
> >>>of a hat. We'd need to also expose the kernel's PG_foo-to-bitnumber
> >>>mapping to make this viable.
> >>
> >>I don't think it is viable because that makes the flags part of the
> >>userspace ABI.
> >
> >
> > It *will* be viable. If the application wants to know if a page is dirty,
> > it looks up "PG_dirty" in /proc/pg_foo-to-bitnumber and uses PG_dirty's
> > numerical offset when inspecting fields in /proc/kpagemap. If correctly
> > designed, such a monitoring application will be able to report upon page
> > flags which we haven't even thought up yet.
>
> Ooh, you wanted a _runtime_ mapping of flags, yeah then I guess that works.
> Still seems like a basically hit and miss affair to just use flags. What if
> you want to know the process mapping a page? With systemtap or something you
> could walk the rmap structures. What if you want to look at pages along the
> LRU list rather than per-pfn? What about connecting pages to inodes?

Well hang on. This isn't a tool for understanding kernel behaviour. It's
a tool for understanding applciation behaviour.

So one doesn't ask "who is mapping that page" - that's a kernel developer
thing.

Instead, one says "what pages are being used by my application", then, for
each of those pages "what is that page's state". So the first step is to
collect all the pfns from /proc/$(pidof my-application)/pagemap and then to
use those pfns to look the individual pages up in /proc/kpagemap.

If you really want to know "who is using page 123435" then you'd need to
search /proc/*/pagemap. There are possibly legitimate reasons why an
application developer would want to at least pertially perform such an
operation ("who am I sharing with"), but I doubt if it's the common case.

>
> But I was going to say
> that satisfying an Oracle requirement is a good reason _not_ to merge it ;)
>

hm, yes, there's plenty of precedent for that.

> (I joke!)

I akpm!