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 224D0426ED3 for ; Fri, 29 May 2026 15:24:37 +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=1780068281; cv=none; b=pB30PH5UuDzyY2gJauxBYqG8HjtXMk0Numl7KylbkLMA1034enu5oIinvNZTm9fcqYM+uzY+LaTKP5lUDXIamzNaAEM+RTVPdpxtdE2ras/9+MqJj8dE42THpsCH0z3CheW637KJcL1MK+eVeJBR4vsRR1ppXBE023Bd9Nci0Yg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780068281; c=relaxed/simple; bh=c6xJpyp5zpjmRc9jnwYRt4nCMF1SinUlHasxCFwTPkI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iuNTwidtTN5+5o8PycBWE07qubx7bUw28F74qQHbSs+1o6UUS/6IJhSANVlrMVLSYg5K4Y0Hj9wxndQTkg1hE1EMIhNtdhgSJ9NSLSkiUBUNQxhFm6DtKqhTGzwQfZOSzCWnCpjRFGLyLNIDFyYx5irApEIWjNmjBQRSjvbhUF4= 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=hfvNjctb; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=CJjg1iwJ; 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="hfvNjctb"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="CJjg1iwJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780068276; 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=qdOI4mS59hNGv2oV9kd67xyAhp7b5Wts0l8Olu5Azv0=; b=hfvNjctbYxLYHahl6/MCCHR/3J0VLEB6LHLJf8QO7BvNbifne87s10XGiupjI3Og//LIPh +3JfG1O4LlFmCPZEZXott8qWegFs3SnF0ySmH0HpMXytYgtNOmF+HMlYsAJ5G2VxzupRpK 88khCjw5LhkxxeJ+Fo1Amm3IunMy2ck= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-w15L5dgtOWa8KrFFBuB9_w-1; Fri, 29 May 2026 11:24:35 -0400 X-MC-Unique: w15L5dgtOWa8KrFFBuB9_w-1 X-Mimecast-MFC-AGG-ID: w15L5dgtOWa8KrFFBuB9_w_1780068274 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4903dcb32f8so69898845e9.0 for ; Fri, 29 May 2026 08:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780068274; x=1780673074; 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=qdOI4mS59hNGv2oV9kd67xyAhp7b5Wts0l8Olu5Azv0=; b=CJjg1iwJzGxHtocFKWJfrPey4g3o44lSdJUSgvYPVUYXCk0zbiYgDSCGIpwF9hSM4r knoSoB6bdu+q8dkI7q8JP++FroKqZ3pMCaM4/1jPU3DQeB7QGq3IaLSGwyFwhEKJlL9B ivyHpi1coc2DhRQzCkgoMlfQzmyI/t9KPw6dHjZ0eOd/Z0FTx50wwDcb5BKweM617v3k rIB7vwLewUnHaE7vGsXZ8KyM3ORHJfxANNDI9BY6wiS/qN6U8E2XIF1IxI2Uixtyhv2P LICRN9518Hj4qGt4WHanPKzS74vcV1sPwTetmMR/TwaNdx+JiCnguIEgakOTq1Mdzvwq AkTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780068274; x=1780673074; 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=qdOI4mS59hNGv2oV9kd67xyAhp7b5Wts0l8Olu5Azv0=; b=Qt/5MPONe027sGP0Tx1i8cMx+pvBtKPwBGdnHQluXdoRcJ+nPqOxKxMCA42MLVxFPr FzFVF/Wq7EOmKl7vqe9UFV4eRT4xDipVpcpkMBGZqqjyVkN65CmgeGxoqlUcnpicNuUr IkJ7w3DzVKacOhaTrBJOIraZOy78NIChUhRvONtEAgc8bOkMZoPyIa8PLxDDwq7tXdXp GQ9no1XpwxeP1alIuCk0MAmkr8lzxutqou8MSljRDSAklfPwkQa/8OozGH2g/va+Bp1C yLMtoybojWJF1ZPzYaiZyRfqFQqUGxT8QYsOHNWk6rT6Z1Ei+xe4gDn+HhBtcBIJO3Sn NGow== X-Gm-Message-State: AOJu0YxLXytEfV9CAX8aUbA6GVlutWWWSKveEJ1Zkz64uQAhX6I1fsGU bjsBgfRNlxPXS1N6T/bSyuc2LaxyJNRTLY4HcRfzUbb0t0je5LbiBNxi+2mLNSruGEwnCoLopKO Q7zb3IiZwMxuJFrBuK70SUHS+ggU6Q1DLcalvhZt8eiKBNdIUThGEASeoC0W4AyLkcKc89uXs+b /YEgKpz9+EG7uhqy1JDhv/VSsXq1CmfeAsmHF8X0kRBxY= X-Gm-Gg: Acq92OEY5TA84b05VQwA0qVZb2IVKiw6ceu5e71/kd/EUafINwTlOPtAY7czigfn7cX sqPiDBOtJAgETKPOu2o6nneb7nXdHD2tZD09oaa2paVUMX/gt0B4yJ95OZmre36+Lnr/UeCdHK3 LF3Tg33X8VbBrWuPx7CRNNwxpXMrIe0KwkfEiR3yNeLf6F0yUV1XyyEMDIBfppAaBGwAWeHecpQ D8DUK4gOzkKqPNZD0teUj4AL1El/ZwquUptxT+356f6loyul342oOeSmE0+ppE1u67VaMPYjcCf zKCGdgAq0L7jUp0XyDG4MM/XamJIENByd95z4g9YxhgtnNZ+OR/SEKy+nfv9Zvmx57H1EkQIntP wVITSPOj/GGdP4nKOOXgdtb4tdlP4iPaAlZDTifSxWBF92rctYDOkdA== X-Received: by 2002:a05:600c:1988:b0:490:845e:3a6 with SMTP id 5b1f17b1804b1-490a295013bmr1065755e9.25.1780068274096; Fri, 29 May 2026 08:24:34 -0700 (PDT) X-Received: by 2002:a05:600c:1988:b0:490:845e:3a6 with SMTP id 5b1f17b1804b1-490a295013bmr1064315e9.25.1780068273271; Fri, 29 May 2026 08:24:33 -0700 (PDT) Received: from redhat.com (IGLD-80-230-25-45.inter.net.il. [80.230.25.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef34a0674sm3959493f8f.8.2026.05.29.08.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 08:24:32 -0700 (PDT) Date: Fri, 29 May 2026 11:24:28 -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 v9 25/37] 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 Reviewed-by: Gregory Price Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/page-flags.h | 1 + mm/page_alloc.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 4ee64134acc3..ff0b192b38e5 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -680,6 +680,7 @@ FOLIO_FLAG_FALSE(idle) * uses this to skip redundant zeroing in post_alloc_hook(). */ __PAGEFLAG(Zeroed, zeroed, PF_NO_COMPOUND) +CLEARPAGEFLAG(Zeroed, zeroed, PF_NO_COMPOUND) #define __PG_ZEROED (1UL << PG_zeroed) /* diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 4cb7e779a6c5..ff614e422eec 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