[v3] mm/page_vma_mapped.c: Explicitly compare pfn for noraml, hugetlbfs and THP page
diff mbox series

Message ID 1578671804-8297-1-git-send-email-lixinhai.lxh@gmail.com
State New
Headers show
Series
  • [v3] mm/page_vma_mapped.c: Explicitly compare pfn for noraml, hugetlbfs and THP page
Related show

Commit Message

Li Xinhai Jan. 10, 2020, 3:56 p.m. UTC
When check_pte, pfn of normal, hugetlbfs and THP page need be compared.
The current implementation apply comparison as
- normal 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.

Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Michal Hocko <mhocko@kernel.org>
---
 mm/page_vma_mapped.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Kirill A. Shutemov Jan. 11, 2020, midnight UTC | #1
On Fri, Jan 10, 2020 at 03:56:44PM +0000, Li Xinhai wrote:
> When check_pte, pfn of normal, hugetlbfs and THP page need be compared.
> The current implementation apply comparison as
> - normal 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.
> 
> Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Mike Kravetz <mike.kravetz@oracle.com>
> Cc: Michal Hocko <mhocko@kernel.org>
> ---
>  mm/page_vma_mapped.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
> index eff4b45..a286ff7 100644
> --- a/mm/page_vma_mapped.c
> +++ b/mm/page_vma_mapped.c
> @@ -52,12 +52,16 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw)
>  	return true;
>  }
>  
> -static inline bool pfn_in_hpage(struct page *hpage, unsigned long pfn)
> +static inline bool pfn_is_match(struct page *page, unsigned long pfn)
>  {
> -	unsigned long hpage_pfn = page_to_pfn(hpage);
> +	unsigned long page_pfn = page_to_pfn(page);
> +
> +	/* normal page and hugetlbfs page */
> +	if (!PageCompound(page) || PageHuge(page))

!PageTransCompound() instead of !PageCompound() would be better for cases
when THP is disabled compile-time. Otherwise:

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

Patch
diff mbox series

diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
index eff4b45..a286ff7 100644
--- a/mm/page_vma_mapped.c
+++ b/mm/page_vma_mapped.c
@@ -52,12 +52,16 @@  static bool map_pte(struct page_vma_mapped_walk *pvmw)
 	return true;
 }
 
-static inline bool pfn_in_hpage(struct page *hpage, unsigned long pfn)
+static inline bool pfn_is_match(struct page *page, unsigned long pfn)
 {
-	unsigned long hpage_pfn = page_to_pfn(hpage);
+	unsigned long page_pfn = page_to_pfn(page);
+
+	/* normal page and hugetlbfs page */
+	if (!PageCompound(page) || PageHuge(page))
+		return page_pfn == pfn;
 
 	/* THP can be referenced by any subpage */
-	return pfn >= hpage_pfn && pfn - hpage_pfn < hpage_nr_pages(hpage);
+	return pfn >= page_pfn && pfn - page_pfn < hpage_nr_pages(page);
 }
 
 /**
@@ -108,7 +112,7 @@  static bool check_pte(struct page_vma_mapped_walk *pvmw)
 		pfn = pte_pfn(*pvmw->pte);
 	}
 
-	return pfn_in_hpage(pvmw->page, pfn);
+	return pfn_is_match(pvmw->page, pfn);
 }
 
 /**