Skip to content

Commit

Permalink
mm, page_vma_mapped: Introduce pfn_in_hpage()
Browse files Browse the repository at this point in the history
The new helper would check if the pfn belongs to the page. For huge
pages it checks if the PFN is within range covered by the huge page.

The helper is used in check_pte(). The original code the helper replaces
had two call to page_to_pfn(). page_to_pfn() is relatively costly.

Although current GCC is able to optimize code to have one call, it's
better to do this explicitly.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Kirill A. Shutemov authored and Linus Torvalds committed Jan 22, 2018
1 parent 0d665e7 commit 7222708
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions mm/page_vma_mapped.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw)
return true;
}

static inline bool pfn_in_hpage(struct page *hpage, unsigned long pfn)
{
unsigned long hpage_pfn = page_to_pfn(hpage);

/* THP can be referenced by any subpage */
return pfn >= hpage_pfn && pfn - hpage_pfn < hpage_nr_pages(hpage);
}

/**
* check_pte - check if @pvmw->page is mapped at the @pvmw->pte
*
Expand Down Expand Up @@ -78,14 +86,7 @@ static bool check_pte(struct page_vma_mapped_walk *pvmw)
pfn = pte_pfn(*pvmw->pte);
}

if (pfn < page_to_pfn(pvmw->page))
return false;

/* THP can be referenced by any subpage */
if (pfn - page_to_pfn(pvmw->page) >= hpage_nr_pages(pvmw->page))
return false;

return true;
return pfn_in_hpage(pvmw->page, pfn);
}

/**
Expand Down

0 comments on commit 7222708

Please sign in to comment.