Re: [PATCH] mm/memory: mark unshare copies dirty to fix MADV_FREE data loss
From: Daniel Wade
Date: Tue Nov 17 2026 - 05:06:26 EST
On Tue, 17 Nov 2026 09:55:24 +0100
"David Hildenbrand (Arm)" <david@xxxxxxxxxx> wrote:
> We should always prefer setting the pte dirty, not the folio, as the latter
> needs atomics.
Will do a v2 with your version, thanks.
> numa_maps does not show any such data. Did you mean smaps_rollup ?
It does, gather_stats() ors the pte bit with folio_test_dirty(). So I
kept it.
> A more future proof solution would be to only allow MADV_FREE if we are the
> exclusive folio owner, checked under folio lock.
Makes sense to me, it kills the whole class instead of one producer at a
time.
One thing though, that takes the folio lock on every folio. Right now a
clean exclusive one doesn't take it at all. If the lock is busy you skip
the folio, so jemalloc freeing a big range would leave some of it
behind.