Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/memory: convert details->even_cows into details->skip_cows

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.

Link: https://lkml.kernel.org/r/20260227200848.114019-10-david@kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Arve <arve@android.com>
Cc: "Borislav Petkov (AMD)" <bp@alien8.de>
Cc: Carlos Llamas <cmllamas@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Daniel Borkman <daniel@iogearbox.net>
Cc: Dave Airlie <airlied@gmail.com>
Cc: David Ahern <dsahern@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Dimitri Sivanich <dimitri.sivanich@hpe.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jakub Kacinski <kuba@kernel.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Janosch Frank <frankja@linux.ibm.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Namhyung kim <namhyung@kernel.org>
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Todd Kjos <tkjos@android.com>
Cc: Tvrtko Ursulin <tursulin@ursulin.net>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand (Arm) and committed by
Andrew Morton
a97bc13d b6c0384a

+7 -8
+1 -1
include/linux/mm.h
··· 2767 2767 */ 2768 2768 struct zap_details { 2769 2769 struct folio *single_folio; /* Locked folio to be unmapped */ 2770 - bool even_cows; /* Zap COWed private pages too? */ 2770 + bool skip_cows; /* Do not zap COWed private pages */ 2771 2771 bool reclaim_pt; /* Need reclaim page tables? */ 2772 2772 zap_flags_t zap_flags; /* Extra flags for zapping */ 2773 2773 };
-1
mm/madvise.c
··· 853 853 struct madvise_behavior_range *range = &madv_behavior->range; 854 854 struct zap_details details = { 855 855 .reclaim_pt = true, 856 - .even_cows = true, 857 856 }; 858 857 859 858 zap_page_range_single_batched(
+6 -6
mm/memory.c
··· 1554 1554 static inline bool should_zap_cows(struct zap_details *details) 1555 1555 { 1556 1556 /* By default, zap all pages */ 1557 - if (!details || details->reclaim_pt) 1557 + if (!details) 1558 1558 return true; 1559 1559 1560 + VM_WARN_ON_ONCE(details->skip_cows && details->reclaim_pt); 1561 + 1560 1562 /* Or, we zap COWed pages only if the caller wants to */ 1561 - return details->even_cows; 1563 + return !details->skip_cows; 1562 1564 } 1563 1565 1564 1566 /* Decides whether we should zap this folio with the folio pointer specified */ ··· 2151 2149 struct mmu_notifier_range range; 2152 2150 struct zap_details details = { 2153 2151 .zap_flags = ZAP_FLAG_DROP_MARKER | ZAP_FLAG_UNMAP, 2154 - /* Careful - we need to zap private pages too! */ 2155 - .even_cows = true, 2156 2152 }; 2157 2153 2158 2154 vma = unmap->first; ··· 4282 4282 first_index = folio->index; 4283 4283 last_index = folio_next_index(folio) - 1; 4284 4284 4285 - details.even_cows = false; 4285 + details.skip_cows = true; 4286 4286 details.single_folio = folio; 4287 4287 details.zap_flags = ZAP_FLAG_DROP_MARKER; 4288 4288 ··· 4312 4312 pgoff_t first_index = start; 4313 4313 pgoff_t last_index = start + nr - 1; 4314 4314 4315 - details.even_cows = even_cows; 4315 + details.skip_cows = !even_cows; 4316 4316 if (last_index < first_index) 4317 4317 last_index = ULONG_MAX; 4318 4318