Skip to content

Commit 5b8d6e3

Browse files
Li Xinhaitorvalds
authored andcommitted
mm/page_vma_mapped.c: explicitly compare pfn for normal, hugetlbfs and THP page
When check_pte, pfn of normal, hugetlbfs and THP page need be compared. The current implementation apply comparison as - normal 4K page: page_pfn <= pfn < page_pfn + 1 - hugetlbfs page: page_pfn <= pfn < page_pfn + HPAGE_PMD_NR - THP page: page_pfn <= pfn < page_pfn + HPAGE_PMD_NR in pfn_in_hpage. For hugetlbfs page, it should be page_pfn == pfn Now, change pfn_in_hpage to pfn_is_match to highlight that comparison is not only for THP and explicitly compare for these cases. No impact upon current behavior, just make the code clear. I think it is important to make the code clear - comparing hugetlbfs page in range page_pfn <= pfn < page_pfn + HPAGE_PMD_NR is confusing. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Li Xinhai <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Acked-by: Mike Kravetz <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Michal Hocko <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9285527 commit 5b8d6e3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mm/page_vma_mapped.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw)
5252
return true;
5353
}
5454

55-
static inline bool pfn_in_hpage(struct page *hpage, unsigned long pfn)
55+
static inline bool pfn_is_match(struct page *page, unsigned long pfn)
5656
{
57-
unsigned long hpage_pfn = page_to_pfn(hpage);
57+
unsigned long page_pfn = page_to_pfn(page);
58+
59+
/* normal page and hugetlbfs page */
60+
if (!PageTransCompound(page) || PageHuge(page))
61+
return page_pfn == pfn;
5862

5963
/* THP can be referenced by any subpage */
60-
return pfn >= hpage_pfn && pfn - hpage_pfn < hpage_nr_pages(hpage);
64+
return pfn >= page_pfn && pfn - page_pfn < hpage_nr_pages(page);
6165
}
6266

6367
/**
@@ -108,7 +112,7 @@ static bool check_pte(struct page_vma_mapped_walk *pvmw)
108112
pfn = pte_pfn(*pvmw->pte);
109113
}
110114

111-
return pfn_in_hpage(pvmw->page, pfn);
115+
return pfn_is_match(pvmw->page, pfn);
112116
}
113117

114118
/**

0 commit comments

Comments
 (0)