Re: [PATCH] mm/mmap.c: refine data locality of find_vma_prev

From: Vlastimil Babka
Date: Thu Aug 08 2019 - 04:49:34 EST


On 8/8/19 5:26 AM, Wei Yang wrote:
>
> @@ -2270,12 +2270,9 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
> if (vma) {
> *pprev = vma->vm_prev;
> } else {
> - struct rb_node *rb_node = mm->mm_rb.rb_node;
> - *pprev = NULL;
> - while (rb_node) {
> - *pprev = rb_entry(rb_node, struct vm_area_struct, vm_rb);
> - rb_node = rb_node->rb_right;
> - }
> + struct rb_node *rb_node = rb_last(&mm->mm_rb);
> + *pprev = !rb_node ? NULL :
> + rb_entry(rb_node, struct vm_area_struct, vm_rb);
> }
> return vma;
>
> Not sure this style would help a little in understanding the code?

Yeah using rb_last() would be nicer than basically repeating its
implementation, so it's fine as a cleanup without performance implications.

>> --
>> Michal Hocko
>> SUSE Labs
>