From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BF053B7B8B for ; Mon, 8 Jun 2026 08:38:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907933; cv=none; b=F1QBFvE1f5Nwzl8QoxYiL0K1ino1SQoklIGbnf8mOeNvSI93y2qJrGg8SYpf/3FCESzNLLsBlLtJ13ahS2rKEo/JC46pU6lQ6TmQI3+3pN0s7Uo2PN42rN9hoCu5tDa/u+k/pRjKMXDUFe7pl7I1nzyuy2Hu0oFE1qsuWLkCiSw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907933; c=relaxed/simple; bh=XOxo/dtWeCKwLWC3rRtMtJbaGbjkk6GuaLkok0aBtBs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LOCO4f68qAggBHW7ghVwB7ZT1WnxG4LrevgvcvEwTPzr7shzQiq2eGcXUxnz2gAzUS5WzmvxBtDRiWollquLkyfwX8VsUaS30BWXAxNGZ3CEUmOPjrM5vWYZlSNmuj4M3IIomqsJTx6O4Wxhn7mVABqhGaXqh9wDpFdzs73JKFQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DlTapet2; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Urlpb5/2; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DlTapet2"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Urlpb5/2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780907929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1lvfH8Mz6BNBeGQvvcXVuozV5D9pusYvRbrmVhIfIf0=; b=DlTapet2T4ktiww2FSwxG+lE4KDjZIcaI4onjkGmuFPZWex1/xziDRMfmcplF7OvBOiwWC JxEsGtsQPVaNQBh8r61ys2VGLKBFvoEoUerImHnAt+jf9xvb2kC29uQJAp9LF8DNaeplHC 819B45EDsamu6FNS5ZmjsG62aaaFj3o= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-138-_Zy8ioxuO_ehsQ7hgBFV9A-1; Mon, 08 Jun 2026 04:38:47 -0400 X-MC-Unique: _Zy8ioxuO_ehsQ7hgBFV9A-1 X-Mimecast-MFC-AGG-ID: _Zy8ioxuO_ehsQ7hgBFV9A_1780907926 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-490ace40f13so18300575e9.3 for ; Mon, 08 Jun 2026 01:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780907926; x=1781512726; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1lvfH8Mz6BNBeGQvvcXVuozV5D9pusYvRbrmVhIfIf0=; b=Urlpb5/28rLuJcG8oBKSQPGzpKDKu+h2dCAY842GtiMjYWqDMigKGiqf8GdktvW7yw N1AytAJnsi6UU5klFh3n21cjHonMuR6sMcS8+0Q13r0Rbn/+o6vQD4cwqOiaTCCFOMnF DIK7KAc+dUR3iKJTZn0OX5afKJ/jqBWnTiMTAdXQqsir5BXmmI4BR+M9duLbWrHo6Th1 F7X94CpW7JK2/h5aDh3dKVF4g3zbiBnaI4qPI4fa9ONOxLe4LXCrAnaGD5oF4wvsdxFE 19oN1BtuCiQsVJODyrG7AltYqTv/kIXg3VYvGw0xk//yx8M2BzsxoydhMY277KF6Uas3 dzZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780907926; x=1781512726; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1lvfH8Mz6BNBeGQvvcXVuozV5D9pusYvRbrmVhIfIf0=; b=YZ5sjDrf0HtotmLRGhCYjDn/INFcUvvZikcqkcjjWwHeTlwR+IQRASar0aMWAorIYq WhWDyoI0WMOa++/RNnkeDUARMdZ3y1msj6RlRqqCli5RMhinyR0wIGn3xO0bde00/S+A w8/raGRudon5730LI7mUZbSJZvClxABEtrPwQ7ZF1diirIsb0oGitvpjcw1a7xVi/8cQ 716V016TuwEA2ujsS+QyugyC6n+mtzYi4tr9io6SUee9ABgYnHmqVOXtxV6UrjosDH/c JRwNLCGkxdAgIJOI6yJAFJM1Hys5hW0bKGh8/xVwjuMkr+spMC42YlMZdNQ0/OiLmQdP pD8Q== X-Gm-Message-State: AOJu0YzNWKwaiWvlqV1AlNhjZE4Dh5jbHMp2VCuSrWtufn1lWp0grh+A W5ubTuaLigcshkK8U5qA13hD6Evf9Du8t4AXRnbhxQHUJQGPOUFmNoPHc+GUUlXui810ahxwQ8O S9Ea5HFJNWiD6TohY9Z5BRKl+UEzNRGES4Ph3KJLTeocbedPTAqUH6cD4W9CJFr5fcK0F8z8O0d gEmKc1QA/M3GzPJfanb136KwZz2WiEdmn+NPhB7B3fNMA= X-Gm-Gg: Acq92OFvxzkBXGj/tu/n/QsUL/r1wzKmit5BFzZF0Dgj4bClCsKP9U/MONT2d2okB10 Y8q3A1xirAZWwZDc/P15OZrso74zUGdBD3R0cL7eqB3qM8Z7eLkKsn9944sVVZBp6uMts93zcW6 dhpoWXMU3CgtEPT73rCeqlqwgb628sO3GJdUrtVlzFUM8XqGvTyvG8QTEYAx4X/j+skXboQLpbm DawiYfJZWPEpDBFAUZN/Dk8tXCflyiSP6hwPUx/udZ4P2Wd7klRB1uLUeCFJ94ncd+nbqkgX1hE JH+YlLyNqVMhaujD8BwfCHXSWvty/Gnk1b5s3XqLL/BC1Qk6hlG5OPVRG3ZFfcEshNIebFpy36c QqbCnTsiU2nwtTAhWojg74Nc= X-Received: by 2002:a05:600c:628c:b0:48f:e26a:1744 with SMTP id 5b1f17b1804b1-490c25a87f5mr237272785e9.9.1780907926368; Mon, 08 Jun 2026 01:38:46 -0700 (PDT) X-Received: by 2002:a05:600c:628c:b0:48f:e26a:1744 with SMTP id 5b1f17b1804b1-490c25a87f5mr237271745e9.9.1780907925906; Mon, 08 Jun 2026 01:38:45 -0700 (PDT) Received: from redhat.com ([31.152.37.159]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2eadefsm51854339f8f.11.2026.06.08.01.38.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 01:38:45 -0700 (PDT) Date: Mon, 8 Jun 2026 04:38:37 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , Muchun Song , Oscar Salvador , Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Hugh Dickins , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Axel Rasmussen , Yuanchu Xie , Wei Xu , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , virtualization@lists.linux.dev, linux-mm@kvack.org, Andrea Arcangeli Subject: [PATCH v10 22/37] mm: add free_frozen_pages_zeroed Message-ID: <4220116b4d91f3e933fa76ad473106c2e48fd452.1780906288.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.51.2.2891.g4157995a80.dirty X-Mutt-Fcc: =sent Add free_frozen_pages_zeroed(page, order) to free a frozen page while marking it as zeroed, so the next allocation can skip redundant zeroing. An FPI_ZEROED internal flag carries the hint through the free path. PageZeroed is set after __free_pages_prepare() clears all flags, so the hint survives on the free list. __SetPageZeroed is non-atomic but safe here: the page is frozen (refcount 0) and not yet on any free list. Note: when want_init_on_free() zeroes the page via kernel_init_pages(), the page is zero but the direct-map cache lines may be dirty. A later patch (skip kernel_init_pages for FPI_ZEROED) avoids the redundant re-zero, and post_alloc_hook handles the dcache flush for user pages on aliasing architectures. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- include/linux/gfp.h | 1 + mm/internal.h | 1 + mm/page_alloc.c | 23 ++++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 73109d4e31a4..d24b61e45861 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -384,6 +384,7 @@ __meminit void *alloc_pages_exact_nid_noprof(int nid, size_t size, gfp_t gfp_mas extern void __free_pages(struct page *page, unsigned int order); extern void free_pages_nolock(struct page *page, unsigned int order); extern void free_pages(unsigned long addr, unsigned int order); +void free_frozen_pages_zeroed(struct page *page, unsigned int order); #define __free_page(page) __free_pages((page), 0) #define free_page(addr) free_pages((addr), 0) diff --git a/mm/internal.h b/mm/internal.h index 4af5e72742ba..fd910743ddc3 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -938,6 +938,7 @@ struct page *__alloc_frozen_pages_noprof(gfp_t, unsigned int order, int nid, #define __alloc_frozen_pages(...) \ alloc_hooks(__alloc_frozen_pages_noprof(__VA_ARGS__)) void free_frozen_pages(struct page *page, unsigned int order); +void free_frozen_pages_zeroed(struct page *page, unsigned int order); void free_unref_folios(struct folio_batch *fbatch); #ifdef CONFIG_NUMA diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 21f9e92922f1..008f1a311c40 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -91,6 +91,13 @@ typedef int __bitwise fpi_t; /* Free the page without taking locks. Rely on trylock only. */ #define FPI_TRYLOCK ((__force fpi_t)BIT(2)) +/* + * The page contents are known to be zero (e.g., the host zeroed them + * during balloon deflate). Set PageZeroed after free so the next + * allocation can skip redundant zeroing. + */ +#define FPI_ZEROED ((__force fpi_t)BIT(3)) + /* prevent >1 _updater_ of zone percpu pageset ->high and ->batch fields */ static DEFINE_MUTEX(pcp_batch_high_lock); #define MIN_PERCPU_PAGELIST_HIGH_FRACTION (8) @@ -1596,8 +1603,12 @@ static void __free_pages_ok(struct page *page, unsigned int order, unsigned long pfn = page_to_pfn(page); struct zone *zone = page_zone(page); - if (__free_pages_prepare(page, order, fpi_flags)) + if (__free_pages_prepare(page, order, fpi_flags)) { + /* Don't mark zeroed if poison overwrote with 0xAA. */ + if ((fpi_flags & FPI_ZEROED) && !page_poisoning_enabled_static()) + __SetPageZeroed(page); free_one_page(zone, page, pfn, order, fpi_flags); + } } void __meminit __free_pages_core(struct page *page, unsigned int order, @@ -3020,6 +3031,10 @@ static void __free_frozen_pages(struct page *page, unsigned int order, if (!__free_pages_prepare(page, order, fpi_flags)) return; + /* Don't mark zeroed if poison overwrote with 0xAA. */ + if ((fpi_flags & FPI_ZEROED) && !page_poisoning_enabled_static()) + __SetPageZeroed(page); + /* * We only track unmovable, reclaimable and movable on pcp lists. * Place ISOLATE pages on the isolated list because they are being @@ -3058,6 +3073,12 @@ void free_frozen_pages(struct page *page, unsigned int order) __free_frozen_pages(page, order, FPI_NONE); } +void free_frozen_pages_zeroed(struct page *page, unsigned int order) +{ + __free_frozen_pages(page, order, FPI_ZEROED); +} +EXPORT_SYMBOL(free_frozen_pages_zeroed); + void free_frozen_pages_nolock(struct page *page, unsigned int order) { __free_frozen_pages(page, order, FPI_TRYLOCK); -- MST