[PATCH v11 4/7] mm: skip zeroing of pre-zeroed order-0 user pages
From: Michael S. Tsirkin
Date: Thu Nov 19 2026 - 07:03:03 EST
Skip initialization for order-0 PG_zeroed folios.
For the generic vma_alloc_zeroed_movable_folio(), skip clearing known-zero
contents and unpoison KMSAN metadata.
On x86, vma_alloc_zeroed_movable_folio() requests __GFP_ZERO, so check
PageZeroed() in post_alloc_hook() to cover that.
Signed-off-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
Assisted-by: LLM
---
include/linux/highmem.h | 8 ++++++--
mm/page_alloc.c | 5 ++++-
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 70bbe93b8d669..4abd2a0fd82f7 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -344,8 +344,12 @@ struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struct *vma,
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);
+ if (folio) {
+ if (folio_is_zeroed(folio))
+ kmsan_unpoison_memory(folio_address(folio), PAGE_SIZE);
+ else if (user_alloc_needs_zeroing())
+ clear_user_highpage(&folio->page, vaddr);
+ }
return folio;
}
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 927a288eb419b..c2cb2f66c1736 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1829,8 +1829,11 @@ inline void post_alloc_hook(struct page *page, unsigned int order,
gfp_t gfp_flags, unsigned int alloc_flags)
{
const bool zero_tags = gfp_flags & __GFP_ZEROTAGS;
+ /*
+ * Skip zeroing if already done. Sanitizer handling still needs to happen.
+ */
bool init = !want_init_on_free() && want_init_on_alloc(gfp_flags) &&
- !should_skip_init(gfp_flags);
+ !should_skip_init(gfp_flags) && !PageZeroed(page);
int i;
set_page_private(page, 0);
--
MST