Re: [RFC PATCH v1 0/4] mm: port MADV_VOLATILE and MADV_NONVOLATILE to v7.3-rc1

From
Liam R. Howlett <liam@infradead.org>
Date
2026-12-04 16:34:07
Also in
cgroups, linux-arch, linux-fsdevel, linux-mm, linux-trace-kernel, lkml
Reply to
Lorenzo Stoakes (ARM), 2026-11-30
On 26/11/30 06:18PM, Lorenzo Stoakes (ARM) wrote:
On Mon, Nov 30, 2026 at 11:39:45AM +0100, David Hildenbrand (Arm) wrote:
quoted
On 11/30/26 09:34, Hirotaka Yamagata wrote:

Hi,
quoted
This RFC series revives and modernizes the volatile ranges patchset
originally proposed by John Stultz and Minchan Kim [1].

Volatile ranges allow userspace caches holding regenerable data (such as
decoded image bitmaps or other private caches) to mark private anonymous
memory as safe for the kernel to discard under memory pressure,
bypassing swap. Such ranges are marked via madvise(MADV_VOLATILE).
Before reusing the buffer, userspace calls madvise(MADV_NONVOLATILE),
which unmarks the range and returns 1 if any pages in the range were
purged while volatile (or 0 if all pages remained intact).
We have MAP_DROPPABLE nowadays, I don't think we want more of that.
Yes exactly.
MAP_DROPPABLE is fundamentally different than what they are trying to
accomplish.  They want to be able to mark something as recoverable from
the userspaces side of things after the mapping exists.

MAP_DROPPABLE is permanent for the whole vma with no notification to the
userspace application that it happened, MADV_VOLATILE would be for a
section at any time.  On reading it sees zeros vs a SIGBUS.
And also absolutely no to this pattern of:

1. Create an unnecessary new file for something
2. Redirect an MADV_xxx to that file, maybe some hooks
3. ???
4. the control of what the MADV_xxx does sits outside of madvise now.
yes to all of that, plus..

There's a race as noted by the bot.

It holds the anon_vma interval tree lock which would be a problem
for forked processes (affecting COW users too, I think?)

Checks up front, but not all of them?
quoted
quoted
Unlike MADV_FREE, which silently zero-fills dropped pages on re-access,
calling MADV_NONVOLATILE before reuse gives userspace deterministic
notification of whether cached data was lost without having to touch
every page.
We do have userfaultfd missing faults + rwp (read-write-protection). Can't we
build something based on that instead?

We currently disable uffd with MAP_DROPPABLE, but maybe there could be a use
case for it. Of course, you can also build it based on MADV_FREE instead.
Well we'd need to have a compelling reason to combine the two I think :P

But in general agree with - check to see what tooling there is already before
making a big, invasive change to mm.
This would work, probably.  Since this is the second time this has been
suggested, it seems like a pattern to spend some time on.

MADV_FREE will allow you to see either someone trying to write to the
area or faulting it in, which seems to fit the usecase.  The only
missing piece is that uffd can notify you that you have lost data that
you are in the process of using - That data that you just reconstructed?
We wiped that.

That is, MADV_UNFREE does not exist - You cannot say that you're not
done with something that you thought you were done with.

You might be able to do it this way:
register uffd for missing faults
MADV_FREE
before use MADV_POPULATE_WRITE (-efault == reconstruct it)
UFFDIO_COPY and populate.

This does work, but it's not ideal.  Really, I think to use this
meaningfully how they intend, we need an MADV_UNFREE mirror call.  You
call MADV_UNFREE to set the mappings as stable, then check your local
tracking if you have to recover what was wiped.  Local side is kept up
to date by UFFD.

The dropping will probably happen faster than what they wanted here but
it's a lot less complex.  I'm not really sure how this would benchmark
compared to the scheme they're proposing.

If performance is important (when isn't it?), then you may want to
concentrate you efforts at the code paths of uffd and falling back to
the mmap read lock vs the per-vma locking.  It has been a while, but not
long enough, since I ventured into uffd.

Thanks,
Liam
Thread (9 messages) 9 messages, 4 authors, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help