Skip to content

Commit 097d591

Browse files
committed
vm: avoid using find_vma_prev() unnecessarily
Several users of "find_vma_prev()" were not in fact interested in the previous vma if there was no primary vma to be found either. And in those cases, we're much better off just using the regular "find_vma()", and then "prev" can be looked up by just checking vma->vm_prev. The find_vma_prev() semantics are fairly subtle (see Mikulas' recent commit 83cd904: "mm: fix find_vma_prev"), and the whole "return prev by reference" means that it generates worse code too. Thus this "let's avoid using this inconvenient and clearly too subtle interface when we don't really have to" patch. Cc: Mikulas Patocka <mpatocka@redhat.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 71fece9 commit 097d591

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

arch/x86/mm/hugetlbpage.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
333333
* Lookup failure means no vma is above this address,
334334
* i.e. return with success:
335335
*/
336-
if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
336+
vma = find_vma(mm, add);
337+
if (!vma)
337338
return addr;
338339

339340
/*
340341
* new region fits between prev_vma->vm_end and
341342
* vma->vm_start, use it:
342343
*/
344+
prev_vma = vma->vm_prev;
343345
if (addr + len <= vma->vm_start &&
344346
(!prev_vma || (addr >= prev_vma->vm_end))) {
345347
/* remember the address as a hint for next time */

mm/mempolicy.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,11 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
640640
unsigned long vmstart;
641641
unsigned long vmend;
642642

643-
vma = find_vma_prev(mm, start, &prev);
643+
vma = find_vma(mm, start);
644644
if (!vma || vma->vm_start > start)
645645
return -EFAULT;
646646

647+
prev = vma->vm_prev;
647648
if (start > vma->vm_start)
648649
prev = vma;
649650

mm/mlock.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
385385
return -EINVAL;
386386
if (end == start)
387387
return 0;
388-
vma = find_vma_prev(current->mm, start, &prev);
388+
vma = find_vma(current->mm, start);
389389
if (!vma || vma->vm_start > start)
390390
return -ENOMEM;
391391

392+
prev = vma->vm_prev;
392393
if (start > vma->vm_start)
393394
prev = vma;
394395

mm/mprotect.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
262262

263263
down_write(&current->mm->mmap_sem);
264264

265-
vma = find_vma_prev(current->mm, start, &prev);
265+
vma = find_vma(current->mm, start);
266266
error = -ENOMEM;
267267
if (!vma)
268268
goto out;
269+
prev = vma->vm_prev;
269270
if (unlikely(grows & PROT_GROWSDOWN)) {
270271
if (vma->vm_start >= end)
271272
goto out;

0 commit comments

Comments
 (0)