[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220126164102.of64gqiikbtwhnu6@revolver>
Date: Wed, 26 Jan 2022 16:41:11 +0000
From: Liam Howlett <liam.howlett@...cle.com>
To: Vlastimil Babka <vbabka@...e.cz>
CC: "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>,
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>,
Rik van Riel <riel@...riel.com>,
Peter Zijlstra <peterz@...radead.org>,
Michel Lespinasse <walken.cr@...il.com>,
Jerome Glisse <jglisse@...hat.com>,
Minchan Kim <minchan@...gle.com>,
Joel Fernandes <joelaf@...gle.com>,
Rom Lemarchand <romlem@...gle.com>
Subject: Re: [PATCH v4 56/66] mm/mlock: Use maple tree iterators instead of
vma linked list
* Vlastimil Babka <vbabka@...e.cz> [220120 07:16]:
> On 12/1/21 15:30, Liam Howlett wrote:
> > From: "Liam R. Howlett" <Liam.Howlett@...cle.com>
> >
> > Signed-off-by: Liam R. Howlett <Liam.Howlett@...cle.com>
> > ---
> > mm/mlock.c | 19 +++++++++----------
> > 1 file changed, 9 insertions(+), 10 deletions(-)
> >
> > diff --git a/mm/mlock.c b/mm/mlock.c
> > index e263d62ae2d0..feb691eb4c64 100644
> > --- a/mm/mlock.c
> > +++ b/mm/mlock.c
> > @@ -563,6 +563,7 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
> > unsigned long nstart, end, tmp;
> > struct vm_area_struct *vma, *prev;
> > int error;
> > + MA_STATE(mas, ¤t->mm->mm_mt, start, start);
> >
> > VM_BUG_ON(offset_in_page(start));
> > VM_BUG_ON(len != PAGE_ALIGN(len));
> > @@ -571,11 +572,11 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
> > return -EINVAL;
> > if (end == start)
> > return 0;
> > - vma = find_vma(current->mm, start);
> > - if (!vma || vma->vm_start > start)
> > + vma = mas_walk(&mas);
> > + if (!vma)
> > return -ENOMEM;
> >
> > - prev = vma->vm_prev;
> > + prev = mas_prev(&mas, 0);
>
> Could be only done as an 'else' of the 'if' below?
Agreed. I will make that change.
>
> > if (start > vma->vm_start)
> > prev = vma;
> >
> > @@ -597,7 +598,7 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
> > if (nstart >= end)
> > break;
> >
> > - vma = prev->vm_next;
> > + vma = find_vma(prev->vm_mm, prev->vm_end);
> > if (!vma || vma->vm_start != nstart) {
> > error = -ENOMEM;
> > break;
> > @@ -618,15 +619,12 @@ static unsigned long count_mm_mlocked_page_nr(struct mm_struct *mm,
> > {
> > struct vm_area_struct *vma;
> > unsigned long count = 0;
> > + MA_STATE(mas, &mm->mm_mt, start, start);
> >
> > if (mm == NULL)
> > mm = current->mm;
> >
> > - vma = find_vma(mm, start);
> > - if (vma == NULL)
> > - return 0;
> > -
> > - for (; vma ; vma = vma->vm_next) {
> > + mas_for_each(&mas, vma, start + len) {
>
> Could be for_each_vma_range()?
yes, I will do this.
>
> > if (start >= vma->vm_end)
> > continue;
>
> Unnecessary? (even before this patch, I think?)
I think so too, I will remove it.
>
> > if (start + len <= vma->vm_start)
>
> Unnecessary after your patch?
This appears to be for overflow. My patch will not deal with overflow
as it is dealt with today. I will update my patch to deal with overflow
in the same way by removing this from the loop & setting up an end
variable. This will have the added benefit of reducing the loop for a
one time check. I don't love the fact that overflow is handled like
this. Perhaps this should be revisited at a later date.
>
> > @@ -741,6 +739,7 @@ static int apply_mlockall_flags(int flags)
> > {
> > struct vm_area_struct *vma, *prev = NULL;
> > vm_flags_t to_add = 0;
> > + unsigned long addr = 0;
> >
> > current->mm->def_flags &= VM_LOCKED_CLEAR_MASK;
> > if (flags & MCL_FUTURE) {
> > @@ -759,7 +758,7 @@ static int apply_mlockall_flags(int flags)
> > to_add |= VM_LOCKONFAULT;
> > }
> >
> > - for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
> > + mt_for_each(¤t->mm->mm_mt, vma, addr, ULONG_MAX) {
and I'll add a for_each_vma() here.
> > vm_flags_t newflags;
> >
> > newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
>
Powered by blists - more mailing lists