Skip to content

Commit 7fdbd37

Browse files
howlettakpm00
authored andcommitted
mm/mmap: use the maple tree for find_vma_prev() instead of the rbtree
Use the maple tree's advanced API and a maple state to walk the tree for the entry at the address of the next vma, then use the maple state to walk back one entry to find the previous entry. Add kernel documentation comments for this API. Link: https://lkml.kernel.org/r/20220906194824.2110408-13-Liam.Howlett@oracle.com Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Acked-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: David Hildenbrand <david@redhat.com> Tested-by: Yu Zhao <yuzhao@google.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: David Howells <dhowells@redhat.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: SeongJae Park <sj@kernel.org> Cc: Sven Schnelle <svens@linux.ibm.com> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent be8432e commit 7fdbd37

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

mm/mmap.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,23 +2475,30 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
24752475
}
24762476
EXPORT_SYMBOL(find_vma);
24772477

2478-
/*
2479-
* Same as find_vma, but also return a pointer to the previous VMA in *pprev.
2478+
/**
2479+
* find_vma_prev() - Find the VMA for a given address, or the next vma and
2480+
* set %pprev to the previous VMA, if any.
2481+
* @mm: The mm_struct to check
2482+
* @addr: The address
2483+
* @pprev: The pointer to set to the previous VMA
2484+
*
2485+
* Note that RCU lock is missing here since the external mmap_lock() is used
2486+
* instead.
2487+
*
2488+
* Returns: The VMA associated with @addr, or the next vma.
2489+
* May return %NULL in the case of no vma at addr or above.
24802490
*/
24812491
struct vm_area_struct *
24822492
find_vma_prev(struct mm_struct *mm, unsigned long addr,
24832493
struct vm_area_struct **pprev)
24842494
{
24852495
struct vm_area_struct *vma;
2496+
MA_STATE(mas, &mm->mm_mt, addr, addr);
24862497

2487-
vma = find_vma(mm, addr);
2488-
if (vma) {
2489-
*pprev = vma->vm_prev;
2490-
} else {
2491-
struct rb_node *rb_node = rb_last(&mm->mm_rb);
2492-
2493-
*pprev = rb_node ? rb_entry(rb_node, struct vm_area_struct, vm_rb) : NULL;
2494-
}
2498+
vma = mas_walk(&mas);
2499+
*pprev = mas_prev(&mas, 0);
2500+
if (!vma)
2501+
vma = mas_next(&mas, ULONG_MAX);
24952502
return vma;
24962503
}
24972504

0 commit comments

Comments
 (0)