[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210817154651.1570984-21-Liam.Howlett@oracle.com>
Date: Tue, 17 Aug 2021 15:47:18 +0000
From: Liam Howlett <liam.howlett@...cle.com>
To: "maple-tree@...ts.infradead.org" <maple-tree@...ts.infradead.org>,
"linux-mm@...ck.org" <linux-mm@...ck.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Andrew Morton <akpm@...ux-foundation.org>
CC: Song Liu <songliubraving@...com>,
Davidlohr Bueso <dave@...olabs.net>,
"Paul E . McKenney" <paulmck@...nel.org>,
Matthew Wilcox <willy@...radead.org>,
Laurent Dufour <ldufour@...ux.ibm.com>,
David Rientjes <rientjes@...gle.com>,
Axel Rasmussen <axelrasmussen@...gle.com>,
Suren Baghdasaryan <surenb@...gle.com>,
Vlastimil Babka <vbabka@...e.cz>,
Rik van Riel <riel@...riel.com>,
Peter Zijlstra <peterz@...radead.org>,
Michel Lespinasse <walken.cr@...il.com>,
Liam Howlett <liam.howlett@...cle.com>
Subject: [PATCH v2 20/61] mm/mmap: Convert count_vma_pages_range() to use
ma_state
From: "Liam R. Howlett" <Liam.Howlett@...cle.com>
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@...cle.com>
---
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
Powered by blists - more mailing lists