Skip to content

Commit 7222708

Browse files
kiryltorvalds
authored andcommitted
mm, page_vma_mapped: Introduce pfn_in_hpage()
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 <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0d665e7 commit 7222708

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

mm/page_vma_mapped.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw)
3030
return true;
3131
}
3232

33+
static inline bool pfn_in_hpage(struct page *hpage, unsigned long pfn)
34+
{
35+
unsigned long hpage_pfn = page_to_pfn(hpage);
36+
37+
/* THP can be referenced by any subpage */
38+
return pfn >= hpage_pfn && pfn - hpage_pfn < hpage_nr_pages(hpage);
39+
}
40+
3341
/**
3442
* check_pte - check if @pvmw->page is mapped at the @pvmw->pte
3543
*
@@ -78,14 +86,7 @@ static bool check_pte(struct page_vma_mapped_walk *pvmw)
7886
pfn = pte_pfn(*pvmw->pte);
7987
}
8088

81-
if (pfn < page_to_pfn(pvmw->page))
82-
return false;
83-
84-
/* THP can be referenced by any subpage */
85-
if (pfn - page_to_pfn(pvmw->page) >= hpage_nr_pages(pvmw->page))
86-
return false;
87-
88-
return true;
89+
return pfn_in_hpage(pvmw->page, pfn);
8990
}
9091

9192
/**

0 commit comments

Comments
 (0)