LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* mm: how to check for kernel pages
@ 2007-02-04 11:02 Michal Hocko
  2007-02-04 13:57 ` Arjan van de Ven
  0 siblings, 1 reply; 6+ messages in thread
From: Michal Hocko @ 2007-02-04 11:02 UTC (permalink / raw)
  To: linux-kernel

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mm: how to check for kernel pages
  2007-02-04 11:02 mm: how to check for kernel pages Michal Hocko
@ 2007-02-04 13:57 ` Arjan van de Ven
  2007-02-04 15:33   ` Michal Hocko
  0 siblings, 1 reply; 6+ messages in thread
From: Arjan van de Ven @ 2007-02-04 13:57 UTC (permalink / raw)
  To: Michal Hocko; +Cc: linux-kernel

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?



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mm: how to check for kernel pages
  2007-02-04 13:57 ` Arjan van de Ven
@ 2007-02-04 15:33   ` Michal Hocko
  2007-02-04 15:45     ` Arjan van de Ven
  0 siblings, 1 reply; 6+ messages in thread
From: Michal Hocko @ 2007-02-04 15:33 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: linux-kernel

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mm: how to check for kernel pages
  2007-02-04 15:33   ` Michal Hocko
@ 2007-02-04 15:45     ` Arjan van de Ven
  2007-02-04 16:54       ` Michal Hocko
  0 siblings, 1 reply; 6+ messages in thread
From: Arjan van de Ven @ 2007-02-04 15:45 UTC (permalink / raw)
  To: Michal Hocko; +Cc: linux-kernel

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mm: how to check for kernel pages
  2007-02-04 15:45     ` Arjan van de Ven
@ 2007-02-04 16:54       ` Michal Hocko
  2007-02-04 17:49         ` David Schwartz
  0 siblings, 1 reply; 6+ messages in thread
From: Michal Hocko @ 2007-02-04 16:54 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: linux-kernel

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: mm: how to check for kernel pages
  2007-02-04 16:54       ` Michal Hocko
@ 2007-02-04 17:49         ` David Schwartz
  0 siblings, 0 replies; 6+ messages in thread
From: David Schwartz @ 2007-02-04 17:49 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: linux-kernel


> 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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-02-04 17:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-04 11:02 mm: how to check for kernel pages Michal Hocko
2007-02-04 13:57 ` Arjan van de Ven
2007-02-04 15:33   ` Michal Hocko
2007-02-04 15:45     ` Arjan van de Ven
2007-02-04 16:54       ` Michal Hocko
2007-02-04 17:49         ` David Schwartz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).