Re: [PATCH] mm: madvise: MADV_DONTNEED_LOCKED

From: Johannes Weiner
Date: Thu Mar 03 2022 - 17:25:23 EST


On Thu, Mar 03, 2022 at 01:35:56PM -0800, Nadav Amit wrote:
>
>
> > On Mar 3, 2022, at 1:29 PM, Johannes Weiner <hannes@xxxxxxxxxxx> wrote:
> >
> > MADV_DONTNEED historically rejects mlocked ranges, but with
> > MLOCK_ONFAULT and MCL_ONFAULT allowing to mlock without populating,
> > there are valid use cases for depopulating locked ranges as well.
>
> ...
>
> > @@ -850,7 +858,7 @@ static long madvise_dontneed_free(struct vm_area_struct *vma,
> > VM_WARN_ON(start >= end);
> > }
> >
> > - if (behavior == MADV_DONTNEED)
> > + if (behavior == MADV_DONTNEED || behavior == MADV_DONTNEED_LOCKED)
> > return madvise_dontneed_single_vma(vma, start, end);
> > else if (behavior == MADV_FREE)
> > return madvise_free_single_vma(vma, start, end);
> > @@ -988,6 +996,7 @@ static int madvise_vma_behavior(struct vm_area_struct *vma,
> > return madvise_pageout(vma, prev, start, end);
> > case MADV_FREE:
> > case MADV_DONTNEED:
> > + case MADV_DONTNEED_LOCKED:
> > return madvise_dontneed_free(vma, prev, start, end, behavior);
> > case MADV_POPULATE_READ:
> > case MADV_POPULATE_WRITE:
> > @@ -1113,6 +1122,7 @@ madvise_behavior_valid(int behavior)
> > case MADV_REMOVE:
> > case MADV_WILLNEED:
> > case MADV_DONTNEED:
> > + case MADV_DONTNEED_LOCKED:
> > case MADV_FREE:
> > case MADV_COLD:
> > case MADV_PAGEOUT:
>
> Don’t you want to change madvise_need_mmap_write() as well and add
> MADV_DONTNEED_LOCKED there too?

You're absolutely right, thanks Nadav! It'd be fine, but more
expensive than necessary. Here is the fixlet:

diff --git a/mm/madvise.c b/mm/madvise.c
index 12dfa14bc985..7dbfcd6c955a 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -52,6 +52,7 @@ static int madvise_need_mmap_write(int behavior)
case MADV_REMOVE:
case MADV_WILLNEED:
case MADV_DONTNEED:
+ case MADV_DONTNEED_LOCKED:
case MADV_COLD:
case MADV_PAGEOUT:
case MADV_FREE: