On Fri, Feb 27, 2026 at 09:08:40PM +0100, David Hildenbrand (Arm) wrote:
> The current semantics are confusing: simply because someone specifies an
> empty zap_detail struct suddenly makes should_zap_cows() behave
> differently. The default should be to also zap CoW'ed anonymous pages.
>
> Really only unmap_mapping_pages() and friends want to skip zapping of
> these anon folios.
>
> So let's invert the meaning; turn the confusing "reclaim_pt" check that
> overrides other properties in should_zap_cows() into a safety check.
>
> Note that the only caller that sets reclaim_pt=true is
> madvise_dontneed_single_vma(), which wants to zap any pages.
>
> Signed-off-by: David Hildenbrand (Arm) <[email protected]>

This is another nice change. I have some tweak suggestions below, but past
experience suggests to me it's quite possible you do what I ask in subsequent
patches, will see :)

Anyway overall LGTM, so:

Reviewed-by: Lorenzo Stoakes (Oracle) <[email protected]>

> ---
>  include/linux/mm.h |  2 +-
>  mm/madvise.c       |  1 -
>  mm/memory.c        | 12 ++++++------
>  3 files changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index d3ef586ee1c0..21b67c203e62 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2798,7 +2798,7 @@ extern void pagefault_out_of_memory(void);
>   */
>  struct zap_details {
>       struct folio *single_folio;     /* Locked folio to be unmapped */
> -     bool even_cows;                 /* Zap COWed private pages too? */
> +     bool skip_cows;                 /* Do not zap COWed private pages */
>       bool reclaim_pt;                /* Need reclaim page tables? */
>       zap_flags_t zap_flags;          /* Extra flags for zapping */
>  };
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 557a360f7919..b51f216934f3 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -853,7 +853,6 @@ static long madvise_dontneed_single_vma(struct 
> madvise_behavior *madv_behavior)
>       struct madvise_behavior_range *range = &madv_behavior->range;
>       struct zap_details details = {
>               .reclaim_pt = true,
> -             .even_cows = true,
>       };
>
>       zap_page_range_single_batched(
> diff --git a/mm/memory.c b/mm/memory.c
> index fdcd2abf29c2..7d7c24c6917c 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1554,11 +1554,13 @@ copy_page_range(struct vm_area_struct *dst_vma, 
> struct vm_area_struct *src_vma)
>  static inline bool should_zap_cows(struct zap_details *details)

Not sure if you fix up later, but we should probably change this function to
should_skip_cows() to keep everything consistent, otherwise this is a bit weird
and confusing.

>  {
>       /* By default, zap all pages */
> -     if (!details || details->reclaim_pt)
> +     if (!details)
>               return true;
>
> +     VM_WARN_ON_ONCE(details->skip_cows && details->reclaim_pt);
> +
>       /* Or, we zap COWed pages only if the caller wants to */
> -     return details->even_cows;
> +     return !details->skip_cows;
>  }
>
>  /* Decides whether we should zap this folio with the folio pointer specified 
> */
> @@ -2149,8 +2151,6 @@ void unmap_vmas(struct mmu_gather *tlb, struct 
> unmap_desc *unmap)
>       struct mmu_notifier_range range;
>       struct zap_details details = {
>               .zap_flags = ZAP_FLAG_DROP_MARKER | ZAP_FLAG_UNMAP,
> -             /* Careful - we need to zap private pages too! */
> -             .even_cows = true,
>       };
>
>       vma = unmap->first;
> @@ -4282,7 +4282,7 @@ void unmap_mapping_folio(struct folio *folio)
>       first_index = folio->index;
>       last_index = folio_next_index(folio) - 1;
>
> -     details.even_cows = false;
> +     details.skip_cows = true;
>       details.single_folio = folio;
>       details.zap_flags = ZAP_FLAG_DROP_MARKER;
>
> @@ -4312,7 +4312,7 @@ void unmap_mapping_pages(struct address_space *mapping, 
> pgoff_t start,
>       pgoff_t first_index = start;
>       pgoff_t last_index = start + nr - 1;
>
> -     details.even_cows = even_cows;
> +     details.skip_cows = !even_cows;

Not sure if you clean up later, but seems sensible to cascade the change into
the local boolean here.

>       if (last_index < first_index)
>               last_index = ULONG_MAX;
>
> --
> 2.43.0
>

Reply via email to