[PATCH v2 20/61] mm/mmap: Convert count_vma_pages_range() to use ma_state

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Liam R. Howlett" <Liam.Howlett@xxxxxxxxxx>

mmap_region() uses a maple state to do all the work so convert the
static inline count_vma_pages_range() to use the same structure.

Signed-off-by: Liam R. Howlett <Liam.Howlett@xxxxxxxxxx>
---
 mm/mmap.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index ef618dfd1d94..d01659a64b86 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -502,30 +502,41 @@ static inline struct vm_area_struct *vma_next(struct mm_struct *mm,
 	return vma->vm_next;
 }
 
-static unsigned long count_vma_pages_range(struct mm_struct *mm,
-		unsigned long addr, unsigned long end)
+/*
+ * count_vma_pages_range() - Count the number of pages in a range.
+ * @mas: The maple state
+ *
+ * The start and end address are in the @mas
+ * @mas must be locked.
+ */
+static unsigned long count_vma_pages_range(struct ma_state *mas)
 {
 	unsigned long nr_pages = 0;
 	struct vm_area_struct *vma;
 	unsigned long vm_start, vm_end;
-	MA_STATE(mas, &mm->mm_mt, addr, addr);
+	unsigned long end = mas->last;
+	unsigned long addr = mas->index;
+	struct ma_state ma_count = *mas;
 
+	rcu_read_lock();
 	/* Find first overlapping mapping */
-	vma = mas_find(&mas, end - 1);
+	vma = mas_find(&ma_count, end);
 	if (!vma)
-		return 0;
+		goto unlock;
 
 	vm_start = vma->vm_start;
 	vm_end = vma->vm_end;
-	nr_pages = (min(end, vm_end) - max(addr, vm_start)) >> PAGE_SHIFT;
+	nr_pages = (min(end + 1, vm_end) - max(addr, vm_start)) >> PAGE_SHIFT;
 
 	/* Iterate over the rest of the overlaps */
-	mas_for_each(&mas, vma, end) {
+	mas_for_each(&ma_count, vma, end) {
 		vm_start = vma->vm_start;
 		vm_end = vma->vm_end;
 		nr_pages += (min(end, vm_end) - vm_start) >> PAGE_SHIFT;
 	}
 
+unlock:
+	rcu_read_unlock();
 	return nr_pages;
 }
 
@@ -2607,7 +2618,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
 		 * MAP_FIXED may remove pages of mappings that intersects with
 		 * requested mapping. Account for the pages it would unmap.
 		 */
-		nr_pages = count_vma_pages_range(mm, addr, end);
+		nr_pages = count_vma_pages_range(&mas);
 
 		if (!may_expand_vm(mm, vm_flags,
 					(len >> PAGE_SHIFT) - nr_pages))
-- 
2.30.2





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux