• L
    mm/hugetlb.c: fix unnecessary address expansion of pmd sharing · a1ba9da8
    Li Xinhai 提交于
    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, we will check that the vma span at least one PUD aligned
    size and the start,end range overlap the aligned range of vma.
    
    With above example, the aligned vma range is (1G, 3G), so if (start, end)
    range is within (1G-4M, 1G), or within (3G, 3G+4M), then no adjustment to
    both start and end.  Otherwise, we will have chance to adjust start
    downwards or end upwards without exceeding (vm_start, vm_end).
    
    Mike:
    
    : The 'adjusted range' is used for calls to mmu notifiers and cache(tlb)
    : flushing.  Since the current code unnecessarily expands the range in some
    : cases, more entries than necessary would be flushed.  This would/could
    : result in performance degradation.  However, this is highly dependent on
    : the user runtime.  Is there a combination of vma layout and calls to
    : actually hit this issue?  If the issue is hit, will those entries
    : unnecessarily flushed be used again and need to be unnecessarily reloaded?
    
    Link: https://lkml.kernel.org/r/20210104081631.2921415-1-lixinhai.lxh@gmail.com
    Fixes: 75802ca6 ("mm/hugetlb: fix calculation of adjust_range_if_pmd_sharing_possible")
    Signed-off-by: NLi Xinhai <lixinhai.lxh@gmail.com>
    Suggested-by: NMike Kravetz <mike.kravetz@oracle.com>
    Reviewed-by: NMike Kravetz <mike.kravetz@oracle.com>
    Cc: Peter Xu <peterx@redhat.com>
    Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
    a1ba9da8
hugetlb.c 155.7 KB