Re: [PATCH] mm/madvise: swap in CoW'd MAP_PRIVATE-file mappings on MADV_WILLNEED

From: Lorenzo Stoakes (ARM)

Date: Mon Sep 07 2026 - 11:30:14 EST


On Mon, Sep 07, 2026 at 05:09:34PM +0200, Vlastimil Babka (SUSE) wrote:
> On 9/7/26 14:32, Lorenzo Stoakes (ARM) wrote:
> > On Sat, Sep 05, 2026 at 05:17:57PM -0700, Andrew Morton wrote:
> >> On Fri, 4 Sep 2026 17:01:37 +0100 "Lorenzo Stoakes (ARM)" <ljs@xxxxxxxxxx> wrote:
> >>
> >> > Andrew - could you swap the patch out in-place with below? Thanks!
> >> >
> >>
> >> np.
> >>
> >> > Currently MADV_WILLNEED treats file-backed and pure anonymous mappings
> >> > entirely separately - using POSIX_FADV_WILLNEED (equivalent of a readahead)
> >> > for the former and a tree walk and swap in to swap cache for the latter.
> >> >
> >> > MAP_PRIVATE-file backed mappings straddle the two and currently get treated
> >> > as if they were purely file-backed, meaning any swapped out private pages
> >> > remain swapped out.
> >> >
> >> > Resolve the issue by explicitly checking for CoW'd MAP_PRIVATE-file backed
> >> > mappings and performing both walks in this case.
> >> >
> >> > Since the logic checks for vma->anon_vma this means un-CoW'd
> >> > MAP_PRIVATE-file backed mappings retain only the single file walk.
> >> >
> >> > Reported-by: Mike Kaplinskiy <mike@xxxxxxxxx>
> >> > Closes: https://lore.kernel.org/all/CABeknB_S2XJSHFgnHdgnN0rjzHhH4oQJs_APq9fvxHztQ_pgiA@xxxxxxxxxxxxxx/
> >> > Signed-off-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
> >>
> >> The failure mode looks pretty obscure, so I'm thinking that no backport
> >> is needed.
> >
> > Well it's not even really a failure mode so much as a 'known limitation' :)
> > So yeah agreed.
>
> Yeah, as we know madvise() just an advice after all, the kernel is free to
> ignore it :)
>
> (MADV_DONTNEED and friends enter the chat)

Haha yeah, another brilliant footgun invented by the proud folks at kernel mm,
catch us next time with some prctl's and BPF APIs! ;)

>
> > --
> > Cheers, Lorenzo
>

--
Cheers, Lorenzo