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.133.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 40D363BB670 for ; Mon, 8 Jun 2026 08:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907978; cv=none; b=UwWvfvnNu14uzJ27J9R08uwN2KYTWDzyyqnUM/3GcLApGjZjaFh96EqgAS2VGSL49bN6EfLtICRGHHxVFeBqevNk0DAGyi/gBFSERyQK97+/+QqsTgMXfU4uYJRWT71siwVyd/25Ng/tYQeRLsId1d5UXU35YErYxwvbGZ0p+xE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907978; c=relaxed/simple; bh=GbupeTEyC1nYpB3GHTrtS/PPh02DP7xvsmjmQMrjGAg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cuAi+/sjrOrk95+kVU3j/4O+sp1onHhrKm5aY+eM68Ftyejh2gXLuNy2l59ToMSBoYlcOJJ8mhE5ZjUJEpeSb0UL+61lkAryQvPSi2gpcAFv7hGqSNV7R6hES+9893kstgejXTPPknr1RVthBn2tcLBalbxTIuRGandTGgM0Chk= 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=TIJWC3VL; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=jvfAhMD/; arc=none smtp.client-ip=170.10.133.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="TIJWC3VL"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="jvfAhMD/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780907974; 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=jfQ8iRnJTK4n0bEkv49q5EiiPzQx8wAqaRkFNFNqcuU=; b=TIJWC3VLZM8qcwWG4C2KOilwTP6jXoR7a6LQLP6kEqmW+LcZFcVh1dda8vwJn1S8S29fpq 1shnULKrVcqpFTt39FyvlNXFESqycUYKvvGrvzFg6IlPijLtCoRNzGBuZBNQtKIn3Kp3qE 5JRolpvsxEg42NcjzG7h6yVQmNIMzg8= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-100-nd3Oioq6McChcbhjb8W0AQ-1; Mon, 08 Jun 2026 04:39:27 -0400 X-MC-Unique: nd3Oioq6McChcbhjb8W0AQ-1 X-Mimecast-MFC-AGG-ID: nd3Oioq6McChcbhjb8W0AQ_1780907966 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-45ef6ad76bfso1301664f8f.0 for ; Mon, 08 Jun 2026 01:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780907966; x=1781512766; 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=jfQ8iRnJTK4n0bEkv49q5EiiPzQx8wAqaRkFNFNqcuU=; b=jvfAhMD/zLuaiid/6DseBcrGBfPbzF4MUIacpIYarJnpP9GJkvHIPfIfNbWsERCGaq LsHFUes5tXboit2jchkeDHQc/lJCp6N56I8EU2PqppW9uks4A/9ThvA7LaXY4+a+CCN2 zJgr/MPBvFACbM4oHfdVLAmZx3gDXHbnQazKfOHeYxUsfYhp67j13vm6exzqnfzM95I4 4SZYo8tisrC/77kQwuVGZkq2uXpX+yrSq8lEVnr0tOkVDNyQvmlfLY+mg+QntnIfwcJB WvxthgmD+En/HZUkDtIZndUB5tQdN60o4X+zWhzvhNk5BG8DzHixYKi8/TtP5SpS6ikE fSqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780907966; x=1781512766; 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=jfQ8iRnJTK4n0bEkv49q5EiiPzQx8wAqaRkFNFNqcuU=; b=XLp6Tie1nPcYPp24r0JUC0MJtZL/Vy0L7bPsofMrP/HQhjyI5H7wW65EoMBK8Us6eP z/lbG9VOFxMY/hV/IkfPTzslosvfUY9D4kzd7VBGHTICRdAiFLLSRyCT4xDUWUW9nfNX FfVAvBYmW/OFA46ENc32SXhuDFhlYA2mJ4i+Gm3YexcOG3KfaO3OkfMvZKUX2LiAX0gS hwjEg3vvOOJ5x1R61LbWGGDy9C17NO94jN9IIYeSSjVcpUaklokLxU2qMYP92/pa1/a5 euHaISGQDzZ8u+HJaWZyj77K12HJoC36sSETeZNUTYoay02XQrtIvo0gsmhK7z/ZC0AM R53w== X-Gm-Message-State: AOJu0Yyz5BDkKjkielKWqgbIjP21/IEgAgBG1PvP2NUZxl3/rW0pkNob HBDpGExEyykRCtSbtFykxDhu8nZ9oQvD34/wGlML0M7OuUbb4UvJNaPZatKjoLOGnwpP2KZp7xr J15YNwm94e1sTL/g8oMsnEHUtY0aapxiJkm2Dj9IFYmYTHhS4ayqnMGCCw11ICcXueQSl+e3ijI zV95GhLbhuGoE/0iisf+GEsWbadWKPCl4zKi7SvotxvoI= X-Gm-Gg: Acq92OET4EU3UmFzIFWBb9PWKhwXoeVF6Ck0tJ0tEdCtGYme/8uUmIADFYMfw8qhQOd 2S97Aam3iEQt0i5+uAs3Cc7LFuHCfYO4ym4F5lV9Hm+uz9glRSRIOj5WQwdJ4QdwSfEIAfhpFQl BYKqwXqxnS6PtqTIC7jm22ibRMqakd6W6jPvac8E/w4m2uVUoTSJKMPWyzBWpkryKUTWxc52uRY Ct4HUWpemDuT+qs6uw4zIwQMaV4gH1Ga65NCu72BcZ5zxEHaI7Lqrm5WMcGgwrL7C1nyFtjT4Dx +/GInU6O1WhYgPYgrW33r8mctnzPZ1mwMK8ImWtgNhVn0VUZS/3S+2CoDSi117NvDnc8relr8wt 3SbU1zQ5mvJABh8kZMT+DqH8= X-Received: by 2002:a05:600c:8b70:b0:490:ae94:a7e6 with SMTP id 5b1f17b1804b1-490c25c20e0mr225777375e9.24.1780907966289; Mon, 08 Jun 2026 01:39:26 -0700 (PDT) X-Received: by 2002:a05:600c:8b70:b0:490:ae94:a7e6 with SMTP id 5b1f17b1804b1-490c25c20e0mr225776435e9.24.1780907965793; Mon, 08 Jun 2026 01:39:25 -0700 (PDT) Received: from redhat.com ([31.152.37.159]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490c2d30eeasm239643575e9.1.2026.06.08.01.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 01:39:25 -0700 (PDT) Date: Mon, 8 Jun 2026 04:39:18 -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 v10 27/37] mm: use __GFP_ZERO in vma_alloc_anon_folio_pmd Message-ID: <2ee827fed4765a155d2b56bb0e13d7ee5fc6dce8.1780906288.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.51.2.2891.g4157995a80.dirty X-Mutt-Fcc: =sent Convert vma_alloc_anon_folio_pmd() 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 folio_zero_user() 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. Signed-off-by: Michael S. Tsirkin Reviewed-by: Gregory Price Assisted-by: Claude:claude-opus-4-6 --- mm/huge_memory.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d689e6491ddb..0dec3c717ff2 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1333,7 +1333,7 @@ EXPORT_SYMBOL_GPL(thp_get_unmapped_area); static struct folio *vma_alloc_anon_folio_pmd(struct vm_area_struct *vma, unsigned long addr) { - gfp_t gfp = vma_thp_gfp_mask(vma); + gfp_t gfp = vma_thp_gfp_mask(vma) | __GFP_ZERO; const int order = HPAGE_PMD_ORDER; struct folio *folio; @@ -1347,7 +1347,7 @@ static struct folio *vma_alloc_anon_folio_pmd(struct vm_area_struct *vma, VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); if (mem_cgroup_charge(folio, vma->vm_mm, gfp)) { - folio_put(folio); + folio_put_zeroed(folio); count_vm_event(THP_FAULT_FALLBACK); count_vm_event(THP_FAULT_FALLBACK_CHARGE); count_mthp_stat(order, MTHP_STAT_ANON_FAULT_FALLBACK); @@ -1356,17 +1356,9 @@ static struct folio *vma_alloc_anon_folio_pmd(struct vm_area_struct *vma, } 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, addr); /* * The memory barrier inside __folio_mark_uptodate makes sure that - * folio_zero_user writes become visible before the set_pmd_at() + * page zeroing becomes visible before the set_pmd_at() * write. */ __folio_mark_uptodate(folio); -- MST