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 C247D3A641A for ; Tue, 21 Apr 2026 22:02:14 +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=1776808936; cv=none; b=Ds95vDXi7KRGgIJYzmgXsDD6csHXNE8algM9BmgVfIRjxUUpZaI7B80vRPvvcZAjiROF7AhFA5e+Nskxvgq5bbUFDjova2ZROMUBGcUkc1or6adZYlG+y5FpIlQPe1XNZHEdVhVW5eVOgzqRfJFBItKOLOPk6sVOG1CDcf7ufpk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776808936; c=relaxed/simple; bh=qSEJ1Kijx5ZivGiuuv5dmsRR2ofsgHwqXpUDJzbMbi0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=r0QmstpX3p2n105tic3Oo8uFjBShJzCJNJQmUtIFgJRKQryA5y0FP/D5f0kUosLl+naZnpcNg6Q1t7TlP7Hqs1n/cJoelyDy6AedoMPv5bRjt3KkHkA2KLad78sF3G16DhittueLCzigCHf1P2rrfTkRBJUF7CmCm+mWK86iqPQ= 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=HSdB8Yve; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=uHSaOflW; 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="HSdB8Yve"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="uHSaOflW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776808934; 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=B71z8WI6bGkbALDtbCGicFiZB6WFkZ9HcNzSfAqdU04=; b=HSdB8Yvew7jUWPR+BNNxK/HpbNndT5kRPUkSJsLP8WaygL/nSkokgrReyDwF82L8GdpTcK WMQk7b0/MiFvcf0rbtEt9MMi8NyUh/OwcZ4LCdkh2p+jhY3ZAtk5rfWHSHeFsygfzzaPUn j2T55VwIzMWRUgm5JpMvmeJj57GRkdU= 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-671-XkYtm4nwM4WV0Q0-G5kgKA-1; Tue, 21 Apr 2026 18:02:12 -0400 X-MC-Unique: XkYtm4nwM4WV0Q0-G5kgKA-1 X-Mimecast-MFC-AGG-ID: XkYtm4nwM4WV0Q0-G5kgKA_1776808932 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48a5775d647so9448215e9.2 for ; Tue, 21 Apr 2026 15:02:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776808931; x=1777413731; 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=B71z8WI6bGkbALDtbCGicFiZB6WFkZ9HcNzSfAqdU04=; b=uHSaOflWSVZqCPD3BaW5c2MB6L+EMCH+PFHIEn/HEFApxJIvC7xFzbBaopYNpbKhto hP7dzyD5wRjtwV5i4gaL9rZg9xLU9gqNj/5i/Yx0exbMmQnj8B+zxcBox76cE6pwSfMv TlT7b6NvnHOce+UKvOXZl+nxLKf5VyLY76ifqHs0F9VgWwUHyRYrsFxVGqu04zd6q3QF 90xW1wKy8prxAgGm4DPt9SLnHFlxR9foFBl2SJay340rBP3UMm4kiv06ol2ZeljYfuVx 3/FzkKQqcIgSinVaecajBl0KPSwtVWShU4sdGp9Fqf5/pSnYS0cGRXblGsaHtafD4pNw Nz0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776808931; x=1777413731; 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=B71z8WI6bGkbALDtbCGicFiZB6WFkZ9HcNzSfAqdU04=; b=ONGOaz1acuZ3MgH5kP7YRy5WamBoK+PRa6Uv7FSH8AxXuNIyyl8RXwBacuK+iVkHyg gc8PqMG/2noxRzXO8ijCX3gZFjyMOjnjj1mkaaMuD1b8N5JD3fL3QiniOiUQs83uWoTX UM4sOcJXHeFesB3jCiPS1nuoZ8HLoorIWh2NX+aIL7V+lLpWHTAXRsp4DiK142sjYFNU g2UzupX3vo/sbhCBo9stxI91f7+9NRs2WoP5w7zrw+XCoalHMfxHZwPyPe1Usx72i/YZ ShnZJLHbEK8hl41iwBGLgH3cIkKabyeMfVDtfsg7LXAg1Uwo8bFwtQNYdVfKNDF0IyAg 5grw== X-Gm-Message-State: AOJu0YwR+/UFaIVZ4G296z6pXUaRln4h6B+ML9brzw9rhiaWo2Z3ZY+I XQx3WRemvJbDTsHypg6gPxecc6mmcZtUbH56VMrCHhDCD2G5SonQ+o8WYPvD9dNA3TL3/UPl4zf R+vMpMBPCqRj8JOMols5fIkvwb0firZSDYXnlGQ+w4bU8oVZ28d9K7rhdjWo8+UharULxCDA2W8 JaX3QfDzLOkWJrZhyoyNSNbxq1lhYnvf1WUMdjK+kNjfg= X-Gm-Gg: AeBDietWcEmHsI3dXlFKjJFFG14Et41k8JiM3aMxY0CnsiSbEdMdNxDKQ5jqfCNGF9H i1CwblZj3UFp+UdEG0xvXo0+ySbTz+baAdY19WCTXSgDpsoNxna+QglNFYyGs+dNRrCXEwt6zYL Bq15LJmHqgkqyZe6khM76Bud+oq53ET3mJnv7CEnfw60Af7CMDrA95VoCP8IEnufdAT33WZfnyc 1Lhsb5J3O6BzdkX+OSjSGdN1UkrTsZUVoRu7KfeJxEzXvRIj2u8g1743FR0HOXwXr6UGKkzccQN ebchPWiy+Hv5gwt8xDquOKaa/sDzsg//wZ8c4E3jb36eGUbEJC0yFVOYogs3uID0mGMuvPdxwWH P0BFFzo2sQqR/yGHS8tB+xqXwvTeBTEs3qCqEdHMT8qR8cQMaCu6VCA== X-Received: by 2002:a05:600c:4ec6:b0:489:1f98:71e3 with SMTP id 5b1f17b1804b1-4891f987487mr132175435e9.28.1776808931382; Tue, 21 Apr 2026 15:02:11 -0700 (PDT) X-Received: by 2002:a05:600c:4ec6:b0:489:1f98:71e3 with SMTP id 5b1f17b1804b1-4891f987487mr132175005e9.28.1776808930932; Tue, 21 Apr 2026 15:02:10 -0700 (PDT) Received: from redhat.com (IGLD-80-230-25-21.inter.net.il. [80.230.25.21]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4e4d525sm38750206f8f.31.2026.04.21.15.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2026 15:02:10 -0700 (PDT) Date: Tue, 21 Apr 2026 18:02:07 -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, Johannes Weiner , Zi Yan Subject: [PATCH RFC v3 17/19] mm: page_alloc: clear PG_zeroed on buddy merge if not both zero Message-ID: <6992d257f953733586275aa766add3195aa93770.1776808210.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 When two buddy pages merge in __free_one_page(), preserve PG_zeroed on the merged page only if both buddies have the flag set. Otherwise clear it. Without this, a zeroed page (freed via free_frozen_pages_zeroed from balloon deflate) could merge with a non-zero buddy. The merged page would inherit PG_zeroed, and a later __GFP_ZERO allocation would skip zeroing stale data in the non-zero half. The page reporting path is not affected: it sets PG_zeroed during allocation (page_del_and_expand), not on free list pages. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- mm/page_alloc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9311374bbd2d..122b49a6d435 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -991,6 +991,8 @@ static inline void __free_one_page(struct page *page, unsigned long buddy_pfn = 0; unsigned long combined_pfn; struct page *buddy; + bool buddy_zeroed; + bool page_zeroed; bool to_tail; VM_BUG_ON(!zone_is_initialized(zone)); @@ -1029,6 +1031,8 @@ static inline void __free_one_page(struct page *page, goto done_merging; } + buddy_zeroed = PageZeroed(buddy); + /* * Our buddy is free or it is CONFIG_DEBUG_PAGEALLOC guard page, * merge with it and move up one order. @@ -1047,10 +1051,17 @@ static inline void __free_one_page(struct page *page, change_pageblock_range(buddy, order, migratetype); } + page_zeroed = PageZeroed(page); + __ClearPageZeroed(page); + __ClearPageZeroed(buddy); + combined_pfn = buddy_pfn & pfn; page = page + (combined_pfn - pfn); pfn = combined_pfn; order++; + + if (page_zeroed && buddy_zeroed) + __SetPageZeroed(page); } done_merging: -- MST