2007-02-04 10:48:18

by Michal Hocko

[permalink] [raw]
Subject: mm: how to check for kernel pages

Hi,
is there any effective and fast way how to find out whether page
given by its page frame number is currenly used by (mapped by) kernel?

At the time of checking I can rely that such page:
- is not buddy allocator page and also not on per CPU lists
- is not compound page
- is not reserved page
Because I can check that from struct page's flags.
I was thinking about using rmap code to find all ptes, but I don't know
whether it is not too complicated way.

Thanks for all hints.

Please add me to Cc, because I am not the list member.
Best regards.
--
Michal Hocko


2007-02-04 13:57:33

by Arjan van de Ven

[permalink] [raw]
Subject: Re: mm: how to check for kernel pages

On Sun, 2007-02-04 at 12:02 +0100, Michal Hocko wrote:
> Hi,
> is there any effective and fast way how to find out whether page
> given by its page frame number is currenly used by (mapped by) kernel?

what do you want to use this for? The answer to your question greatly
depends on that...

Specifically, do you want to know if it's a kernel allocated page or a
kernel mapped page? (Those are different concepts)
Also can you deal with false negatives/positives?


2007-02-04 15:13:04

by Michal Hocko

[permalink] [raw]
Subject: Re: mm: how to check for kernel pages

On Sun, Feb 04, 2007 at 02:57:30PM +0100, Arjan van de Ven wrote:
> On Sun, 2007-02-04 at 12:02 +0100, Michal Hocko wrote:
> > Hi,
> > is there any effective and fast way how to find out whether page
> > given by its page frame number is currenly used by (mapped by) kernel?
>
> what do you want to use this for? The answer to your question greatly
> depends on that...

Sorry for not being more precise. As a part of my thesis work I need to
migrate pages. I greatly use mm/migrate.c code.
I assume that not all pages can be migrated - especially those used by
kernel (where direct virtual to physical mapping is used).
So I intended something like following code:

/* Returns 0 if page is suitable to be migration source */
int check_migrate_page(struct page * page)
{
return PageBuddy(page) || PageCompound(page) || ...
kernel_page(page);
}

/* Steals pfn page from its current user(s) and replace it by newly
* allocated page. pfn page structure is returned if page was migrated
* to new location (can be reused by caller) or NULL otherwise.
*/
struct page * steal_page(unsigned long pfn)
{
int ret;
struct page *page, *target_page;

page = pfn_to_page(pfn);
if(!page)
goto bad_page;

ret = check_migrate_page(page);
if(ret)
goto bad_page;

target_page = alloc_pages(flags, 0);
/* uses migrate_pages function internally */
ret = do_migration(page, target_page);
if(ret)
goto bad_page;

/* TODO clear page frame data. */
return page;
bad_page:
return NULL;
}

Please add me to Cc, because I am not the list member.
Best regards
--
Michal Hocko

2007-02-04 15:45:59

by Arjan van de Ven

[permalink] [raw]
Subject: Re: mm: how to check for kernel pages

On Sun, 2007-02-04 at 16:33 +0100, Michal Hocko wrote:
> On Sun, Feb 04, 2007 at 02:57:30PM +0100, Arjan van de Ven wrote:
> > On Sun, 2007-02-04 at 12:02 +0100, Michal Hocko wrote:
> > > Hi,
> > > is there any effective and fast way how to find out whether page
> > > given by its page frame number is currenly used by (mapped by) kernel?
> >
> > what do you want to use this for? The answer to your question greatly
> > depends on that...
>
> Sorry for not being more precise. As a part of my thesis work I need to
> migrate pages. I greatly use mm/migrate.c code.
> I assume that not all pages can be migrated - especially those used by
> kernel (where direct virtual to physical mapping is used).
> So I intended something like following code:

it's more than that... even userspace pages may not be moved if they're
the target of active DMA for example .....
--
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org

2007-02-04 16:33:39

by Michal Hocko

[permalink] [raw]
Subject: Re: mm: how to check for kernel pages

On Sun, Feb 04, 2007 at 04:45:51PM +0100, Arjan van de Ven wrote:
> > Sorry for not being more precise. As a part of my thesis work I need to
> > migrate pages. I greatly use mm/migrate.c code.
> > I assume that not all pages can be migrated - especially those used by
> > kernel (where direct virtual to physical mapping is used).
> > So I intended something like following code:
>
> it's more than that... even userspace pages may not be moved if they're
> the target of active DMA for example .....

Ok, so what everything should be checked?

- PageReserved
- PageSlab
- PageLocked
- PageBuddy
- PageCompound
- PageNosave
- PageNosaveFree
- kernel page
- userspace active DMA as you've mentioned. But I don't know how to test
it

--
Michal Hocko

2007-02-04 17:50:10

by David Schwartz

[permalink] [raw]
Subject: RE: mm: how to check for kernel pages


> Ok, so what everything should be checked?
>
> - PageReserved
> - PageSlab
> - PageLocked
> - PageBuddy
> - PageCompound
> - PageNosave
> - PageNosaveFree
> - kernel page
> - userspace active DMA as you've mentioned. But I don't know how to test
> it

Perhaps I'm missing something obvious, but shouldn't this just be the same
check to see if the page can be swapped out or discarded? Surely any page
that can be swapped out or discarded can be migrated. There might
theoretically be some pages that can't be swapped out or discarded that
could be migrated, but why not just ignore those cases?

DS