linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/hugetlb.c: fix unnecessary address expansion of pmd sharing
@ 2020-12-29  4:21 Li Xinhai
  2020-12-29 19:21 ` Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Li Xinhai @ 2020-12-29  4:21 UTC (permalink / raw)
  To: linux-mm; +Cc: akpm, Mike Kravetz, Peter Xu

The current code would unnecessarily expand the address range. Consider
one example, (start, end) = (1G-2M, 3G+2M), and  (vm_start, vm_end) =
(1G-4M, 3G+4M), the expected adjustment should be keep (1G-2M, 3G+2M)
without expand. But the current result will be (1G-4M, 3G+4M). Actually,
the range (1G-4M, 1G) and (3G, 3G+4M) would never been involved in pmd
sharing.

After this patch, if pud aligned *start across vm_start, then we know the
*start and vm_start are in same pud_index, and vm_start is not pud
aligned, so don't adjust *start. Same logic applied to *end.

Fixes: commit 75802ca66354 ("mm/hugetlb: fix calculation of adjust_range_if_pmd_sharing_possible")
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Peter Xu <peterx@redhat.com>
Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
---
 mm/hugetlb.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index cbf32d2824fd..d1e9ea55b7e6 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5249,11 +5249,16 @@ void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma,
 	a_end = ALIGN(*end, PUD_SIZE);
 
 	/*
-	 * Intersect the range with the vma range, since pmd sharing won't be
-	 * across vma after all
+	 * If the PUD aligned address across vma range, then it means the
+	 * vm_start/vm_end is not PUD aligned. In that case, we must don't
+	 * adjust range because pmd sharing is not possbile at the start and/or
+	 * end part of vma.
 	 */
-	*start = max(vma->vm_start, a_start);
-	*end = min(vma->vm_end, a_end);
+	if (a_start >= vma->vm_start)
+		*start = a_start;
+
+	if (a_end <= vma->vm_end)
+		*end = a_end;
 }
 
 /*
-- 
2.18.4



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-01-05 18:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-29  4:21 [PATCH] mm/hugetlb.c: fix unnecessary address expansion of pmd sharing Li Xinhai
2020-12-29 19:21 ` Andrew Morton
2020-12-29 21:20 ` Mike Kravetz
2020-12-31 17:56   ` Mike Kravetz
2021-01-02 11:56     ` Li Xinhai
2021-01-04  3:55       ` Mike Kravetz
2021-01-04  7:10         ` Li Xinhai
2021-01-04 18:59           ` Mike Kravetz
2021-01-05  2:10             ` Li Xinhai
2021-01-05  2:38               ` Li Xinhai
2021-01-05 18:20                 ` Mike Kravetz
2020-12-30 18:42 ` Peter Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox