From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 C4995378833; Mon, 8 Jun 2026 12:29:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780921780; cv=none; b=bFEwnleQhn11U5kTu68DkrLOl5TULnKmInj0CS0rt3qBbVVuh9cCxU594UGPbuzqvO/22n0768PtWwCAvqjPuVZRSnPT+Fw39UURlbnjnvh1bFBzSL6RzRotLceNVGkoDi1L0Svwp7JnbE2nDl1zQmePjZmXOnXnnVP1TCaSQUM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780921780; c=relaxed/simple; bh=7JEKa4WyC9weyJC0qq2pKoPsQUrSHoBjAugj/XCXvpc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=knkHyUfEOQTuh+/ms2R+h1j6zelOGZp4IMTKlWkaSemlz97zqxUok8FpFIEojguQX906o2CS47zlFYH6rahVE5ASRpEBNK2joSAieCBNLzbBqcp8odRE9f8+kEMsqn8e0LwyZjrY8a8fP9lALPxVto/UniG93SSeljWj6UhhokI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gJomfNfj; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gJomfNfj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5A2B1F00893; Mon, 8 Jun 2026 12:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780921779; bh=rAUA5rzcwEowomF8bvC+wP4/eskLSjeaT0mDws2eabw=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=gJomfNfjHUXhpfXzIbWi9ZWTWmsfuKpfU1PN5tXQ9+wVWf/J0u5GwDYGvXpWIlJLl o0N5Lma90r++0YOHdXe4SBXQaxTq8P7MaieFdchHBWlEb3fuvtzrFk0GSCC0lPsYjy /spwzit17UxG8bDETTvG6Mm+C2ZqWV8t9ef8QUg3cZwujC3qcOEZaeQ2HkLIKFsQKC dCwMJ65PdahtJ8/5VI1bz/J4JdrVpbWYCe7LIkNjHbpAeJJHQto4wEZhQhi5FwuO2m q/Vf9HKa9Ls7GMplUEjCoK4+L8TLk9SoaxAHnZ5Dr1puE3DjxNj34OzQ81R4iNeZME c/yob3kPsmkMQ== Date: Mon, 8 Jun 2026 13:29:26 +0100 From: Lorenzo Stoakes To: "Michael S. Tsirkin" Cc: linux-kernel@vger.kernel.org, "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , Muchun Song , Oscar Salvador , Andrew Morton , "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: Re: [PATCH v10 25/37] mm: use __GFP_ZERO in alloc_anon_folio Message-ID: References: <13ed2aa6607d510bd8dc6d602e96626511ee4fee.1780906288.git.mst@redhat.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <13ed2aa6607d510bd8dc6d602e96626511ee4fee.1780906288.git.mst@redhat.com> On Mon, Jun 08, 2026 at 04:39:02AM -0400, Michael S. Tsirkin wrote: > Convert alloc_anon_folio() to pass __GFP_ZERO instead of zeroing > at the callsite. post_alloc_hook uses the fault address passed > through vma_alloc_folio for cache-friendly zeroing. > > Note: before this series, replacing clear_user_highpage() with > __GFP_ZERO was unsafe on cache-aliasing architectures because > __GFP_ZERO uses clear_page() without a dcache flush. With this > series, it is safe if the caller passes a valid user address > (not USER_ADDR_NONE) to vma_alloc_folio() etc., which delivers > it to post_alloc_hook() for the dcache flush via > folio_zero_user(). It is only unsafe if USER_ADDR_NONE is passed. > > Note: with __GFP_ZERO, the folio is zeroed before > mem_cgroup_charge(). If the charge fails, the zeroing work is > wasted. Previously zeroing was done after a successful charge. > This is inherent to moving zeroing into the allocator. > Charge failures are rare (only at cgroup limits). > > Use folio_put_zeroed() on charge failure so the zeroed hint > propagates to the buddy allocator, avoiding redundant re-zeroing > on the next allocation attempt. Is this even worth the effort? This is surely not a hotpath... > > Signed-off-by: Michael S. Tsirkin > Reviewed-by: Gregory Price > Assisted-by: Claude:claude-opus-4-6 > --- > mm/memory.c | 13 ++----------- > 1 file changed, 2 insertions(+), 11 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 6c14b90f558e..6d6a3e1a02c1 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -5265,25 +5265,16 @@ static struct folio *alloc_anon_folio(struct vm_fault *vmf) > goto fallback; > > /* Try allocating the highest of the remaining orders. */ > - gfp = vma_thp_gfp_mask(vma); > + gfp = vma_thp_gfp_mask(vma) | __GFP_ZERO; > while (orders) { > folio = vma_alloc_folio(gfp, order, vma, vmf->address); > if (folio) { > if (mem_cgroup_charge(folio, vma->vm_mm, gfp)) { > count_mthp_stat(order, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE); > - folio_put(folio); > + folio_put_zeroed(folio); You just allocated the folio as zeroed above, should PG_zeroed not be set thus making it unnecessary to add folio_put_zeroed()? > goto next; > } > folio_throttle_swaprate(folio, gfp); > - /* > - * When a folio is not zeroed during allocation > - * (__GFP_ZERO not used) or user folios require special > - * handling, folio_zero_user() is used to make sure > - * that the page corresponding to the faulting address > - * will be hot in the cache after zeroing. > - */ > - if (user_alloc_needs_zeroing()) > - folio_zero_user(folio, vmf->address); > return folio; > } > next: > -- > MST > Thanks, Lorenzo