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 B7292261B70 for ; Sun, 26 Apr 2026 21:48:25 +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=1777240107; cv=none; b=R/vZmZbzJvF/hvUKozWhPc9PyJQVjdbCbESM+c7UWZl7l5Zcb2y5ivzhKTDxTBhdX/tMrY8BpaqE7rbhxh6NXkg6XS1r86dPhtbedFcdQ6cfmlhDEQlxcDde/vqgONr9uXdKMhkA60woqlw8FaCXQ1sCpnYMml2AdzQQzwnsUxE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777240107; c=relaxed/simple; bh=GQIxt3426GlDeqT1vnTp0KvfVXzR4vpnMpFfUxs113g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hfTkx4gy9kKn4g9Ze8jqYTomZrPQ//zcUHxZsXLRnXeqmYHAjNBpDMUpCnAyRaBAUTMq/V+Tx0qKiQTajad2wOBF8yWKFst07HTK/Jn6JaBqG6QQy2kRUxsqrRoDC5iMzKo129iGflriDoHRnlhUS0TZHVbZ7P1ocGElLfJanb4= 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=WC3Cw5uB; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=dEL1bdtK; 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="WC3Cw5uB"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="dEL1bdtK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777240104; 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=iX7QlDEIRvMq/lhdobB75J6k8cJUQBTaq/dVJzKRSYI=; b=WC3Cw5uBo3HFGVPImiwsIktgHhwArlKdGK5QT+D6y7ogEu7XY+OwZJK/lsesFnTVqSyOHL mqGFpwlfehXy8qEMwKvT+A7oZZmqL32hlKmB6TBTLvGPKExpfbrpAV+t2r8V9PhcxIFO7H HUiTr8oYx/65LSAzybHNbysxO7lCefc= 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-391-jc7XGKDaNLe1SNGigepoJA-1; Sun, 26 Apr 2026 17:48:23 -0400 X-MC-Unique: jc7XGKDaNLe1SNGigepoJA-1 X-Mimecast-MFC-AGG-ID: jc7XGKDaNLe1SNGigepoJA_1777240103 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4411a215f17so5934004f8f.1 for ; Sun, 26 Apr 2026 14:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1777240102; x=1777844902; 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=iX7QlDEIRvMq/lhdobB75J6k8cJUQBTaq/dVJzKRSYI=; b=dEL1bdtKYVAuagDpkX9IzYvbwk3W1NeKPbSakSQvDJsoutMVmVWazSPdjCTr36/c2P qOuigJkTvcjV8XQ/ZpkLDkjxx601fcZNTmg5258oZTrePdaAv9wz4DAain4ba8mfQXY0 iehw07Ot/PDCeX6ZXWSAw1m2hF2k0vKCEDbOqZu/IbU4e5HKuxVe6gl8M7Pd2Bi+YcUX z0gVJc5jNrNXx7BeBeHxkfarN5LGfBauMyrJ7MB5/A7WducZwD/UecTxMUkfX7t3uZA+ fvGgeT3PtlaefP0nV7blvBu2OI3RUNhY+QRqFv2UwwRjABbunlO7y2VMOTm1y5v3tNB7 x2mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777240102; x=1777844902; 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=iX7QlDEIRvMq/lhdobB75J6k8cJUQBTaq/dVJzKRSYI=; b=POtkoA8CIMMtRdRrsgYdzwQdsVKB+xtW6yAQdyRhgRXXsJbGHFZ1CSW88RIwN4R/Fo k5BRyGURHVhcyTyNhwTPq9JD8UVCm0aZZbU701RSwEkQPgbXcn3e+6GVSlJ76EQy/sdU EWNqTPxGjWg+QVOfS2HXIxhjSqtdAy3tt+YHZnDXu5Lh/1gc1ymWj+BL96QinIXYT+Uq VJYiHXpH5Dbq6BPuRSoQ7ksk5nIHHZ/V8HcY8Tp/qOgjypkwzYw/7JigRMSst7rd4mMO riZRFFc7Rg4WFLMaWktzyid3sdKGl4lCZbgrNKib0PTP1r8qGEMfTBcIKyco+wfxVZTL LE8A== X-Gm-Message-State: AOJu0Yw6Ahu9LnMaV2k5Tpvo6+ArAwj3R4OgiCJnDhrAnEtZlgttTkVb oZN0M9+9cOwWToc0PY4sKP6vTkTm/BIpFKS+YqqDC2ac1dzZpQaXFoI+olhxoiLiEavY5t8ELSm ZL5KZVj5+s9ULAr/rDRzK+c32n8RQt6jnHykHQkt4mThkDayBjZR+pIOR2qL0JziQTys/73200N jZQHZcRAT1KTpvT9QTbeolVtHOpt/VpvZpvLKG0dbxc6k= X-Gm-Gg: AeBDiesVpF3GRy5cTZG8MC5diRNRg9xPHsET/Y/HToUDssDgAAZyFivxzzzu0airrgY EBM2Fd0w6slg1n/3TQ2Gs+nVU9bPAjT3Vwv7SKuE5RT/9pl1P91rGN0T0bgJPrlcClsP7bj793W VNkn7MKZIOIVyH/PFMWqSgpx9Wm5Hl/VVMJg23R2dfVhTUNMPJkeL5Kufp1YjTjXNYqG8aJwWMf hyvD8UuKhFjvgbQRmosxWFlJvCgiUbUCPs6oJoe2X8h3pz8povkSo4BHMC3ipWt4X+dJ+KC4luO QE57A6/QuP2IjJ519Mjf6Z19oDPSUoZ+eMboYtn4l1QhCjOznHQEp0KIVG0J+zMqOC5RWKxUo19 fNBL8ehOhO1fun7cLH5VjWyPFaSpxWtMN+bBOrqb+oE0R50dbhYylZ8UB X-Received: by 2002:a05:6000:420a:b0:43c:4810:dc4a with SMTP id ffacd0b85a97d-43fe3e14f81mr62740571f8f.38.1777240102289; Sun, 26 Apr 2026 14:48:22 -0700 (PDT) X-Received: by 2002:a05:6000:420a:b0:43c:4810:dc4a with SMTP id ffacd0b85a97d-43fe3e14f81mr62740532f8f.38.1777240101794; Sun, 26 Apr 2026 14:48:21 -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 ffacd0b85a97d-43fe4cc0f31sm76656472f8f.12.2026.04.26.14.48.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2026 14:48:21 -0700 (PDT) Date: Sun, 26 Apr 2026 17:48:19 -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 v4 15/22] mm: page_alloc: clear PG_zeroed on buddy merge if not both zero 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 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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index eff01a819744..1183ef3e91c9 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -984,10 +984,14 @@ 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)); - VM_BUG_ON_PAGE(page->flags.f & PAGE_FLAGS_CHECK_AT_PREP, page); + /* PG_zeroed (aliased to PG_private) is valid on free-list pages */ + VM_BUG_ON_PAGE(page->flags.f & + (PAGE_FLAGS_CHECK_AT_PREP & ~__PG_ZEROED), page); VM_BUG_ON(migratetype == -1); VM_BUG_ON_PAGE(pfn & ((1 << order) - 1), page); @@ -1022,6 +1026,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. @@ -1040,10 +1046,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