On 1/4/21 11:55 AM, Mike Kravetz wrote:
I believe the only case where your patch produced incorrect results is
when the range was within a vma that was smaller than PUD_SIZE. Do you
agree?
Not exactly. We need to consider for vma which span at least one
PUD_SIZE after align its vm_start and vm_end.
If that is the case, then how about just adding the following to your patch?
I think this is simpler and faster than the 'range_in_vma' checking I proposed.
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 49990c0a02a3..716d1e58a7ae 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5261,7 +5261,9 @@ void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma,
{
unsigned long a_start, a_end;
- if (!(vma->vm_flags & VM_MAYSHARE))
+ /* Quick check for vma capable of pmd sharing */
+ if (!(vma->vm_flags & VM_MAYSHARE) ||
+ (vma->vm_start - vma->vm_end) < PUD_SIZE)
return;
/* Extend the range to be PUD aligned for a worst case scenario */
Your suggestion is good, we are able to simplify the code a bit, with
less comparison, and maybe easier to follow. I will send a new patch to
review.