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 40FAF3C3459 for ; Wed, 20 May 2026 22:22:15 +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=1779315736; cv=none; b=lms4t6Rmj1+U0NXWK9bTUvW+rXKOFvdrBTH87LitqQypA4nu4osBtJrRCmLyoHR+Eu0JbLIdn1bgrGOIJQd6fZUEK0gmSeHzfmeYr7ImyrjhOXmJTlJXodYrWSkvSyYdLhRtJd/S9URy7oeYPPQZ7+/Mt/Hh3Nf6l6YHc5I3IyA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315736; c=relaxed/simple; bh=+9Q5fGlUrZYlSCWgLoOvdSgXnGUe3WMtEgfY+DGuKBc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=c5tl1VgwXn0qf5O/E4eGXi0rr7yMi1y2MGpDt98MVbFOSQYNSWPnVc4MVLAOAnc8P5dcqN0AL9eV0N0GF6nf/C3efNpMACbs1YMbMn5BgISPxwHS1sjp75kzZ85WAeVKgiyOC65Fx4bQj6rJJT1LoMTusM04n4YhUemE/J9baf4= 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=gcZ2T4AC; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=OrSjq0xZ; 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="gcZ2T4AC"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="OrSjq0xZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779315734; 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=dwGlO3yG5EtH2T+AQMoYdXPNyVEDsUWFS+ozJXrj1vA=; b=gcZ2T4ACk2BL8KCO2q7IvGLy6+4O/uAfZ8JANfTpayir5/H5Op7cbFrkrge8LlPSsSpyg5 LEwHsaFOILu5ow8XcxMEuZrdF7XCLdn5+pEQaIa8LCuZgZ2lbnca1qZzCd+gk/xFYA9VQS 6HpasHKHN1Krn2jX010QkGUK7G7UPgE= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-UgdR6rqaMkKHs9j_McQXVQ-1; Wed, 20 May 2026 18:22:13 -0400 X-MC-Unique: UgdR6rqaMkKHs9j_McQXVQ-1 X-Mimecast-MFC-AGG-ID: UgdR6rqaMkKHs9j_McQXVQ_1779315732 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-43fe791a398so4315460f8f.0 for ; Wed, 20 May 2026 15:22:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1779315732; x=1779920532; 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=dwGlO3yG5EtH2T+AQMoYdXPNyVEDsUWFS+ozJXrj1vA=; b=OrSjq0xZQMAEFH9hL1NFCMAWOBNd0OTRZ0M7+/cdSG0GJAewNkjyBTajcSaYFpZZX4 CLnj08zKDkqNq2hSGY0xxA/qQcwJErfGVY5HIZr/7ZRSgAybemoMA6Hnsn2sN4q84c/3 ZSBmnp8rPaDKWBPEB74oV5a1CeHsRAZs+GPfWaK7HKxIdZ8vZdmAlJ7Wt5tgat6lMbu0 I2GqYLVk+cLFyN2iB2mtlTOrWpoVYAN8okTD/GRRlFjJRfCSgyyYANlmWD5LfR/rZPnA llxJ795KmcHGGuQ1yPNbiwIpA613l0JU2q4dzjA5qAIIk9vhz0gMFVK0QvOf4XIuuUeW EDkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779315732; x=1779920532; 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=dwGlO3yG5EtH2T+AQMoYdXPNyVEDsUWFS+ozJXrj1vA=; b=U0MQwMrnEppJBZIQkanKP45BW58FxA8h7G8WsFatJu7ww4UWGam1sBXKfxoMg10dnI ui3dzPuuWTOh/4wCDa634sWXz9Ew5e+S5G1wmlB3Fjnr+tszyrlNI8oAQ+cQUZBwe1uW xRNOGG/+AaK326zRhz+eJK7YamoqbXPMR6d6u2BuMRLu5KgoIaeLdMJMT3wumapDfyK7 /LKge9DvUmD4KuMhOCP419zwS2RoseLXm23gpOvRWbPIOUYc8xvZA4JETfytYL+U3GV9 z/mpapher+ncykHFPAebI3/80IftzuRtZR0W1Qk8daHSrP32bf/yiNi8qovW/GKpSc7j 02Ow== X-Gm-Message-State: AOJu0Yztb/AvrAifpw0vEon+Pkyp+iH+iN2BRkaiAA8SPnaa0cOkREG8 AviT506cz+CQx/mSQxQq98yTjAiIfCmxoQCGnkg3+OXW1Q/AcDzEe02qydwR6nKgFtvxyVnxqY4 /es3QAbwHfjKgSq7CuSD2biSwS8tW2Jy2AVl1HGP5JTS/Mah+Dca5668IAUOJi2lKWbTDlM0dEs mid0o2/7yZnlPArYLq7l0+WAUvoeIlU64RWZj9nqCOCIE= X-Gm-Gg: Acq92OFDIULpOZjkputByOQSGdvaxDKitq+eIQ6cP3axu2cOp+IyRmO4Uf9ZXAAgwAS kAgWLzALo4Y5HDt8PRLYPqBqqJ1QKr+XpfNAYmlyiFGQYjMjmDAnANfV9qrAlhM6PZgkK9Bozv4 KQQgJqce8zsTnNIrkqGdbbt6gZgL9rPOU+dlEJFmjpZkXYlr0HtVjvr20iKnip+qGxHbUP+ey6Y 4wdllpZn/r1n+UNbY4hYISoAv6UysfSUMIuU8mhuMb4YKY1RnypSaqgyupJOKe6afszskOxAtyM uRJ3nakBAFjuO5TK3II//6uqApTam/CCcLatrkjPmaIk76ra2mOWa/w0Kb/dEAGYuMJ05/x7iUY RlAXzRmoKSgoNEtp5QQLXpB1MrmoL+Lagl9HegQTUSuc= X-Received: by 2002:a05:6000:402b:b0:45e:73b3:8118 with SMTP id ffacd0b85a97d-45ea3bee76fmr278682f8f.29.1779315731808; Wed, 20 May 2026 15:22:11 -0700 (PDT) X-Received: by 2002:a05:6000:402b:b0:45e:73b3:8118 with SMTP id ffacd0b85a97d-45ea3bee76fmr278599f8f.29.1779315731226; Wed, 20 May 2026 15:22:11 -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-45da0a19b1dsm56913999f8f.17.2026.05.20.15.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 15:22:10 -0700 (PDT) Date: Wed, 20 May 2026 18:22:06 -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 v8 19/37] mm: use __GFP_ZERO in vma_alloc_anon_folio_pmd Message-ID: <0ec029361949c492b10accc8cd787aa0d2fef0df.1779315441.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.27.0.106.g8ac3dc51b1 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: 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. Signed-off-by: Michael S. Tsirkin Reviewed-by: Gregory Price Assisted-by: Claude:claude-opus-4-6 --- mm/huge_memory.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d689e6491ddb..9845c920c29c 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; @@ -1356,14 +1356,6 @@ 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() -- MST