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.129.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 411E23F23B7 for ; Wed, 20 May 2026 22:23:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315808; cv=none; b=ZsPtv6Q1YWgnjG5a1tLqnoUqyQnLuTcKZpPDbQfepXk2gqlWesEmN/Ac6gvdt3loHa3Kc0DAOIQFyywYPSasc8GWbT4vIcXal40bZdo7CjHI1Mc5IpfSSmguYHXyQ9EB/VIFFeRfHfVcwqNP6u0aEFKdXaOyqQkm/3bww7p82gA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315808; c=relaxed/simple; bh=6Lm0/uxEF7Jrx82xgvKLV/wotxiG6uz9abF+ckORdaA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aUpMvEDtQNuiAYmCCmjS53UJItzQYeKPTTxohsyyvogDGqWxgikJz/2i+eIyIq24HD3/U2ZEzaHlxFA4gI0hakshFIINuapgMWFUzK2IQAbL6zStQE/72c+Y4zIOLgXZq3ck2CiEkpinry7GvCY4h0iDBg3rL6bidj0+Gl3RX0Y= 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=VGHak+2D; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=MXRvYr3e; arc=none smtp.client-ip=170.10.129.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="VGHak+2D"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="MXRvYr3e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779315806; 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=4vz+PjXrtbljoW8SfvrGsI8KrTf/iN/5SV/3uQ1i74A=; b=VGHak+2DCD3M5vDUfGSi+2F3C7AXMXT9QzBSZxzKVEkUEAQHq5HobX9BsGRH5MRpBCRQz7 89Ixg0pwr+o9ZKRWGMq27VcbS46SWlksIWfKgmieJENY4/W3R0JVhh1xYd0tUHsesJ/35f n5sbYMyaMBkiKN7KFkGL/E6SSX5lIoU= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-271-WhKWmYhFNSubsq1l7BIt-g-1; Wed, 20 May 2026 18:23:24 -0400 X-MC-Unique: WhKWmYhFNSubsq1l7BIt-g-1 X-Mimecast-MFC-AGG-ID: WhKWmYhFNSubsq1l7BIt-g_1779315804 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-45dbbbf8d57so7164226f8f.3 for ; Wed, 20 May 2026 15:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1779315804; x=1779920604; 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=4vz+PjXrtbljoW8SfvrGsI8KrTf/iN/5SV/3uQ1i74A=; b=MXRvYr3eDlVjGR/cX/q6ofLTGz/Iypc1s4CCXqv7aqZ9wMWajlV596kDItbTwstT7K PxxRMfEVmf8S9ZOONtJKvLpEyfrxhpI4vA4nS1NF5qAaTIw23Khqki8kuTBHbYYwoD2v YpmxdtIb6IzUqrAF/q9OeySiV7/ZKJc/c4jNawnflzxpjvxIGqyExlWUvuYFQOk0i+hJ KJSyHU0+RBRqLETHmHf+gkyTw9i4L2VIQnjJOXPlkKsQApDrx1Vb7m6IZaXkcl+IFrqm Nqt/PUB0TKszIB84BQO1N20g1pE3Uwurx1t4rArOusUrDZAn7uRIhK3T2tiZmBWQLA6G Jv3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779315804; x=1779920604; 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=4vz+PjXrtbljoW8SfvrGsI8KrTf/iN/5SV/3uQ1i74A=; b=VjP4o25KNB3sJtkFS1F+Wt2p6v8tlh5IJX0Gg9CFMsMoRFBgAEpPHGBTzWb9GKCYxb 48kwW4B8vygwpmghhCHCmk9jyxGdE6OtJ+jmOkSTZY23IWeCUTZB9xD70I02nVTKTX9/ EvLQ+e/LpMxWWto1JCmsQ8kQzhhwbkOm+Yh0r+hKsCgoMKJRqsFlSq46MpmJUADdaRcP WgZ6oOBNhSnJg5cpHzsFUgQ8sKi44tnkJSlYtWMe8caK4JlKI9UCQ3JspqosshhFXIFg WPFtkzqBDaULq2u+GDtmkUzqRasFiFKCxhRMXH1XSWHDFBeR8E+zUSDdwiiF1FPUQslN HmhQ== X-Gm-Message-State: AOJu0YzYoTtartmsXL0frxISCFPegYTuGsDh5449Z3WbAOYPZZRO89WB p0QOxqD0r8x2069tnjkavpNPo3MbBh5yB49jl31nQlLE7s9XjbSSn4mI82tlpukzeUdeaZ9xV+I jxxntXOuB8lv9RKBAGJsEdAZP2vrJDhpJ3SijAW9AiK4Tki6F7v/oSq/UwmEcs2Uq7YecFKTLJ4 tbsiOyuY9EpfmqPy2lEp157MkOiXQJE95oxrlupxDRWqY= X-Gm-Gg: Acq92OEp3vuQ4XsbQhr19+sEewuW3JQ9d8AF60kPKGa5Ghsg+OAvsZGB4pksEP4J/mF Zt+p9K/sY3xD6LyHpNH0PsYJYZrlai4IraUtp5lf1BKFP8Re05WWXMj4K41o42bpePvLWPYugrD WwBs9kXeNspcGyp7ZliazKo+l7iW69ThjsB3VSuti3ENFpdo/wip0sUmqe1Rf3mdlKBBSfniFjv Tqfw0D6+QV74eUHxsa2LNGqMyCBLC64Cy/8fmiR2ZoOdl+WNpKmKyzoyzFxdXN+UkJwCrDlvIx7 N3mq1/LS1fJ9tb8TqPMyrkMTgX0L33h7kkWpvDX4BRSDLrjk6qjy+ZVIdZHN3b1QLCRHNwImWYm TePAOpHN+IBeJeOngDOmPbbkeyWCWPsVh6njGiY6vtGo= X-Received: by 2002:a05:6000:2089:b0:43d:73de:abd2 with SMTP id ffacd0b85a97d-45ea3ae8801mr287906f8f.26.1779315803561; Wed, 20 May 2026 15:23:23 -0700 (PDT) X-Received: by 2002:a05:6000:2089:b0:43d:73de:abd2 with SMTP id ffacd0b85a97d-45ea3ae8801mr287814f8f.26.1779315802825; Wed, 20 May 2026 15:23:22 -0700 (PDT) Received: from redhat.com (IGLD-80-230-25-45.inter.net.il. [80.230.25.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45d9ed2ffdfsm53030712f8f.15.2026.05.20.15.23.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 15:23:22 -0700 (PDT) Date: Wed, 20 May 2026 18:23:18 -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 v8 33/37] mm: add free_frozen_pages_zeroed Message-ID: <321e9f1a5a15a80dfb25a9b8aa76657ce27b2b2d.1779315441.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.27.0.106.g8ac3dc51b1 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. 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 | 29 ++++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) 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 fd910743ddc3..4af5e72742ba 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -938,7 +938,6 @@ 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 702fa2ced1e1..399e2038dcd9 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -90,6 +90,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) @@ -1599,8 +1606,19 @@ 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)) { + /* + * Only mark as zeroed if the page is actually still zero. + * kernel_poison_pages() overwrites with PAGE_POISON (0xAA) + * when CONFIG_PAGE_POISONING is enabled. With init_on_free, + * kernel_init_pages() re-zeroes after poisoning, so the + * page is still zero. + */ + if ((fpi_flags & FPI_ZEROED) && + (!page_poisoning_enabled_static() || want_init_on_free())) + __SetPageZeroed(page); free_one_page(zone, page, pfn, order, fpi_flags); + } } void __meminit __free_pages_core(struct page *page, unsigned int order, @@ -3021,6 +3039,9 @@ static void __free_frozen_pages(struct page *page, unsigned int order, if (!__free_pages_prepare(page, order, fpi_flags)) return; + if (fpi_flags & FPI_ZEROED) + __SetPageZeroed(page); + /* * We only track unmovable, reclaimable and movable on pcp lists. * Place ISOLATE pages on the isolated list because they are being @@ -3059,6 +3080,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