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 2BAA33BE17C for ; Mon, 11 May 2026 09:03:45 +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=1778490227; cv=none; b=rz4GWj3twGH83qHKUgu9zZ+VjYNJVwaC8m54hQ/p3B/edM9zSXfJgLqhcXWOF/Y+C3caBDpAi58FtzHu8bp6sfj9117qBBJjnekN7EiEZGt/ZNyXP0pq0hXKarYI7+IM0zlCUkVgBZyLx6woUbEzr4b//VHTyix0mmb4HCShqCQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490227; c=relaxed/simple; bh=2qwfIvYMP4MobFXYMZ9IfggvCGLyS5KNS+zvJpAn5WA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=D235O4oSehMV9RSxJ+redeKpiPC3pgKMV1V3HmylFL9iDTLr25/oPvCm8q/PQa5SizjbJ7o52Q2OlFixzKDkOfSUKWP34i/YimguHs/b2q+kAp1Byq0g3SqZBYbTWinglaks4isXAzV2w5gsqi4xGBaeuLNyxKikpv66hSFfD4E= 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=HZqg5Eg4; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=tVWtFTKW; 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="HZqg5Eg4"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="tVWtFTKW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490225; 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=aIsDJpt3h7ld/REGYicPHvXqVXWObeKhcjO9DGpcUJs=; b=HZqg5Eg4/tLEHdNhhGBl05uNKVD3mTL4npZUAfvTmpv8y03M0XcNpz+WLMhSI5sSH41miN 2vYJ+q/tsIOhHEgafXk1OqKFuOayiQDgcagyErD5uj0dY/5k6jwkOsFOoy40V4Vxne6W6u PrW98LjErz+uK+/ksBibvXSU91aKdl0= 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-347-f3VToZjxMfaa_lTBTEswZw-1; Mon, 11 May 2026 05:03:43 -0400 X-MC-Unique: f3VToZjxMfaa_lTBTEswZw-1 X-Mimecast-MFC-AGG-ID: f3VToZjxMfaa_lTBTEswZw_1778490222 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48d1b294dfeso38016335e9.0 for ; Mon, 11 May 2026 02:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490222; x=1779095022; 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=aIsDJpt3h7ld/REGYicPHvXqVXWObeKhcjO9DGpcUJs=; b=tVWtFTKWwvnmHxSvw/TMTtyz5v60CaxNsZzpjz3wS74RnmHrL+5mSRbahW9/5USd/s TtUq/1PytkP0gOTvMhEdTIe9JJDVWsb8l7MBenBe74lRfkgzN7kjnySAuFFbVB2QVjT/ 2q58EWCuIVoVSJldStj6XCsSJgrVVva5gvRxsrmTGWm2EiB/01T1tFS5Njo46njpLLjm 8vc3PBbHdYspPVBGR+3URqd+u4VX7tfciSWA1c4lGvu9iPHwxpTNhISLCZnPYXVa/lIe qdX/RxlyErGobqwdOrt3GIswahgfnx/+jxPi1rYig2lc7ZJrL5WsIVVaKW6V25HEMjoV AoRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490222; x=1779095022; 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=aIsDJpt3h7ld/REGYicPHvXqVXWObeKhcjO9DGpcUJs=; b=j2F30EkYhI9DfjO/nzxMab2gk/5JLf62eC0y8q02uggIte4dS8wA3eLzQZQYwT4EzZ a+DZBpFUncsn9kB0LLMhF4hmekrqxSoYleCAf4D1gsJVKwiXeiozKoaYTS6C5rrVjYdj BAHDHTeEtAWABrYOwKqYAfX/Jsx+klS4u0icf4Rj7SvSSiHaH8Qgt613eVOztW1OwVzM dVqKAkei2CUVnDQt4rB8eXa3pLjFzt10pvVi26lQzAQAZyWbTO/ajgHTlrY2TX9h8yQk VJ/qWhchCBWm+/S3b0V+aH//7GVteMnUxXlw2DfvfO/UPJrAW1Z6Fs7gfhFi0GRYJD/k 7Ocg== X-Gm-Message-State: AOJu0YwFc9neqld5YcIxqGUC1IwvWQ0zfmBxIIntJr54Hwz9JXRO+mZg Gog5c+5D/hqVzjOACC/ZT70tPKz7fgJ4yX1IXYQoiQzJz8NGYy644WZbIX7DfTOjbGnC0l8zllp Q9NRJ/Esr0rR8nLYhEh1FzAiEZjTrG4Q3/ZWlWGUcWfcGwLqpOKtEF1ihn28sA6OeOqx+DM5WBS CG9AMt2jxS+At0/HvEh9txQ34ritSwZDd0XzkG7sbos0E= X-Gm-Gg: Acq92OHrMeCka7jgDJ0wHZhA/xY0ttLX0v19L+sMfxlMm0Snm0m46OS9HhQSOfEgCSt mCQPjdQgHkCv6KwbFIaCcJfsD5h2MBc3lbWHMMdunGCyEJuUOkckxBo+q4uwVz0RjzozJFkQMjk rNsXzOl03w3Hsw+vY47FnGNKUAfT0dGGDXgUSbkfeHWBvb1RdVM1jO8YG4/K1d6DV57FtFyxSiD KRibN5E9YM68lhHkDp3PvFc4vfVwb1IAxe3H8n2GCSvWWofcCKYf/D8pbMf79B06n8o4Ed++F1u 9nuI3kHwOthHzrkC/3PVSFQhUWvQ8lZOzwT7w9SQ9f917Zn9k6UhVJjXDJtLP801veWAWzWCxUf py9dZdldWBX2vtoGdVqpZ8BZ5b4b/rAPE3vSOsra1 X-Received: by 2002:a05:600c:6299:b0:489:1c32:210d with SMTP id 5b1f17b1804b1-48e706f120fmr146717885e9.15.1778490221636; Mon, 11 May 2026 02:03:41 -0700 (PDT) X-Received: by 2002:a05:600c:6299:b0:489:1c32:210d with SMTP id 5b1f17b1804b1-48e706f120fmr146716725e9.15.1778490220928; Mon, 11 May 2026 02:03: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 5b1f17b1804b1-48e6fffb9bdsm160295555e9.1.2026.05.11.02.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:40 -0700 (PDT) Date: Mon, 11 May 2026 05:03:35 -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 resend v6 20/30] 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. The merged page would inherit PG_zeroed, and a later __GFP_ZERO allocation would skip zeroing stale data in the non-zero half. 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 bd3b909cacdf..d70c9ba6b329 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -940,10 +940,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); @@ -978,6 +982,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. @@ -996,10 +1002,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