From d4ce53c32b490f10f387cdcf75685e93647055ca Mon Sep 17 00:00:00 2001 From: KOSAKI Motohiro Date: Fri, 16 Dec 2011 15:49:57 +1100 Subject: [PATCH] mm: simplify find_vma_prev() commit 297c5eee37 ("mm: make the vma list be doubly linked") added the vm_prev member to vm_area_struct. We can simplify find_vma_prev() by using it. Also, this change helps to improve page fault performance because it has stronger locality of reference. Signed-off-by: KOSAKI Motohiro Reviewed-by: KAMEZAWA Hiroyuki Cc: Hugh Dickins Cc: Peter Zijlstra Cc: Shaohua Li Cc: Linus Torvalds Cc: Michal Hocko Signed-off-by: Andrew Morton --- mm/mmap.c | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index be0d6066b7db..82e90ab3ecea 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1626,39 +1626,21 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr) EXPORT_SYMBOL(find_vma); -/* Same as find_vma, but also return a pointer to the previous VMA in *pprev. */ +/* + * Same as find_vma, but also return a pointer to the previous VMA in *pprev. + * Note: pprev is set to NULL when return value is NULL. + */ struct vm_area_struct * -find_vma_prev(struct mm_struct *mm, unsigned long addr, - struct vm_area_struct **pprev) +find_vma_prev(struct mm_struct *mm, unsigned long addr, struct vm_area_struct **pprev) { - struct vm_area_struct *vma = NULL, *prev = NULL; - struct rb_node *rb_node; - if (!mm) - goto out; - - /* Guard against addr being lower than the first VMA */ - vma = mm->mmap; - - /* Go through the RB tree quickly. */ - rb_node = mm->mm_rb.rb_node; - - while (rb_node) { - struct vm_area_struct *vma_tmp; - vma_tmp = rb_entry(rb_node, struct vm_area_struct, vm_rb); + struct vm_area_struct *vma; - if (addr < vma_tmp->vm_end) { - rb_node = rb_node->rb_left; - } else { - prev = vma_tmp; - if (!prev->vm_next || (addr < prev->vm_next->vm_end)) - break; - rb_node = rb_node->rb_right; - } - } + *pprev = NULL; + vma = find_vma(mm, addr); + if (vma) + *pprev = vma->vm_prev; -out: - *pprev = prev; - return prev ? prev->vm_next : vma; + return vma; } /* -- 2.39.5