Skip to content

Commit be8432e

Browse files
howlettakpm00
authored andcommitted
mm/mmap: use the maple tree in find_vma() instead of the rbtree.
Using the maple tree interface mt_find() will handle the RCU locking and will start searching at the address up to the limit, ULONG_MAX in this case. Add kernel documentation to this API. Link: https://lkml.kernel.org/r/20220906194824.2110408-12-Liam.Howlett@oracle.com Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> 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: "Matthew Wilcox (Oracle)" <willy@infradead.org> 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 2e3af1d commit be8432e

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

mm/mmap.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,34 +2449,26 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
24492449

24502450
EXPORT_SYMBOL(get_unmapped_area);
24512451

2452-
/* Look up the first VMA which satisfies addr < vm_end, NULL if none. */
2452+
/**
2453+
* find_vma() - Find the VMA for a given address, or the next VMA.
2454+
* @mm: The mm_struct to check
2455+
* @addr: The address
2456+
*
2457+
* Returns: The VMA associated with addr, or the next VMA.
2458+
* May return %NULL in the case of no VMA at addr or above.
2459+
*/
24532460
struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
24542461
{
2455-
struct rb_node *rb_node;
24562462
struct vm_area_struct *vma;
2463+
unsigned long index = addr;
24572464

24582465
mmap_assert_locked(mm);
24592466
/* Check the cache first. */
24602467
vma = vmacache_find(mm, addr);
24612468
if (likely(vma))
24622469
return vma;
24632470

2464-
rb_node = mm->mm_rb.rb_node;
2465-
2466-
while (rb_node) {
2467-
struct vm_area_struct *tmp;
2468-
2469-
tmp = rb_entry(rb_node, struct vm_area_struct, vm_rb);
2470-
2471-
if (tmp->vm_end > addr) {
2472-
vma = tmp;
2473-
if (tmp->vm_start <= addr)
2474-
break;
2475-
rb_node = rb_node->rb_left;
2476-
} else
2477-
rb_node = rb_node->rb_right;
2478-
}
2479-
2471+
vma = mt_find(&mm->mm_mt, &index, ULONG_MAX);
24802472
if (vma)
24812473
vmacache_update(addr, vma);
24822474
return vma;

0 commit comments

Comments
 (0)