Re: [PATCH] mm: madvise: MADV_DONTNEED_LOCKED

From: Nadav Amit
Date: Thu Mar 03 2022 - 16:36:03 EST




> 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?