Re: [PATCH RFC v2 11/18] mm: skip zeroing in vma_alloc_zeroed_movable_folio for pre-zeroed pages

David Hildenbrand (Arm)
2026-04-21T10:58:20Z

On 4/20/26 14:50, Michael S. Tsirkin wrote:
> Use vma_alloc_folio_hints() and check PGHINT_ZEROED to skip
> clear_user_highpage() when the page is already zeroed.
>
> On x86, vma_alloc_zeroed_movable_folio is overridden by a macro
> that uses __GFP_ZERO directly, so this change has no effect there.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> Assisted-by: Claude:claude-opus-4-6
> Assisted-by: cursor-agent:GPT-5.4-xhigh
> ---
> include/linux/highmem.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/highmem.h b/include/linux/highmem.h
> index af03db851a1d..8bb67772c1cb 100644
> --- a/include/linux/highmem.h
> +++ b/include/linux/highmem.h
> @@ -321,9 +321,11 @@ struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struct *vma,
> unsigned long vaddr)
> {
> struct folio *folio;
> + pghint_t hints;
>
> - folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vaddr);
> - if (folio && user_alloc_needs_zeroing())
> + folio = vma_alloc_folio_hints(GFP_HIGHUSER_MOVABLE, 0, vma, vaddr,
> + &hints);
> + if (folio && user_alloc_needs_zeroing() && !(hints & PGHINT_ZEROED))
> clear_user_highpage(&folio->page, vaddr);
>
> return folio;

For others reading along, the variant on your other branch:

diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index af03db851a1d9..ffa683f64f1d1 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -320,13 +320,8 @@ static inline
struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struct *vma,
unsigned long vaddr)
{
- struct folio *folio;
-
- folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vaddr);
- if (folio && user_alloc_needs_zeroing())
- clear_user_highpage(&folio->page, vaddr);
-
- return folio;
+ return vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO,
+ 0, vma, vaddr);
}
#endif

Looks like an extremely clean interface.

--
Cheers,

David