Re: [PATCH v7 13/16] mm: memory: support clearing page ranges
From: David Hildenbrand
Date: Tue Sep 23 2025 - 04:14:24 EST
On 17.09.25 23:44, Andrew Morton wrote:
On Wed, 17 Sep 2025 08:24:15 -0700 Ankur Arora <ankur.a.arora@xxxxxxxxxx> wrote:
Change folio_zero_user() to clear contiguous page ranges instead of
clearing using the current page-at-a-time approach. Exposing the largest
feasible length can be useful in enabling processors to optimize based
on extent.
This patch is something which MM developers might care to take a closer
look at.
I took a look at various revisions of this series, I'm only lagging behind on reviewing the latest series :)
However, clearing in large chunks can have two problems:
- cache locality when clearing small folios (< MAX_ORDER_NR_PAGES)
(larger folios don't have any expectation of cache locality).
- preemption latency when clearing large folios.
Handle the first by splitting the clearing in three parts: the
faulting page and its immediate locality, its left and right
regions; with the local neighbourhood cleared last.
Has this optimization been shown to be beneficial?
If so, are you able to share some measurements?
If not, maybe it should be removed?
...
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -7021,40 +7021,80 @@ static inline int process_huge_page(
return 0;
}
-static void clear_gigantic_page(struct folio *folio, unsigned long addr_hint,
- unsigned int nr_pages)
+/*
+ * Clear contiguous pages chunking them up when running under
+ * non-preemptible models.
+ */
+static void clear_contig_highpages(struct page *page, unsigned long addr,
+ unsigned int npages)
Called "_highpages" because it wraps clear_user_highpages(). It really
should be called clear_contig_user_highpages() ;) (Not serious)
You have a point there, though :)
Fortunately this is only an internal helper.
--
Cheers
David / dhildenb