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 11CAE307494 for ; Sun, 26 Apr 2026 21:48:39 +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=1777240121; cv=none; b=aRzfxGd+9p66a2/RxxYTF8OLRYlziMxkNLNX9hxD/qaUEbfRUN3Pzgg32yplwQ3hDjvsTbYUG/xXdz4R5VyjQiuiyKe0HdYGiz735eRnePoiWiQkdpVwsHxrwFhh9RM4pl9mDmxSW+j0B4HRCOffx1Q/G9cL2/MqnMyfJcSydk0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777240121; c=relaxed/simple; bh=QLA2RGwCxgyfX1bS6CbrL8hgVv2A/s1slaGKecTu3qE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KKdKTiqTRt0ij75TKNP+/6XW/re5y4g4bC5OOTwTu7gic4WybebhITkZh88WnAztzbVbWQ+hk8qsr8Pbm0IGSU0+ZtZ5Qiv9C5oJTEVUCI+jaO+ef0e0gLnDx4MReOFrxxgekcTvSxF/O69wFiRuxqDBWmcj3G8IeFZcyqHMXkM= 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=LLKhO/74; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=QEuk6L29; 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="LLKhO/74"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="QEuk6L29" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777240119; 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=ym5bn+CWMcoek2qBVqBOry4vxURkIsMQd8yhmA+BaCk=; b=LLKhO/74o7jPDiLRI4pUlkAp8ImF9MEeho5nrcDaSsegDnkHWrxbci++NN/0AEJ3KNJzuY 7OWnGgvePQgJlw8BC/LOhJztUUt16ZQkD1TRAVru9Lw8Bn/FHb45vqxnFQqcFPsAqemnEG arrV3B6ZKX7wHIB+JTDrSsQFlSbO+pI= 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-668-527_0QK0OcCTqYxcLJMOaQ-1; Sun, 26 Apr 2026 17:48:38 -0400 X-MC-Unique: 527_0QK0OcCTqYxcLJMOaQ-1 X-Mimecast-MFC-AGG-ID: 527_0QK0OcCTqYxcLJMOaQ_1777240117 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-488ba2f4094so57573505e9.1 for ; Sun, 26 Apr 2026 14:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1777240116; x=1777844916; 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=ym5bn+CWMcoek2qBVqBOry4vxURkIsMQd8yhmA+BaCk=; b=QEuk6L291av7zMgazUMYK0n1VT17Gc2frbG9gfqamlvKhhAYIIgq3bYRml7JB/OQNc fqI3fS8NGy0R17XPRMx/FRgG4WBH6cnhLMeoodf420IcpcsHx/HmiBSZMGbTHo+RlfFk rfkuzQRLIPNytVUWVEEUa0yhgmpjbb+ztLmHoQIT0a3Ep2qOxInpRVbCtmOPNX1BV2l6 NMZBSA1OfwtLIY0EnC3rzrAcztivKgR6y+awH12HcOoWrIzRoifVWvrFa6sum4c9t8cS vQ+O5FHfnlmhu6GkaQ3dod+zPYYk/ASWYzzuwr+SKMmAuSvEjWpwK07YfKQ2Uy1T1mDn xlCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777240116; x=1777844916; 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=ym5bn+CWMcoek2qBVqBOry4vxURkIsMQd8yhmA+BaCk=; b=BBpuzEeP52DuDSA1z1xkh5pEE1OIAfuHfOZDo3ysyaeog0yah+iyBRT4L08coDQxt8 Eeb+0aW4c2slqZrqFvzfogzEijhw3bJVHmKLwjBltk3VQKZhz3LrhyCdtAckwbY445eM EPC4FWc68osw5U+tNq/gLpmxuhpd2ZEztB+XDHeKdK9v3zagsMEXpDfdAydhBa1WJERb F1tBsyz4wwYi141pMbVfINd06RMw+Wc4j1LrtlyVnjwFqaOxCgEoh9xUxONgDw9eltKO RFme+bQcrJNEgvoMTuNneGRaOWNDgogUS/x8VnCTB2td3OHt4JPZKPkuquTMcwLUnBHa 6qSQ== X-Gm-Message-State: AOJu0YwIrRiLtS/bQ5cxUhq7NC4Qe0cFUWDq2+bToySxEwybTLZtE+bb V5d2HWdBnbY0zH0FREZ6w9+SARxmNGPUMAu/ovA+8clI236r+6cJeTl+/0/5/bk4DOQlo3Oy8Vw p0wJVyw+0hWHwx3UU7sqTmuPUSl0EXKOQ8ECNWNoY1ORR72tUP6hK8lLO/U5EndS8ozkGSULkDw tvVo61Rl10gnUtRXsYPwcfxmIG/EOut9Z5faTnLniIie4= X-Gm-Gg: AeBDies4j2+uRQRS60D/gxye3w2KruQr29wHSVhjCcBH3kB7nj90jK0CiOZmF513Okg UPqIV6mw0W1xQlj5Q8qxoeilMItJEh3Ka8/NU6BKWFHdmCNb6s/RSjq2LXMeLCRsi0AlNXIxOku YVVbvwrd2H2H5Bs9VNmy2q3YcSAm8FVw/1omdarIJCToxNXXZSf8gxS0OrAM9FuzpKo0psi0Rbx CUnwCS5IbHoqzQjQ3CI7oJN/48NIN7LyHTrUKj3THW9ORPa00+VUygI3CKiBWWxXVAw0TVNrVmt nqkbmRWSCAur4HO8j1WB3f+xJQg31Qni3e5uUR4ruoj4i4CW0TMh9PjU6AeYxXqTqdxVRmk7kwN xk9r4YOC0ZdLjIP9+EzaItSCHkBPs+NTQ6b1x0zkC5tV38brsSP1IZUuI X-Received: by 2002:a05:600c:c085:b0:488:c530:48a0 with SMTP id 5b1f17b1804b1-488fb784843mr454260285e9.24.1777240116501; Sun, 26 Apr 2026 14:48:36 -0700 (PDT) X-Received: by 2002:a05:600c:c085:b0:488:c530:48a0 with SMTP id 5b1f17b1804b1-488fb784843mr454259925e9.24.1777240116042; Sun, 26 Apr 2026 14:48:36 -0700 (PDT) Received: from redhat.com (IGLD-80-230-47-179.inter.net.il. [80.230.47.179]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-489201cde98sm505689585e9.7.2026.04.26.14.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2026 14:48:35 -0700 (PDT) Date: Sun, 26 Apr 2026 17:48:33 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Andrew Morton , David Hildenbrand , Vlastimil Babka , Brendan Jackman , Michal Hocko , Suren Baghdasaryan , Jason Wang , Andrea Arcangeli , Gregory Price , linux-mm@kvack.org, virtualization@lists.linux.dev, Lorenzo Stoakes , "Liam R. Howlett" , Mike Rapoport , Johannes Weiner , Zi Yan Subject: [PATCH RFC v4 20/22] 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 e275cc80e19e..766b1c7f0731 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -394,6 +394,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 0600d824ba03..60b983872d51 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -899,7 +899,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 1169714406e7..981ddf3566b5 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) @@ -1624,8 +1631,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, @@ -3032,6 +3042,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 @@ -3070,6 +3083,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