[PATCH] mm/mlock: stop counting mlocked pages when none vma is found

From: Miaohe Lin
Date: Thu Feb 04 2021 - 06:08:27 EST


There will be no vma satisfies addr < vm_end when find_vma() returns NULL.
Thus it's meaningless to traverse the vma list below because we can't find
any vma to count mlocked pages. Stop counting mlocked pages in this case to
save some vma list traversal cycles.

Signed-off-by: Miaohe Lin <linmiaohe@xxxxxxxxxx>
---
mm/mlock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/mlock.c b/mm/mlock.c
index 73960bb3464d..f8f8cc32d03d 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -622,7 +622,7 @@ static unsigned long count_mm_mlocked_page_nr(struct mm_struct *mm,

vma = find_vma(mm, start);
if (vma == NULL)
- vma = mm->mmap;
+ return 0;

for (; vma ; vma = vma->vm_next) {
if (start >= vma->vm_end)
--
2.19.1