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 66D403CD8C1 for ; Tue, 12 May 2026 21:07:45 +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=1778620066; cv=none; b=E17r3rvdRK3o1CuTKP8UreQqrEqYNFXr3yt+M6IIe3iAUIHqyx+Bm0+S1+XtgCKvNVPCTCrAsGNYkuSLeyOveeBV3pQHON0B4NyIfy0jwk+nOKUa1R3Wv0Iy+UY42jSAWjG9YDD+1uyptVPScMKqfJPW9b04zb/VZqPTgPyuYw8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620066; c=relaxed/simple; bh=wEvn415Fgtrq2ovu0Be2ECwe90TsK5RJeb5vnfFQo5w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QsaCj94lgrSHrHs4rj7uYoO/AsmWEFh9u62PkjynnCRxjwzu4GNm0H9kZ0P3a2RwT3O1Xe9fbeODa6TuqzUnBt09P4y/9fPsAIxM1E3BRqbQdDiUNRPBmYmhmGVSarjMsML6+rx4a8gSu6ayOpiFZkhDeXKUXZWYPwCTQ0NJf30= 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=EQBbSKYI; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Hu1QqZs/; 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="EQBbSKYI"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Hu1QqZs/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620064; 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=D/8VBBw0J+b0eTIG6c4Ba4jQebQb6vF38rsggt16jgI=; b=EQBbSKYIRlTYLLt0orvqFdxIiouldeEHTzspsOqicnJJuHkv8tGGwsPp9Q4FhwPb2wDBWe 5VgZGVKP3EQbqtVsGQTOx02L4mpsI8l5eal6Nj5dEvIHmEJAjN3u/g9P79M7nOWaXTA35C 7/OUZcUiHUd0CwpWPlpGdLoRmqSVQEA= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-152-Y5z566tKMrGsM8rvgrpGDg-1; Tue, 12 May 2026 17:07:43 -0400 X-MC-Unique: Y5z566tKMrGsM8rvgrpGDg-1 X-Mimecast-MFC-AGG-ID: Y5z566tKMrGsM8rvgrpGDg_1778620062 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-43ff19e54beso4180702f8f.2 for ; Tue, 12 May 2026 14:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620062; x=1779224862; 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=D/8VBBw0J+b0eTIG6c4Ba4jQebQb6vF38rsggt16jgI=; b=Hu1QqZs/9IAa7ZPfjqAZgBYfzc3fJ73RfdQOQu74X2BFPhfTKErJEDoPhhT8rUPEaE 2zhd85plF7mtve4aGk5/wxXhaab6JnBIFEoSPY6GUQvYNwXXFoo/8Eh44VseycVy3T5E vNL515F5wcdJ1d13ML/aITlWz2BCulMgrvQiOi9LNCoxOFzJ8VPdoTgQgu7g88n6tV8w D98osWp9VCxyBvFBm5SifOy+5LUNyFM46hLphYkCp3iUXmjCX6qxTWNr/qu96ccN4+Zr le5onf31nd7e33XiOQ8fLJsgdzz9mnHwV75tUzLs09U9FwbmpjlLdDH8SA7yIp3FNJaU ll6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620062; x=1779224862; 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=D/8VBBw0J+b0eTIG6c4Ba4jQebQb6vF38rsggt16jgI=; b=ey1jp1VCGy7RA2nX4sW3x8kkIC+LFlMzG1CnR0yfGyw1bfAKR/YOowyhIk/io3xytZ XtHddm2QBQrh1DIK2KuIbqnapnEjkqFdcYm1M8LeE6b9lsc1SjB3IWpHzwl+/bNJSJ2s 9kECL7/2UP4l/0LJGV41p9kxS6lQdja+bb5ktdOqJyE2O0uFyrV/yX+A+jF545lHJGf8 +sNpAR5fDbUi/gevS+UK6RrDyZ/33AFCEK/lb5qqt4pHD9aOIyMAjCgRaPkznJ6TH2Gb n5bQ07QyJkSKR8sm5Wr1QscbaIj9efK0hWKrKZZmqzdshLNzaMIOsPNcyqh6G+p5FWig pyrQ== X-Gm-Message-State: AOJu0Yw1tV1U2ZGIgo+jMT4KZXI0u9ulh8CsiVy4JgmoJ4edrs3O4WqB xcyLdedBRQp5jyjrpyMW6Cm6iPV35v3uL9EazT3zQ5ylZ03qD6Sy3gg2eziHAiqqQsKdehxvneY r5xHCFkhW3FW91B16JAvrzDGlPZbntcrMco7sC1AnZXhjvErCV7hHkzMqtaq4n0N0gFDcO7cmm5 HK4cIx5wiKY0V5Vj/bYGTFDvdnG0SSVz/e2SBkcx5QGQo= X-Gm-Gg: Acq92OERBjpULIRZ4Zh7Ljg2WlrdAQ6Mh/XfyYnfAHqQQJ7GVRig9gkVgr79ONp1beq bQexhyFT+/gkAILIHDyTnEXwVqxv+DWKnWrWUxZbMwSunpFox95Vmlu+tJNFfzAH0nznr8jPTMp z0KlxVYwRwhAQRtSt6XKAyn84EoQQnxqgNKtVNd9dW4AY7fYYGsyuhR7L3NIxoUgleozDZGSAJF YtUk2PKZDb4VpNatiBgfRxIyXoOXThziNrEhAhE+lP69vhJ7kd9ALfsghDiY9DWoHSog9hu85hG CGwsxFamiObzUwPAt8GnbpruSivoi+G5SQRNQ8oEXngogQW3AFBg77xb3Ds0WxP+GQ86BTDFKIe TvfQlQdkLhI23bXL5mQCdL1Y8pa2WUMxWJ0ilW6CV X-Received: by 2002:a05:6000:2384:b0:43d:71f4:7ed5 with SMTP id ffacd0b85a97d-45c58698080mr544151f8f.17.1778620061459; Tue, 12 May 2026 14:07:41 -0700 (PDT) X-Received: by 2002:a05:6000:2384:b0:43d:71f4:7ed5 with SMTP id ffacd0b85a97d-45c58698080mr544054f8f.17.1778620060883; Tue, 12 May 2026 14:07:40 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4548e6a66bfsm30848344f8f.4.2026.05.12.14.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:40 -0700 (PDT) Date: Tue, 12 May 2026 17:07:36 -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 v7 28/31] mm: add free_frozen_pages_zeroed Message-ID: 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 | 21 ++++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index ee35c5367abc..e0d5743de68d 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 ce43f5a3dbaa..8eebe01cda80 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) @@ -1596,8 +1603,11 @@ 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)) { + if (fpi_flags & FPI_ZEROED) + __SetPageZeroed(page); free_one_page(zone, page, pfn, order, fpi_flags); + } } void __meminit __free_pages_core(struct page *page, unsigned int order, @@ -3000,6 +3010,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 @@ -3038,6 +3051,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