]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm/page_vma_mapped.c: explicitly compare pfn for normal, hugetlbfs and THP page
authorLi Xinhai <lixinhai.lxh@gmail.com>
Fri, 31 Jan 2020 06:13:45 +0000 (22:13 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 31 Jan 2020 18:30:38 +0000 (10:30 -0800)
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/1578737885-8890-1-git-send-email-lixinhai.lxh@gmail.com
Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/page_vma_mapped.c

index eff4b4520c8d5c7603efb2a5f77f3ec3d8d79a3e..719c35246cfaba7c6cd96d3bc0bbaf300225839d 100644 (file)
@@ -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 (!PageTransCompound(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);
 }
 
 /**