Skip to content

Commit 2e3af1d

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mmap: use the VMA iterator in count_vma_pages_range()
This simplifies the implementation and is faster than using the linked list. Link: https://lkml.kernel.org/r/20220906194824.2110408-11-Liam.Howlett@oracle.com Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net> Tested-by: Yu Zhao <yuzhao@google.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: David Howells <dhowells@redhat.com> 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 f39af05 commit 2e3af1d

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

mm/mmap.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -629,29 +629,19 @@ munmap_vma_range(struct mm_struct *mm, unsigned long start, unsigned long len,
629629

630630
return 0;
631631
}
632+
632633
static unsigned long count_vma_pages_range(struct mm_struct *mm,
633634
unsigned long addr, unsigned long end)
634635
{
635-
unsigned long nr_pages = 0;
636+
VMA_ITERATOR(vmi, mm, addr);
636637
struct vm_area_struct *vma;
638+
unsigned long nr_pages = 0;
637639

638-
/* Find first overlapping mapping */
639-
vma = find_vma_intersection(mm, addr, end);
640-
if (!vma)
641-
return 0;
642-
643-
nr_pages = (min(end, vma->vm_end) -
644-
max(addr, vma->vm_start)) >> PAGE_SHIFT;
645-
646-
/* Iterate over the rest of the overlaps */
647-
for (vma = vma->vm_next; vma; vma = vma->vm_next) {
648-
unsigned long overlap_len;
649-
650-
if (vma->vm_start > end)
651-
break;
640+
for_each_vma_range(vmi, vma, end) {
641+
unsigned long vm_start = max(addr, vma->vm_start);
642+
unsigned long vm_end = min(end, vma->vm_end);
652643

653-
overlap_len = min(end, vma->vm_end) - vma->vm_start;
654-
nr_pages += overlap_len >> PAGE_SHIFT;
644+
nr_pages += PHYS_PFN(vm_end - vm_start);
655645
}
656646

657647
return nr_pages;

0 commit comments

Comments
 (0)