On 03.03.22 22:47, Johannes Weiner wrote: > On Thu, Mar 03, 2022 at 04:29:56PM -0500, Johannes Weiner 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. Indeed, there are. I'd have use for that in QEMU for virtio-mem (which uses MADV_POPULATE_WRITE+MADV_DONTNEED to dynamically allocate/discard memory in a sparse memory mapping to be used by the VM, currently doesn't support mlock for obvious reasons). Further, QEMU postcopy live migration handling requires an munlockall() before registering the uffd handler and discarding all RAM via MADV_DONTNEED. Once postcopy finished, we have to mlock() again. I didn't check if there would be more stopping uffd from working on a mlocked region, but this would be one piece of the puzzle I guess. -- Thanks, David / dhildenb