From nobody Fri Jun 12 20:16:54 2026 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 1D77C274652 for ; Tue, 12 May 2026 21:05:19 +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=1778619921; cv=none; b=VwSDqvC4AiZ6xdd5s2WnTf+eSvYBiAe7B5CKkZSIAxZWb3qPMC+BHSMLgfGmVXoUWyEusE9Kxf4pXN/QhPfGZF3HeJ5LS66Wc+34SAB4qfdpl9s2WlHsuAWxK9QlOhrcA9MaBuAZyuQulkOgI66CWidQSmOzTUfYJkdU23sFlJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619921; c=relaxed/simple; bh=5WPB3ZBqh71XoLzj1Vvh/y3ryxaNlqNoDwWwMbiSDuQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Xcp7/yHBTFHwubkvw0O0ZyUzKT4xpz93CCMspZRRtleD/l/8jnxbiAdewZKq/8jIIBcpG+/nbW7sl5vOHZ32CA0CHlh3w4dOcxXqXoKP/l/Sf8JWiN4e4rbwEIJWlPmFAIIb1HICJN3wCN0bdwFtVeyRGifhOducMofPiOZWl4s= 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=CBjkyAd7; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=kJgEoCL/; 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="CBjkyAd7"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="kJgEoCL/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619919; 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=axwB8YBt76LIJzhy+Beipy/onk26AHGibl0rZie+Elc=; b=CBjkyAd7Oc9REib/u/bHkB3SP6VM9GD71oCAXReKPqev0AoTsiB9AYqmFzzIpcKltm7NP9 aF8pXvFEw46h2z6JOeM74XYa1xXqWGEMhSgW35mVkmJahCydNJJAYs6WN5w52RcXDnLUrZ QtC0USSxTmAfJT/ji9bJ5oQgq/ntqLU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-488-M0chTOwhMhmiVBPHDdVWBA-1; Tue, 12 May 2026 17:05:18 -0400 X-MC-Unique: M0chTOwhMhmiVBPHDdVWBA-1 X-Mimecast-MFC-AGG-ID: M0chTOwhMhmiVBPHDdVWBA_1778619917 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-488c2aa6becso48424225e9.2 for ; Tue, 12 May 2026 14:05:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619916; x=1779224716; 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=axwB8YBt76LIJzhy+Beipy/onk26AHGibl0rZie+Elc=; b=kJgEoCL/OpvrkhYRe5SzbKDwJLcGGYQoc1LIyouCQVd6jld4yF+RstfTuHy0m/R0g1 BZDo7y60XPajkjO40DU+jEY7dngTtVZiV8dyJ0UUlYtQK8PhlhJ6vPVFmDZUZyY2XXeu a3KMc9c9TySd04HUAqoj/yRR1+e3qHENlBH6hs7HZuzBoeaDvkRG58QW2mQysByLt4f5 ZWbUXYiiimzfmsIDikdlg5dP4guap3sjLy2YvekwkRLk8L0FLxRVrD8gRoUwmeTNHt47 FDSqK14AG7hmxqq6fs2zzsDs2TzC5h+mhsoWAm6gCfs5Ccizb+8XFQLlvImVBb+XAhIU mDtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619916; x=1779224716; 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=axwB8YBt76LIJzhy+Beipy/onk26AHGibl0rZie+Elc=; b=rXfMPyvgu85+wqY7UkotAFS/YsXvGLcoKCw0CjMqULSvkRRJZR7Zzm4l5WI/PpOCb3 fWT77LnffYURx+WJho5s3w9cmXDd3KRhfhEh/U8g1E2VDW6OjbuQ2JGo1FpDJQlgZife sK5F5OU92zHtR71B+jkd9QpsROlhBDtC4x0jUJXc4qPv4w7ju9s0jZDBfJd3VhwASCpF szh4MRM0jkk6oCB9g3HKaZhECawW+DGNTKk63PcG/dBwzOoMJTC9e4I7jNgBphPUtsl0 GY89kQFDspNe9E+hH7cFPNYoBSAmZLP0zhhNZDcDO+dd7E6LynT7lx/oEablPMT/OeTe XiyA== X-Gm-Message-State: AOJu0Yy8SkaKrsZg0iHZJNmXUhSDeWHv47GaNNY/XUCa+xEe+CuAhU5X ql+uJ9vZ9drlvgUzCKP9pl5w33VvarJCevQttcfzh59To9vebchWzaAFwLYaMM6ksO/16edN7Kz 3xD/aOnGhjXB3ewLb7j5RHDaTJSl29Nf0ZjE20wfRIpVVhZ5ao9G8E+Qxwi286RMiCmqgjGFwAS n53Glu+c18NW8aMafSfUcXRBKmRpXDtqvoIs4qeoBi2rk= X-Gm-Gg: Acq92OFnBgQWSYJGjRs/6pgqyzzUO6y7AgaBQOwhqbSOXhZ5KWCWEa7sL25kfQzp4D2 NfJHeKNOOf7iJwHlDJRCWhU72P5ze/543cLIK9vlP3N28PukYGu4kKEgrDGxRA43vWpc/nQag06 LuqFEMOWGsrH+D7yNU7adayN3TswwmOrqQeJY94vlHuM3UGwtOzUJfhqyT51kSAUqp4XWQrY+LK Hkp1knKyYSdNk+FmHv7vqZCfsl1ypNbZVv+ilcnhWefvQA+EopsK7AxyXYf8Y49zgNTC2FwIl6s EZWylTge3jDrUtKfy5ZfraA70gLHifvE/tGb7CXZWoHm3YreDn/seacw7kdqllXVdLVAYlq6GpJ 3W6zk+pN9J9dM4i5X3o2ZcWiE9m9ZEZMTZcLSUxu/ X-Received: by 2002:a05:600c:859c:b0:488:c683:be89 with SMTP id 5b1f17b1804b1-48fc9a09ca9mr4482685e9.9.1778619916401; Tue, 12 May 2026 14:05:16 -0700 (PDT) X-Received: by 2002:a05:600c:859c:b0:488:c683:be89 with SMTP id 5b1f17b1804b1-48fc9a09ca9mr4482015e9.9.1778619915787; Tue, 12 May 2026 14:05:15 -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-48fc8d624fbsm57846605e9.10.2026.05.12.14.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:05:15 -0700 (PDT) Date: Tue, 12 May 2026 17:05:10 -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 v7 01/31] mm: mempolicy: fix interleave index for unaligned VMA start Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The NUMA interleave index formula (addr - vm_start) >> shift gives wrong results when vm_start is not aligned to the folio size: the subtraction before the shift allows low bits to affect the result via borrows. Use (addr >> shift) - (vm_start >> shift) instead, which independently aligns both values before computing the difference. No functional change for current callers: the fix only affects NUMA interleave and weighted-interleave policies. Current large-order callers either pre-align the address (vma_alloc_anon_folio_pmd) or do not use NUMA interleave (drm_pagemap). All other callers use order 0 where the old and new formulas are equivalent. However subsequent patches in this series add large-order callers that pass unaligned fault addresses, making this fix necessary. Signed-off-by: Michael S. Tsirkin Reviewed-by: Gregory Price --- mm/mempolicy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 4e4421b22b59..b2c21ed1fd84 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2049,7 +2049,8 @@ struct mempolicy *get_vma_policy(struct vm_area_struc= t *vma, if (pol->mode =3D=3D MPOL_INTERLEAVE || pol->mode =3D=3D MPOL_WEIGHTED_INTERLEAVE) { *ilx +=3D vma->vm_pgoff >> order; - *ilx +=3D (addr - vma->vm_start) >> (PAGE_SHIFT + order); + *ilx +=3D (addr >> (PAGE_SHIFT + order)) - + (vma->vm_start >> (PAGE_SHIFT + order)); } return pol; } --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 3826A274652 for ; Tue, 12 May 2026 21:05:24 +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=1778619926; cv=none; b=Vr9Y/7oQ/dJoWe1086Xdi5tdL7F52UUZRQterdSrMyaouoCmgY+PDDZlD0Skgda98RDDd+ySBldGSz+EJtNdr9RFZ2+4ciOu6S0Zszet9CgffpCKxjWnrZ4BOcxHj80N++FTDHeTA4gDbi9wNLkYzc/pLAeDVRIaqo+LtqjiYx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619926; c=relaxed/simple; bh=bGzF3O3suJfDsEpMco/qz1u2W2qF7rZPHMyZKhViaaQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IudVKHH6CUtVqh8MYhVhRBa73d3EAg83rpUTX+vqH3QhtC+da4BaGmkcdjPeHFv6f66HCmhitOqhVCcF36yFfcrKnITHzGHFEJMb54V5KXl0XD2FjbFrTWZJnCp7kfYZSfIuApZogAFCDm3X5qL61gWkmjLRg6V3jfg71TirvDg= 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=F8WXXtXY; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=WQMC41jL; 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="F8WXXtXY"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="WQMC41jL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619924; 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=Rtq/ad55zrZyrod+V9Nt+5t6fAHZwxPdckwVickks5c=; b=F8WXXtXYXMOr5y5In4tfZY928OdJSOS723gd9pBwfW8WoRnNIcPqb4mXHnBdxTOU3rj9WX Ga/LzSXqJcLg9aq1E1LIJ6ygaMupGkdO8fOMBINzuynfO0fhip97lwi4uPEUwbIzSIrlt8 ba4mB7mewFG8aZxkArZI3GMbqflDSno= 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-65-0Y96dcDxMHydxGwkJV8nZw-1; Tue, 12 May 2026 17:05:23 -0400 X-MC-Unique: 0Y96dcDxMHydxGwkJV8nZw-1 X-Mimecast-MFC-AGG-ID: 0Y96dcDxMHydxGwkJV8nZw_1778619922 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-488d1b5bca0so29445965e9.2 for ; Tue, 12 May 2026 14:05:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619921; x=1779224721; 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=Rtq/ad55zrZyrod+V9Nt+5t6fAHZwxPdckwVickks5c=; b=WQMC41jLJpZ0C0iKIJAN6zI3NbVnyVPPr1opabo/KZy4Rx6s39iU3Vd0vdilZkBJZ4 BjhpWUVJ6Se1oJxUoAvzPxGAwQh2v0rTJSEiXdcde3wRG7zOKeZuK3rWtYp/hK+nCvjy Swyb3E0l2k1GF0KctQe9eWKh/z44IdGRQOfGlsi+lGNRRuRftLn13/im3NqvahBSh7YL r+QjSoVL9HQAr2EY/tFcASXjykgkT9TWPeK7Yurckm9HbcKApIxVk7w9m4I4TCyRdEjc h8F5JehrPWsuysP0a6+XnZVyTQJJZoeX4dPEjVqlQQTtHBdMHnXsuZwMk87dySizeZGC HfSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619921; x=1779224721; 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=Rtq/ad55zrZyrod+V9Nt+5t6fAHZwxPdckwVickks5c=; b=EucQyvmpUluIRe3OuBjhjDKRWt+2oXc129agMPhalTv5GPJq60eTMWAeIVGNuULVZo DqruajoJ5BQkFC/cjITqDLpVl3pZAYZZMzK+/5adWDQg8HBSCwpHRBk0pbPBvm1Zn2ab 7L+HF2iMcqv2Rdgect0tpkgszUv7CU0NtHUr+5LfLfUa+N1s4z5ecoPtvJH9fmQku15K UHYAiINWvqP5np9Bsf+fcWD1iF1I6xpjn405SW2DIu6jDl88i7A8R0h5Nj7Iy1xD4WzS 2f1j6ZwV3pBVR86CTdFD08G086qCTrEoWd6sGFNOJyj9CdjhWrHXoF1xVJu4FM+Kgb8t Kp2w== X-Gm-Message-State: AOJu0YxEt02NMGdN/rWFJ+Qxnn30OENX8Xg4X21yFwTfAy7snk7kRjR3 keA9yELQIxd4ZN+2WwMS7kIVHQMEKUKBGj+R7lNxEaPR02VlASFLr0obVvscTF6TapZpRy8WzbD sJyRTt2NUsMgX6JIS4cPAP+9cZ84xQByg0Wcg2DTHtsI14bdHGNnMqVPtfG/Yk+LNf/th+CIeob TkTlRrK7vm3AYYyQYFLHocRiUFhKgedWanOpZ1TnSrHLQ= X-Gm-Gg: Acq92OFbrdV6Hav/RYqE4BazPOTe/DMiSywXvlbFZVM4GqeZy4MlZ+gr3iGhFKvOVtC zgv5K1dftI9fXfShGM3AGpY8D0XULvzGw5Df5AV/Yh3q8HLOJI7tjVsZo/ZYK1AbRK9sbSi3Cxt ZmqcDUm5jRp5J8xr4dgdLm19l3dticCOEWllLKmDJDeYyHt4sF4rTLxs7fiM1wz41ZUW/HXX5dN QJsn0dv62FQgvDqefcEuTdSXWq+wSD882H6wUS1uVYwx4pxdIzsQCzS/0v4nNfiQJ5h9Q13UcKd B+K6r6T8vsAOi0mKDst1GME/zTRCJFQLlfd5+z2eskZIVZvETEiHKI6tOWx4GeelOCHc00l6ZVf MMozv/zmOGdVvDXQVisZ5ao+VLdiLFr/2fbjvWAQa X-Received: by 2002:a05:600c:848c:b0:489:e696:8362 with SMTP id 5b1f17b1804b1-48fc9a30a6amr5860865e9.13.1778619921494; Tue, 12 May 2026 14:05:21 -0700 (PDT) X-Received: by 2002:a05:600c:848c:b0:489:e696:8362 with SMTP id 5b1f17b1804b1-48fc9a30a6amr5860115e9.13.1778619920806; Tue, 12 May 2026 14:05:20 -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-48fc8d27667sm18044215e9.7.2026.05.12.14.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:05:20 -0700 (PDT) Date: Tue, 12 May 2026 17:05:16 -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 v7 02/31] mm: page_alloc: propagate PageReported flag across buddy splits Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a reported free page is split via expand() to satisfy a smaller allocation, the sub-pages placed back on the free lists lose the PageReported flag. This means they will be unnecessarily re-reported to the hypervisor in the next reporting cycle, wasting work. While I was unable to quantify the performance difference, it is an obvious waste, even if small. Propagate the PageReported flag to sub-pages during expand(), both in page_del_and_expand() and try_to_claim_block(), so that they are recognized as already-reported. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- mm/page_alloc.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 227d58dc3de6..e40fd39acbd0 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1699,7 +1699,7 @@ struct page *__pageblock_pfn_to_page(unsigned long st= art_pfn, * -- nyc */ static inline unsigned int expand(struct zone *zone, struct page *page, in= t low, - int high, int migratetype) + int high, int migratetype, bool reported) { unsigned int size =3D 1 << high; unsigned int nr_added =3D 0; @@ -1721,6 +1721,15 @@ static inline unsigned int expand(struct zone *zone,= struct page *page, int low, __add_to_free_list(&page[size], zone, high, migratetype, false); set_buddy_order(&page[size], high); nr_added +=3D size; + + /* + * The parent page has been reported to the host. The + * sub-pages are part of the same reported block, so mark + * them reported too. This avoids re-reporting pages that + * the host already knows about. + */ + if (reported) + __SetPageReported(&page[size]); } =20 return nr_added; @@ -1731,9 +1740,10 @@ static __always_inline void page_del_and_expand(stru= ct zone *zone, int high, int migratetype) { int nr_pages =3D 1 << high; + bool was_reported =3D page_reported(page); =20 __del_page_from_free_list(page, zone, high, migratetype); - nr_pages -=3D expand(zone, page, low, high, migratetype); + nr_pages -=3D expand(zone, page, low, high, migratetype, was_reported); account_freepages(zone, -nr_pages, migratetype); } =20 @@ -2288,10 +2298,12 @@ try_to_claim_block(struct zone *zone, struct page *= page, /* Take ownership for orders >=3D pageblock_order */ if (current_order >=3D pageblock_order) { unsigned int nr_added; + bool was_reported =3D page_reported(page); =20 del_page_from_free_list(page, zone, current_order, block_type); change_pageblock_range(page, current_order, start_type); - nr_added =3D expand(zone, page, order, current_order, start_type); + nr_added =3D expand(zone, page, order, current_order, start_type, + was_reported); account_freepages(zone, nr_added, start_type); return page; } --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 BFB77274652 for ; Tue, 12 May 2026 21:05:30 +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=1778619932; cv=none; b=sHBeksmDjdL4Icsx1vo4bjgsQ3QdxVKIJZpvgRHsRVukZS4PbvY683ea2KyAKX1xHkVvIAis8EAja0sat/8IX9TqrVZ0wEBT5M6E57A+x5aakLoGethvcRS9U2KN/NkXfyqzoky6rgjCoLjO9WmsrrCMmHDBdgGR7jXFdwL5dl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619932; c=relaxed/simple; bh=jAEaO4JfYvTZh0h5rRrKJYMGQ45gKsBKH3AVbKj8c00=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XWfd44tnuJafA6IOatYai+CdM6tOCvvFMKMfH/ExB7RENXzObSHjcTushfwNQFPO0wPqtfo/0K8KR6toBTCbxme1OE+TGaje/oZL9WYydKSqxKsfkGQgXMUpm2D/B579n9w8xTyYeR2BII4H1ZjIqv+l9sNiVwepHLh2/xvSby4= 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=XLcVS6mC; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=l4P51C8C; 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="XLcVS6mC"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="l4P51C8C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619929; 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=dLzVjPl4JuXWdYl/OMkyXvKlFkDQF6qpB2cxYBp2hXA=; b=XLcVS6mCGyDAJ1s26Um1C597dSE/P8Bcvadp2uPEOzSDgHkljKShYseYsuJD1Th3IT5B7A KGoZ+kcj2BWfdc2Gos1PKUZeW8XVEJoT5GciiKPsO0J/Ih0pwbKFx5vOtk4/ZBZsUYy0d2 rqpbk9HWB5ONgLeO2VnbV+71qJP26FY= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-221-lQvqNPacNByI6kho9AvqNA-1; Tue, 12 May 2026 17:05:28 -0400 X-MC-Unique: lQvqNPacNByI6kho9AvqNA-1 X-Mimecast-MFC-AGG-ID: lQvqNPacNByI6kho9AvqNA_1778619927 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-44696b11265so6787072f8f.0 for ; Tue, 12 May 2026 14:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619927; x=1779224727; 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=dLzVjPl4JuXWdYl/OMkyXvKlFkDQF6qpB2cxYBp2hXA=; b=l4P51C8C11EwuYOAPkSnmbNWUnRPZ+Es9ihHYXeC/FvB6opsitNyeuf7Yg3eoMP8tQ fa2ivxx3mrvFMV86khKB1+G5gZ+ut58eByagQBAdY8q5tFa8OKkNdm++OjScB0sdX2n4 8nKk4eAWQT12JpbRKCEu34tDuyRm8yZChQpiBnD8GHqL2yLxKUp69o1sbCmUz4qqbJDn p6V42JU1mifmFbSxTU1YANHSfYHzS1FUZYlJoqcoyMpfQQkJjPx/BaePyfr7wGO9OSrZ YF+Hcth1RzO1aJ23gcJ2SvQQXX7+9HlucCcCatxdcxkMtOXIBlNrbhVT4NBtLvRMZb2H MleA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619927; x=1779224727; 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=dLzVjPl4JuXWdYl/OMkyXvKlFkDQF6qpB2cxYBp2hXA=; b=MUkfMOeuDU094z/zDJef6jlGFfi3TDvfLeD+jV7/xH1knQcZyi5fc60YDNkg6w+hxC AmGkuUKjkDoa0GPtd7pvcx2gABf4l91YkrEpxhnCbRh01mqQ5m42Dn/XIzOI069W+Vfv CgZ76RT2W+xRj32+mgHH1E4hCdd+tS7SzH2iOn4RoF3fcrJq5XFVB196eu+SuiLGoxQU rm6aLz2n2VKsexPdUOQ9I2Ge8efWPUY+XMBrWaRJJUP8XIfKgJ5QZCF89WsHsaTbltXc TdVAdbtrFOq8fLDjyiWcyPhjRgdP5h2g7DQOvmJNgWk5FZeBU2fXVDa9beUq1m10WDJ+ DBHA== X-Gm-Message-State: AOJu0YyhOON9S2lYU4O51H7WqZn9GXAbC/xpecQr1pRD5prTpfa/8TfL bJ6iGmLUhs7DwI78eTBt1y8ybqtd13S/HuzXhzXY3yJT90lJsDuMlFKJ0rzLAX+BAu3mNEnBCFc 2C9hTJqvY9rGApK4Vv5RXhnFYUEU+Sr/myYZ1UYf/6l0pFanB+v5yDZnUgGzY1PsPqqAx0+19pa zq/AB3f3QcuYBAvKjEfgUy+IZXRzPBh/koOcFewMoPy4g= X-Gm-Gg: Acq92OGpWUm79D+ZtixyhcnRS/5BxhO5S8FA3/kOinyvO6R54FGa8RnsVmU7DCOznoz qNjTTk25DNHPCf3dCj5kxU9fJMcoXdF0KAzdFOcB3WkLExbNzXqPsOkHVLAAXVMft6uk0CLpZS8 gbbhx2PqFIqn2x40NFDm5twtv0Hg6nkfVF2TbWBUzJZ0YLFsRdgODyzSvak9UmvBx4EqvMSndJh KQ/YT8u1rpc+kfJueHQ5nYJbEkqXmUyS0WYcvD5Vf6AMmg2XBh6Vt3CRnhjTi9M3vuRSxpGhik/ fOU/9fn9XOE4zGj2J6cOMXBUnmLzyp53J0qs5VoHjVJTp3GgEvGw83dENUKCcWUgy1pnHQq1cVE pabxSnOmCZWE4HeYq08nxEOmNvryjoP/89nCzsXow X-Received: by 2002:a05:6000:268a:b0:43f:e934:50ac with SMTP id ffacd0b85a97d-45c5859efc6mr574275f8f.7.1778619926751; Tue, 12 May 2026 14:05:26 -0700 (PDT) X-Received: by 2002:a05:6000:268a:b0:43f:e934:50ac with SMTP id ffacd0b85a97d-45c5859efc6mr574198f8f.7.1778619926094; Tue, 12 May 2026 14:05:26 -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 ffacd0b85a97d-45491f8d4c3sm34961168f8f.34.2026.05.12.14.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:05:25 -0700 (PDT) Date: Tue, 12 May 2026 17:05:21 -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 v7 03/31] mm: page_reporting: allow driver to set batch capacity Message-ID: <46519548042fe8029d74459704468e0587e674ec.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a capacity field to page_reporting_dev_info so drivers can control the maximum number of pages per report batch. This is useful when the driver needs to reserve virtqueue descriptors for metadata (e.g., a bitmap buffer) alongside the page buffers. The value is capped at PAGE_REPORTING_CAPACITY and rounded down to a power of 2. If unset (0), defaults to PAGE_REPORTING_CAPACITY. The virtio_balloon driver sets capacity to the reporting virtqueue size, letting page_reporting adapt to whatever the device provides. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- drivers/virtio/virtio_balloon.c | 5 +---- include/linux/page_reporting.h | 3 +++ mm/page_reporting.c | 26 +++++++++++++++----------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index f6c2dff33f8a..6a1a610c2cb1 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -1017,10 +1017,6 @@ static int virtballoon_probe(struct virtio_device *v= dev) unsigned int capacity; =20 capacity =3D virtqueue_get_vring_size(vb->reporting_vq); - if (capacity < PAGE_REPORTING_CAPACITY) { - err =3D -ENOSPC; - goto out_unregister_oom; - } =20 vb->pr_dev_info.order =3D PAGE_REPORTING_ORDER_UNSPECIFIED; =20 @@ -1041,6 +1037,7 @@ static int virtballoon_probe(struct virtio_device *vd= ev) vb->pr_dev_info.order =3D 5; #endif =20 + vb->pr_dev_info.capacity =3D capacity; err =3D page_reporting_register(&vb->pr_dev_info); if (err) goto out_unregister_oom; diff --git a/include/linux/page_reporting.h b/include/linux/page_reporting.h index 9d4ca5c218a0..5ab5be02fa15 100644 --- a/include/linux/page_reporting.h +++ b/include/linux/page_reporting.h @@ -22,6 +22,9 @@ struct page_reporting_dev_info { =20 /* Minimal order of page reporting */ unsigned int order; + + /* Max pages per report batch (default PAGE_REPORTING_CAPACITY) */ + unsigned int capacity; }; =20 /* Tear-down and bring-up for page reporting devices */ diff --git a/mm/page_reporting.c b/mm/page_reporting.c index 7418f2e500bb..006f7cdddc18 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -174,10 +174,10 @@ page_reporting_cycle(struct page_reporting_dev_info *= prdev, struct zone *zone, * list processed. This should result in us reporting all pages on * an idle system in about 30 seconds. * - * The division here should be cheap since PAGE_REPORTING_CAPACITY - * should always be a power of 2. + * The division here should be cheap since capacity should + * always be a power of 2. */ - budget =3D DIV_ROUND_UP(area->nr_free, PAGE_REPORTING_CAPACITY * 16); + budget =3D DIV_ROUND_UP(area->nr_free, prdev->capacity * 16); =20 /* loop through free list adding unreported pages to sg list */ list_for_each_entry_safe(page, next, list, lru) { @@ -222,10 +222,10 @@ page_reporting_cycle(struct page_reporting_dev_info *= prdev, struct zone *zone, spin_unlock_irq(&zone->lock); =20 /* begin processing pages in local list */ - err =3D prdev->report(prdev, sgl, PAGE_REPORTING_CAPACITY); + err =3D prdev->report(prdev, sgl, prdev->capacity); =20 /* reset offset since the full list was reported */ - *offset =3D PAGE_REPORTING_CAPACITY; + *offset =3D prdev->capacity; =20 /* update budget to reflect call to report function */ budget--; @@ -234,7 +234,7 @@ page_reporting_cycle(struct page_reporting_dev_info *pr= dev, struct zone *zone, spin_lock_irq(&zone->lock); =20 /* flush reported pages from the sg list */ - page_reporting_drain(prdev, sgl, PAGE_REPORTING_CAPACITY, !err); + page_reporting_drain(prdev, sgl, prdev->capacity, !err); =20 /* * Reset next to first entry, the old next isn't valid @@ -260,13 +260,13 @@ static int page_reporting_process_zone(struct page_reporting_dev_info *prdev, struct scatterlist *sgl, struct zone *zone) { - unsigned int order, mt, leftover, offset =3D PAGE_REPORTING_CAPACITY; + unsigned int order, mt, leftover, offset =3D prdev->capacity; unsigned long watermark; int err =3D 0; =20 /* Generate minimum watermark to be able to guarantee progress */ watermark =3D low_wmark_pages(zone) + - (PAGE_REPORTING_CAPACITY << page_reporting_order); + (prdev->capacity << page_reporting_order); =20 /* * Cancel request if insufficient free memory or if we failed @@ -290,7 +290,7 @@ page_reporting_process_zone(struct page_reporting_dev_i= nfo *prdev, } =20 /* report the leftover pages before going idle */ - leftover =3D PAGE_REPORTING_CAPACITY - offset; + leftover =3D prdev->capacity - offset; if (leftover) { sgl =3D &sgl[offset]; err =3D prdev->report(prdev, sgl, leftover); @@ -322,11 +322,11 @@ static void page_reporting_process(struct work_struct= *work) atomic_set(&prdev->state, state); =20 /* allocate scatterlist to store pages being reported on */ - sgl =3D kmalloc_objs(*sgl, PAGE_REPORTING_CAPACITY); + sgl =3D kmalloc_objs(*sgl, prdev->capacity); if (!sgl) goto err_out; =20 - sg_init_table(sgl, PAGE_REPORTING_CAPACITY); + sg_init_table(sgl, prdev->capacity); =20 for_each_zone(zone) { err =3D page_reporting_process_zone(prdev, sgl, zone); @@ -377,6 +377,10 @@ int page_reporting_register(struct page_reporting_dev_= info *prdev) page_reporting_order =3D pageblock_order; } =20 + if (!prdev->capacity || prdev->capacity > PAGE_REPORTING_CAPACITY) + prdev->capacity =3D PAGE_REPORTING_CAPACITY; + prdev->capacity =3D rounddown_pow_of_two(prdev->capacity); + /* initialize state and work structures */ atomic_set(&prdev->state, PAGE_REPORTING_IDLE); INIT_DELAYED_WORK(&prdev->work, &page_reporting_process); --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 083753C8C7D for ; Tue, 12 May 2026 21:05:36 +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=1778619941; cv=none; b=GZ1YmRLm6RQmmXvbvnQ/tdfCAf5ls1ksu2zvIer75YtUnhcubWmHm0GwTQBKkC08q2ghpOPsgCUn0m8xOIvhZIoWriVRTw50TNtj5RH6wNWvru34LjVdTYoOFXMfA1LKlemebztstsixQ/wWP5wK+avfFbfr0XM8P5+nSVIo0VI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619941; c=relaxed/simple; bh=dbqodEtBSdW6l7fSNG3X+ow9g33S1jhVrQg2Ca7vU3g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MTmLXlHeEsL43s/Ms9QsnpHV35C5NTCeZdRh0wqs7CcnXxUuCMfE/y90wxEhBQJQPofCfxwrTcuzU2dqIN4XbkLK2Ai264nJEQIDpKOGQet5RgpYhcB0ZoMceHDiB0vfAN8WdEnd0axQLP6eBIliD3G+S119G1aEyWhU4e/3Ihk= 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=PMuieYuK; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=m3+528kk; 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="PMuieYuK"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="m3+528kk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619935; 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=73ni6E1OiylZPcnUbU0EX/Y/PdtoGvrjv7tOovuvhS8=; b=PMuieYuKXhiFHmBLLHCUUd9/jhGPGPS4n8QB+f2OrKOqv3ntvbZOr7u2ZEctrEVFCVDdzh AHTM+vHfi9wNk0CrN7P6ZYIgnQMpAUrwgi+H/84n9cJTHjKgd3hHUikHCB7HvvWEuDn/0a BmfvwrKRmGzotaYp3OZcXW8j/v1vw0A= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-EMFq8kIHMbCWbUphyKoilg-1; Tue, 12 May 2026 17:05:33 -0400 X-MC-Unique: EMFq8kIHMbCWbUphyKoilg-1 X-Mimecast-MFC-AGG-ID: EMFq8kIHMbCWbUphyKoilg_1778619932 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-43ff19e54beso4179559f8f.2 for ; Tue, 12 May 2026 14:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619932; x=1779224732; 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=73ni6E1OiylZPcnUbU0EX/Y/PdtoGvrjv7tOovuvhS8=; b=m3+528kkybn20FvN71Rjv3Knsbq8WuoC0sfBHcXmxuVWZYPiqUpAacyRBfxqDTj9Tf gcv7aBg1tkhUUfpoGdkudjrWCNTjtj6iYA1A3EKfQcLMEDxQHRKy0bwSQc3Y4AMnn/ft zue1qhnEicLMTFLYfTyNVbjMW3p3i+Cx6u9LaXiLorQpziMtWCALJcWgiyn97x3Ih1OA 0tlPXGICF5Slc9w7WaY9oqrAerb4ujwu0yVIRSgKRyYQXXkVcDSMiqwRhpv3z2HO5i/j 5vWJE3bV39eApy7JYyGSWrl/mfvLn3RaLzJhvnpP5XjNAP1E6B73R7mVc15gjIpt3V7e 3auQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619932; x=1779224732; 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=73ni6E1OiylZPcnUbU0EX/Y/PdtoGvrjv7tOovuvhS8=; b=W9lD0lj6CKBpdbVwlCC9lRKjKF4a79O37UwERygbgM9L4kFQlJ7xbh9gfu+ABUsgDT DLM8rfR6oXORJGRycB5MR2YpJRd54GLMFnBjaAnmuCTxPmKbDy4GXU3pqbNFirxuMrmC qKSOt4VdMl7JcDtk4mCa47hTIv8CtTW1ufMPmffpUm+gGX2gZwpt32cut2ZJ56/kBhnM 4ew0ZXM40cQz6VPYqA1LvqR9x7LvsgFlJyW0SBoR1jYqMPZWW1UFciE56tTH48ZG9Ti0 wbAnYJpIlslZJh73h5nIKbFwXfv8ZRP+AY58wQZFpGuwi5zTvP2VwICblNQ+/HhFstLZ nyPA== X-Gm-Message-State: AOJu0YyPs8WjYbsVqUuIZ9ErpowadyHvhwt7KrNXt0huWCRRmnl0gKFy 9EGDBwVrAK2UE5FyAUdhw1Cv0UHgznasxHn25fq6dSGUsepvwmGDaFn95tnzqH7khyEyzF/5/2O qy7gaNKQd2x8RfkWcD6JJsMxRnWrPc7vg8f6KOekbHCxkg21W4Lv/TF8rLTJnZNu0ZrdaK5BCAN XEX+uFDTE4E29DpA4kHpq2OLKGotSp8sHj13AeqqrYpPI= X-Gm-Gg: Acq92OGu5md8C0wNmqJ1VC5NpR1x5ib3BusyPNgZ2dIlHcs/fV63hgfQdFBHcroziQH UvA4jMAZW/TExRUwOCM6M5ucixv/itcjtTalcdOFR+/oaPhMawlP7Hq2fkGo3rKrh9lX5LiRwQt rbdoJo2cVSX2BaYRpgKCjRl/xsKRobjFq82jTo4fCQPGX5BWZT6ieMrwTEdXhQ821GLjVx05h4u xUx7dPb8pX+4T7R5iO6DUZ3m7jhyRhvtO6gRAWtXeyOg2ToTbRf4civyJZlhYs9zeuOIiLzuYaU 5l11TjYB3EeWSY2CNGckHWshDM8HCyPfrEK2b2mX2CK3QV5FogdRQ5wigrHm1hR5D0owzH94FL2 6FP1iAnBOGh7T7hLU1vImicfeY2DF0+u3IU/tiYYF X-Received: by 2002:a5d:64c6:0:b0:448:659b:abec with SMTP id ffacd0b85a97d-45c580ce38cmr505598f8f.8.1778619931881; Tue, 12 May 2026 14:05:31 -0700 (PDT) X-Received: by 2002:a5d:64c6:0:b0:448:659b:abec with SMTP id ffacd0b85a97d-45c580ce38cmr505522f8f.8.1778619931288; Tue, 12 May 2026 14:05:31 -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 ffacd0b85a97d-4548eb75c29sm34124809f8f.9.2026.05.12.14.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:05:30 -0700 (PDT) Date: Tue, 12 May 2026 17:05:26 -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 v7 04/31] mm: hugetlb: remove dead alloc_hugetlb_folio stub Message-ID: <0143c5e2086fccb05703500c9269a899d4784768.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove the !CONFIG_HUGETLB_PAGE stub for alloc_hugetlb_folio(). The stub is dead code: all callers are in mm/hugetlb.c (CONFIG_HUGETLB_PAGE) or fs/hugetlbfs/inode.c (CONFIG_HUGETLBFS), and CONFIG_HUGETLB_PAGE is def_bool HUGETLBFS with nothing selecting it independently. The stub is also broken: it returns NULL, but all callers check IS_ERR(folio), so a NULL return would not be caught and would crash on the subsequent folio dereference. Remove it now since follow-up patches change the signature of alloc_hugetlb_folio and would otherwise need to update the broken stub too. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Reviewed-by: Gregory Price --- include/linux/hugetlb.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 93418625d3c5..f016bc2e8936 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -1129,13 +1129,6 @@ static inline void wait_for_freed_hugetlb_folios(voi= d) { } =20 -static inline struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, - unsigned long addr, - bool cow_from_owner) -{ - return NULL; -} - static inline struct folio * alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid, nodemask_t *nmask, gfp_t gfp_mask) --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 5764D3C8195 for ; Tue, 12 May 2026 21:05:41 +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=1778619942; cv=none; b=dgUD74XSfGN2ClD8QXEOmKodA1wJ2KUlXXd+ASpgZ2HiGecEmwzUp/BC2IGH9fja7BJsOwUsp0emdiD1jQbdzRXoze3IVVy1TIE2eGyITVGxJ6lVL3hFyOyLYDYx2ZPqpeJ9w37odb1l9KNAWR7B4Nyfay1dGUTh5EfEvroQ6jo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619942; c=relaxed/simple; bh=ePR7uNlotrezAJookcUJ/8DLykTQxnwcGZYCYwhIa5o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DObnHJqWHZMfjdEtsHb++z83z+skmCMbENj1BOZ9ze4Jgz9ngiYeo163jF/QuOB3oMpq5TV6KGZDFMkYZQPK3LGr20PQiLMTrzVpbkSPVBamORjBKGb2PlQ4y1Xar1uysQLL0RfFY8wpQlEQp91nFjtU3qcBt8D2Hu+8unKxpMY= 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=dykh9N7m; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=lUhsojKs; 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="dykh9N7m"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="lUhsojKs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619940; 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=uXm+f+MkYB5oL4CzdS91ST7c4wCcchxSd9UlyIAHNL0=; b=dykh9N7myHH5nkzF5PHivZ2tcUCIZDtKNo/tcGuW8m1GpZComc1FFtofWWsSap0TqNOLGA 3g9VSoQLlUM6nh6jYjcL/DxRD1IIWFKlHitO1oyrXrAI5eqy9Sb3laDVJCXeWVyuOBSYvQ dPZAFWgmSZErfWYPSQXlczHnX/wqYQA= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-619-v5TyrjV0OPmgrgUvaYcngQ-1; Tue, 12 May 2026 17:05:39 -0400 X-MC-Unique: v5TyrjV0OPmgrgUvaYcngQ-1 X-Mimecast-MFC-AGG-ID: v5TyrjV0OPmgrgUvaYcngQ_1778619938 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-45aeac88af4so1004986f8f.3 for ; Tue, 12 May 2026 14:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619937; x=1779224737; 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=uXm+f+MkYB5oL4CzdS91ST7c4wCcchxSd9UlyIAHNL0=; b=lUhsojKsn9Vs4tfswasb6NPQNWacxwA0Tx+P/nGp0YPP8s1vnR76IylCP1TBuNScrw DkeiUe4PxbCXAm+NhuWu7iIzVtWVllh0lZCBwgNYYm0zQ9t6zAKquAvfkNl5+P5VkJsG s/GvWa+qECY8Skb57lSlasoj9jgOeKmMwtn+lrjkqqd6ZkXQLaLVcqJpbuuI2VzoyKMG tUTMqG26Tkn0NJ9rAdlgmtdTzTVVfM9RQzrmE7yzbFysAto+ZeZ58i85LxWzGSjihN1c bQbK5wyitDFQWjvBMZV+0dLpe/w8UGPnwK1I2e1YkewmKijPQz9sMbWXzMNsQn17iqhs r68A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619937; x=1779224737; 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=uXm+f+MkYB5oL4CzdS91ST7c4wCcchxSd9UlyIAHNL0=; b=cZglGoQReYmWM/eWOXG/tUJBs9zgnTTtevieT4JUSsUHtSYhyu4iitCzFsgI3USaSr 4Z/nbrvYCUlf2YsCRktphAZkSAnU2tt/mTr2q3ETlE+5wG7QtB5q1fnmVGiSlHtPWZHP xi0OBecOt9OJiUTKAXqs9xu7rxuCGgSi2mhMh3PSAJThDDcwy11nvQID//WxqbF5Qtld RdqG4pm66WwP4gQVkdiO9i5GeOU+/qV41sNrQ43RcS2/hd1OMgLYAqv3b2DeiB3orgOS 7AXX+6BNzgD/m96YoZn/RDJ/t0/81pAyACNCwdILmFbt8cACDFdseOQ3JjtWTZa+Vurh Hn2A== X-Gm-Message-State: AOJu0YwO3AUqPe1fH1u+ju2WtvYGUdU3QSbOSRlb+Fbal8BZwNHhQowt eEN5IthxZFgyhfI836mQHxWI8SGsghB+obV+NBzIxSBsXLw6xuFX+a72ooZvZG7bxhxPqJ/1ryl EBeahdkE/D46hAN8Ub2u9SKZZoqoBnO9CLhql1J6Pbt1COrwrla6IYc1Q0hcQCwwoK59ZNle4Iw 8jLpoKjhLOKisWQABo+oNLsgHEwTDxGSjJMgGmqN6QO+A= X-Gm-Gg: Acq92OHhrWPWuumpeVbsoe67+3GWBGrdT2NRTQ3PzwDpfeTn6dxTXY+PlD7giOrDiP0 644grO/hETuiBARN8hxdOdWoZwTiWcIzY9xoPjJW0Fx89w7UHMZqX9FuRPsScDnQUCqxTteTbn8 HStG8JSsGp69cT9AwFHGEZ+jKHfd2NqLXhZF9gr38Ry2vtA4Zdpb+sNHeTSGhy8J++Bm4YXJkQ4 jxw8UZxfcgK2nXGDo9ewEvxTHowNF2J5T1mu2RyHtZGOKeWy3PWH9sSp1xFYTRH8m+tWdJ3wTyv XBOHdV1FaSYg6XX3ojJctWwKoB9kwCsWlG1M/kma2cpyKY3CluihOnKi3A47YPHJBGRnXkY8299 dKzjF07vU/M1YC0KeaJEBrW+js7mNJ+CQ1D/q3eI7 X-Received: by 2002:a05:6000:26cf:b0:45a:ff7d:9800 with SMTP id ffacd0b85a97d-45c584a868bmr548672f8f.15.1778619937291; Tue, 12 May 2026 14:05:37 -0700 (PDT) X-Received: by 2002:a05:6000:26cf:b0:45a:ff7d:9800 with SMTP id ffacd0b85a97d-45c584a868bmr548593f8f.15.1778619936563; Tue, 12 May 2026 14:05:36 -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 ffacd0b85a97d-4548ec6aea4sm40612389f8f.10.2026.05.12.14.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:05:36 -0700 (PDT) Date: Tue, 12 May 2026 17:05:31 -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 v7 05/31] mm: move vma_alloc_folio_noprof to page_alloc.c Message-ID: <17711d281fa0cb9751da2c856e693e9da6d1efa9.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move vma_alloc_folio_noprof() from an inline in gfp.h (for !NUMA) and mempolicy.c (for NUMA) to page_alloc.c. This prepares for a subsequent patch that will thread user_addr through the allocator: having vma_alloc_folio_noprof in page_alloc.c means user_addr can be passed to the internal allocation path without changing public API signatures or duplicating plumbing in both gfp.h and mempolicy.c. The !NUMA path gains the VM_DROPPABLE -> __GFP_NOWARN check that the NUMA path already had. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/gfp.h | 9 ++------- mm/mempolicy.c | 32 -------------------------------- mm/page_alloc.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 51ef13ed756e..7ccbda35b9ad 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -318,13 +318,13 @@ static inline struct page *alloc_pages_node_noprof(in= t nid, gfp_t gfp_mask, =20 #define alloc_pages_node(...) alloc_hooks(alloc_pages_node_noprof(__VA_= ARGS__)) =20 +struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, + struct vm_area_struct *vma, unsigned long addr); #ifdef CONFIG_NUMA struct page *alloc_pages_noprof(gfp_t gfp, unsigned int order); struct folio *folio_alloc_noprof(gfp_t gfp, unsigned int order); struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int order, struct mempolicy *mpol, pgoff_t ilx, int nid); -struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, struct vm_area_= struct *vma, - unsigned long addr); #else static inline struct page *alloc_pages_noprof(gfp_t gfp_mask, unsigned int= order) { @@ -339,11 +339,6 @@ static inline struct folio *folio_alloc_mpol_noprof(gf= p_t gfp, unsigned int orde { return folio_alloc_noprof(gfp, order); } -static inline struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, - struct vm_area_struct *vma, unsigned long addr) -{ - return folio_alloc_noprof(gfp, order); -} #endif =20 #define alloc_pages(...) alloc_hooks(alloc_pages_noprof(__VA_ARGS__)) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index b2c21ed1fd84..39e556e3d263 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2516,38 +2516,6 @@ struct folio *folio_alloc_mpol_noprof(gfp_t gfp, uns= igned int order, return page_rmappable_folio(page); } =20 -/** - * vma_alloc_folio - Allocate a folio for a VMA. - * @gfp: GFP flags. - * @order: Order of the folio. - * @vma: Pointer to VMA. - * @addr: Virtual address of the allocation. Must be inside @vma. - * - * Allocate a folio for a specific address in @vma, using the appropriate - * NUMA policy. The caller must hold the mmap_lock of the mm_struct of the - * VMA to prevent it from going away. Should be used for all allocations - * for folios that will be mapped into user space, excepting hugetlbfs, and - * excepting where direct use of folio_alloc_mpol() is more appropriate. - * - * Return: The folio on success or NULL if allocation fails. - */ -struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, struct vm_area_= struct *vma, - unsigned long addr) -{ - struct mempolicy *pol; - pgoff_t ilx; - struct folio *folio; - - if (vma->vm_flags & VM_DROPPABLE) - gfp |=3D __GFP_NOWARN; - - pol =3D get_vma_policy(vma, addr, order, &ilx); - folio =3D folio_alloc_mpol_noprof(gfp, order, pol, ilx, numa_node_id()); - mpol_cond_put(pol); - return folio; -} -EXPORT_SYMBOL(vma_alloc_folio_noprof); - struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned order) { struct mempolicy *pol =3D &default_policy; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e40fd39acbd0..4c5610b45de5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5285,6 +5285,49 @@ struct folio *__folio_alloc_noprof(gfp_t gfp, unsign= ed int order, int preferred_ } EXPORT_SYMBOL(__folio_alloc_noprof); =20 +#ifdef CONFIG_NUMA +/** + * vma_alloc_folio - Allocate a folio for a VMA. + * @gfp: GFP flags. + * @order: Order of the folio. + * @vma: Pointer to VMA. + * @addr: Virtual address of the allocation. Must be inside @vma. + * + * Allocate a folio for a specific address in @vma, using the appropriate + * NUMA policy. The caller must hold the mmap_lock of the mm_struct of the + * VMA to prevent it from going away. Should be used for all allocations + * for folios that will be mapped into user space, excepting hugetlbfs, and + * excepting where direct use of folio_alloc_mpol() is more appropriate. + * + * Return: The folio on success or NULL if allocation fails. + */ +struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, + struct vm_area_struct *vma, unsigned long addr) +{ + struct mempolicy *pol; + pgoff_t ilx; + struct folio *folio; + + if (vma->vm_flags & VM_DROPPABLE) + gfp |=3D __GFP_NOWARN; + + pol =3D get_vma_policy(vma, addr, order, &ilx); + folio =3D folio_alloc_mpol_noprof(gfp, order, pol, ilx, numa_node_id()); + mpol_cond_put(pol); + return folio; +} +#else +struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, + struct vm_area_struct *vma, unsigned long addr) +{ + if (vma->vm_flags & VM_DROPPABLE) + gfp |=3D __GFP_NOWARN; + + return folio_alloc_noprof(gfp, order); +} +#endif +EXPORT_SYMBOL(vma_alloc_folio_noprof); + /* * Common helper functions. Never use with __GFP_HIGHMEM because the retur= ned * address cannot represent highmem pages. Use alloc_pages and then kmap if --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 3CF113C7E15 for ; Tue, 12 May 2026 21:05:47 +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=1778619949; cv=none; b=Rw+A/2v4mhGCCMTXCKyG+yimg2DJzO1V9xqDwVk5PLUxLvKxHUWTXze4tnvGpxz3D06IEmub8mTeS1E664W64rhMNp38EoXUpgC7cuolcFk95n394unxF//sdaeyCm98ybLxe7dlqEb57Ym0c4HByOprSfnE5Ch9mheLYuROdN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619949; c=relaxed/simple; bh=K8GHHadzqU10eAhtTtOaSjlQWbKeP4P5PFWOuBR6Aog=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=toXO6i2gVqqmQ4XG3hF/fLQcfmhFkvOy55Pb9GkBuB6UG1z6pSZ6kmqk5kBKgOk/Ghc6qGoiw+EIqPHfhiQ6Ze8QqAxH3eVeXVHY8M0w2TVFcSy+VsGqQdaWv3EyJT9+exp/6Ppkla6N/Tka66kYrlW1fMadDBugugTCtaP860M= 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=c/0lVLFq; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=o3c9CZfW; 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="c/0lVLFq"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="o3c9CZfW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619946; 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=tN2+L1RVKNLEiC6SOal2R5Ri9JooNcSUKgYv9R2PK/Q=; b=c/0lVLFqwHu6L8JoX/1yAvPamFdPam9+2g34LCkV7xHiAXW3nEUQHwXU9B5ucV+fFN4Z0z Ku8lHi6ZxtEZC8/wvibPAvR2z69/JupT2I8pi7OofMVD2gODVaerWfG1qKE7U43gLaHApG Ugv0t64Vu+ecjec65FgTZk7As6oxXWs= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-161-HsIz56n6Og6mmVF4-uWadQ-1; Tue, 12 May 2026 17:05:44 -0400 X-MC-Unique: HsIz56n6Og6mmVF4-uWadQ-1 X-Mimecast-MFC-AGG-ID: HsIz56n6Og6mmVF4-uWadQ_1778619943 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-44a122a5128so4528562f8f.0 for ; Tue, 12 May 2026 14:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619943; x=1779224743; 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=tN2+L1RVKNLEiC6SOal2R5Ri9JooNcSUKgYv9R2PK/Q=; b=o3c9CZfW5ppKVcb2rgQvhi0Z99YzBFbp8Av76HuBUQC7mwloYzCTyGMKNp8R18dGWb icXxdhRjdFOe0bzcijjAtsDMGbcqLj8DlhNtdpKqSYqJ5855cTYOdAG3y/amNKIZp/D4 iEltX77Bc/sEfPmm+iayWQQzLC0GIao1CMmEI29pxpnYxNVP42DLVb4WkNvesy5w1ZmT pzu15tSTEUh/NiaT/iYfu9Y/p4i+5P86zRvMOgJIG72GGEWis0D+PLwonXgfge3Je4Vo R9iOz37TQv2LG3F0DpkJkdqaHWRyI+0VNt8ybBfg7Pc8pGzoKnS3UzVGTzwZbJmYAwXl MvuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619943; x=1779224743; 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=tN2+L1RVKNLEiC6SOal2R5Ri9JooNcSUKgYv9R2PK/Q=; b=ZRP9T/Oy+Mco5S5TBYWSRaiO5vflqbxEXWnG4xscd+8U+8f0b24Ug9bAjOeQ+uNaa5 SXlE28NmFnAiUVcwso5HchLCgpnU1QWw2GdzX2qQwCaf2Lnw+C8wiFI8/nw5nMpeQmzo jnBnU67SVuR+UNNsiXdm9TKTKwOrB9o228RsXF9gE6RaYk2h+xdskCtHKGrS4xKcG7hQ 6bk8J3Kc/Jf+Zw4GvmT4TrxdKK778qVulHuObRUHeTRYpnG+tx5M2iSxIM6ZE5hEqZ5U n9CN6TaJRqLOYCQzpJEtACKu9FRKRopSO1pp69lPOv48IHQZj4L9YiZOgmpVraF+J7ue NM1A== X-Gm-Message-State: AOJu0YzhqqA9+/HZH+JGyWmc1fJ/nyywpAUvRGPfJTpbvFHjd+klCt36 DWqrJmNX8Dh/PxWz+cBg2MgMW40IMOBBPMxxuAepBuxuGHWd5/JaCUc/VT9EKi53AsI3JLcRUsM 9CWHBY3eegzP6zXRyjpKFjsRnQHOvZTjDKJLnthn3PKHx/D64+HEz5RYgFfLJxEdPZrl1N8zjMC OzItfJsxhsNqIe8l0PajgDdCZKp4HM7PEyDbQbVYUrDVU= X-Gm-Gg: Acq92OGTmmC0MVz1NwYpL92ed9e5fGnKs7W/BLR1ml9eIt0eO80Ui+xc42bCtylxFHB UjDUXDjj7IRPKtrZJpS4ddLBFomcNmkhrHqYE6M6XgMHR4LyXBO4Biaf++sFtBgn75h+9XQQJmD H8wvZCHype+nAJO+pCb6OvMjrXi2JwyAR2b4NN2ETm2tPOMREyhEFycQxtQh7mQ+07UneZFrGSl plGPEU8owrcO6QHkaVgdK7QkrE+b98HLUxny7U3ccUwEf5lD6Xkhh9EzSg8DonTjpwqXZV4ZsZX 43Fsv7j2PxJzEq4F8nV/kv7bWnN3iEDuPnNb4sdSK1kJyMwndKu/LO5MrdhixRy3KSM/puDF6WL kt5nXYa/06v+SPRYrt3XVn9OW6r2tqFYWRVmRpopd X-Received: by 2002:a05:6000:310c:b0:441:3144:efc5 with SMTP id ffacd0b85a97d-45c5ac533d1mr457608f8f.42.1778619942922; Tue, 12 May 2026 14:05:42 -0700 (PDT) X-Received: by 2002:a05:6000:310c:b0:441:3144:efc5 with SMTP id ffacd0b85a97d-45c5ac533d1mr457511f8f.42.1778619942032; Tue, 12 May 2026 14:05:42 -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 ffacd0b85a97d-4548e6a6a64sm36428239f8f.6.2026.05.12.14.05.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:05:41 -0700 (PDT) Date: Tue, 12 May 2026 17:05:36 -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 , Jann Horn , Pedro Falcato , Harry Yoo , Hao Li Subject: [PATCH v7 06/31] mm: thread user_addr through page allocator for cache-friendly zeroing Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Thread a user virtual address from vma_alloc_folio() down through the page allocator to post_alloc_hook(). This is plumbing preparation for a subsequent patch that will use user_addr to call folio_zero_user() for cache-friendly zeroing of user pages. The user_addr is stored in struct alloc_context and flows through: vma_alloc_folio -> folio_alloc_mpol -> __alloc_pages_mpol -> __alloc_frozen_pages -> get_page_from_freelist -> prep_new_page -> post_alloc_hook USER_ADDR_NONE ((unsigned long)-1) is used for non-user allocations, since address 0 is a valid userspace mapping. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/gfp.h | 2 +- mm/compaction.c | 5 ++--- mm/hugetlb.c | 36 ++++++++++++++++++++---------------- mm/internal.h | 22 +++++++++++++++++++--- mm/mempolicy.c | 44 ++++++++++++++++++++++++++++++++------------ mm/mmap.c | 6 ++++++ mm/page_alloc.c | 44 +++++++++++++++++++++++++++++--------------- mm/slub.c | 4 ++-- 8 files changed, 111 insertions(+), 52 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 7ccbda35b9ad..ee35c5367abc 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -337,7 +337,7 @@ static inline struct folio *folio_alloc_noprof(gfp_t gf= p, unsigned int order) static inline struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned in= t order, struct mempolicy *mpol, pgoff_t ilx, int nid) { - return folio_alloc_noprof(gfp, order); + return __folio_alloc_noprof(gfp, order, numa_node_id(), NULL); } #endif =20 diff --git a/mm/compaction.c b/mm/compaction.c index 3648ce22c807..72684fe81e83 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -82,7 +82,7 @@ static inline bool is_via_compact_memory(int order) { ret= urn false; } =20 static struct page *mark_allocated_noprof(struct page *page, unsigned int = order, gfp_t gfp_flags) { - post_alloc_hook(page, order, __GFP_MOVABLE); + post_alloc_hook(page, order, __GFP_MOVABLE, USER_ADDR_NONE); set_page_refcounted(page); return page; } @@ -1849,8 +1849,7 @@ static struct folio *compaction_alloc_noprof(struct f= olio *src, unsigned long da set_page_private(&freepage[size], start_order); } dst =3D (struct folio *)freepage; - - post_alloc_hook(&dst->page, order, __GFP_MOVABLE); + post_alloc_hook(&dst->page, order, __GFP_MOVABLE, USER_ADDR_NONE); set_page_refcounted(&dst->page); if (order) prep_compound_page(&dst->page, order); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f24bf49be047..a999f3ead852 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1806,7 +1806,8 @@ struct address_space *hugetlb_folio_mapping_lock_writ= e(struct folio *folio) } =20 static struct folio *alloc_buddy_frozen_folio(int order, gfp_t gfp_mask, - int nid, nodemask_t *nmask, nodemask_t *node_alloc_noretry) + int nid, nodemask_t *nmask, nodemask_t *node_alloc_noretry, + unsigned long addr) { struct folio *folio; bool alloc_try_hard =3D true; @@ -1823,7 +1824,7 @@ static struct folio *alloc_buddy_frozen_folio(int ord= er, gfp_t gfp_mask, if (alloc_try_hard) gfp_mask |=3D __GFP_RETRY_MAYFAIL; =20 - folio =3D (struct folio *)__alloc_frozen_pages(gfp_mask, order, nid, nmas= k); + folio =3D (struct folio *)__alloc_frozen_pages(gfp_mask, order, nid, nmas= k, addr); =20 /* * If we did not specify __GFP_RETRY_MAYFAIL, but still got a @@ -1852,7 +1853,7 @@ static struct folio *alloc_buddy_frozen_folio(int ord= er, gfp_t gfp_mask, =20 static struct folio *only_alloc_fresh_hugetlb_folio(struct hstate *h, gfp_t gfp_mask, int nid, nodemask_t *nmask, - nodemask_t *node_alloc_noretry) + nodemask_t *node_alloc_noretry, unsigned long addr) { struct folio *folio; int order =3D huge_page_order(h); @@ -1864,7 +1865,7 @@ static struct folio *only_alloc_fresh_hugetlb_folio(s= truct hstate *h, folio =3D alloc_gigantic_frozen_folio(order, gfp_mask, nid, nmask); else folio =3D alloc_buddy_frozen_folio(order, gfp_mask, nid, nmask, - node_alloc_noretry); + node_alloc_noretry, addr); if (folio) init_new_hugetlb_folio(folio); return folio; @@ -1878,11 +1879,12 @@ static struct folio *only_alloc_fresh_hugetlb_folio= (struct hstate *h, * pages is zero, and the accounting must be done in the caller. */ static struct folio *alloc_fresh_hugetlb_folio(struct hstate *h, - gfp_t gfp_mask, int nid, nodemask_t *nmask) + gfp_t gfp_mask, int nid, nodemask_t *nmask, + unsigned long addr) { struct folio *folio; =20 - folio =3D only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, NULL); + folio =3D only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, NULL, a= ddr); if (folio) hugetlb_vmemmap_optimize_folio(h, folio); return folio; @@ -1922,7 +1924,7 @@ static struct folio *alloc_pool_huge_folio(struct hst= ate *h, struct folio *folio; =20 folio =3D only_alloc_fresh_hugetlb_folio(h, gfp_mask, node, - nodes_allowed, node_alloc_noretry); + nodes_allowed, node_alloc_noretry, USER_ADDR_NONE); if (folio) return folio; } @@ -2091,7 +2093,8 @@ int dissolve_free_hugetlb_folios(unsigned long start_= pfn, unsigned long end_pfn) * Allocates a fresh surplus page from the page allocator. */ static struct folio *alloc_surplus_hugetlb_folio(struct hstate *h, - gfp_t gfp_mask, int nid, nodemask_t *nmask) + gfp_t gfp_mask, int nid, nodemask_t *nmask, + unsigned long addr) { struct folio *folio =3D NULL; =20 @@ -2103,7 +2106,7 @@ static struct folio *alloc_surplus_hugetlb_folio(stru= ct hstate *h, goto out_unlock; spin_unlock_irq(&hugetlb_lock); =20 - folio =3D alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask); + folio =3D alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, addr); if (!folio) return NULL; =20 @@ -2146,7 +2149,7 @@ static struct folio *alloc_migrate_hugetlb_folio(stru= ct hstate *h, gfp_t gfp_mas if (hstate_is_gigantic(h)) return NULL; =20 - folio =3D alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask); + folio =3D alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, USER_ADDR_NO= NE); if (!folio) return NULL; =20 @@ -2182,14 +2185,14 @@ struct folio *alloc_buddy_hugetlb_folio_with_mpol(s= truct hstate *h, if (mpol_is_preferred_many(mpol)) { gfp_t gfp =3D gfp_mask & ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL); =20 - folio =3D alloc_surplus_hugetlb_folio(h, gfp, nid, nodemask); + folio =3D alloc_surplus_hugetlb_folio(h, gfp, nid, nodemask, addr); =20 /* Fallback to all nodes if page=3D=3DNULL */ nodemask =3D NULL; } =20 if (!folio) - folio =3D alloc_surplus_hugetlb_folio(h, gfp_mask, nid, nodemask); + folio =3D alloc_surplus_hugetlb_folio(h, gfp_mask, nid, nodemask, addr); mpol_cond_put(mpol); return folio; } @@ -2296,7 +2299,8 @@ static int gather_surplus_pages(struct hstate *h, lon= g delta) * down the road to pick the current node if that is the case. */ folio =3D alloc_surplus_hugetlb_folio(h, htlb_alloc_mask(h), - NUMA_NO_NODE, &alloc_nodemask); + NUMA_NO_NODE, &alloc_nodemask, + USER_ADDR_NONE); if (!folio) { alloc_ok =3D false; break; @@ -2702,7 +2706,7 @@ static int alloc_and_dissolve_hugetlb_folio(struct fo= lio *old_folio, spin_unlock_irq(&hugetlb_lock); gfp_mask =3D htlb_alloc_mask(h) | __GFP_THISNODE; new_folio =3D alloc_fresh_hugetlb_folio(h, gfp_mask, - nid, NULL); + nid, NULL, USER_ADDR_NONE); if (!new_folio) return -ENOMEM; goto retry; @@ -3400,13 +3404,13 @@ static void __init hugetlb_hstate_alloc_pages_oneno= de(struct hstate *h, int nid) gfp_t gfp_mask =3D htlb_alloc_mask(h) | __GFP_THISNODE; =20 folio =3D only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, - &node_states[N_MEMORY], NULL); + &node_states[N_MEMORY], NULL, USER_ADDR_NONE); if (!folio && !list_empty(&folio_list) && hugetlb_vmemmap_optimizable_size(h)) { prep_and_add_allocated_folios(h, &folio_list); INIT_LIST_HEAD(&folio_list); folio =3D only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, - &node_states[N_MEMORY], NULL); + &node_states[N_MEMORY], NULL, USER_ADDR_NONE); } if (!folio) break; diff --git a/mm/internal.h b/mm/internal.h index 5a2ddcf68e0b..389098200aa6 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -662,6 +662,16 @@ void calculate_min_free_kbytes(void); int __meminit init_per_zone_wmark_min(void); void page_alloc_sysctl_init(void); =20 +/* + * Sentinel for user_addr: indicates a non-user allocation. + * Cannot use 0 because address 0 is a valid userspace mapping. + * (unsigned long)-1 is safe because: + * 1. vm_end =3D addr + len <=3D TASK_SIZE, and vm_end is exclusive, + * so -1 is never inside any VMA. + * 2. It will only be compared to page-aligned addresses. + */ +#define USER_ADDR_NONE ((unsigned long)-1) + /* * Structure for holding the mostly immutable allocation parameters passed * between functions involved in allocations, including the alloc_pages* @@ -693,6 +703,7 @@ struct alloc_context { */ enum zone_type highest_zoneidx; bool spread_dirty_pages; + unsigned long user_addr; }; =20 /* @@ -916,24 +927,29 @@ static inline void init_compound_tail(struct page *ta= il, prep_compound_tail(tail, head, order); } =20 -void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flag= s); +void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flag= s, + unsigned long user_addr); extern bool free_pages_prepare(struct page *page, unsigned int order); =20 extern int user_min_free_kbytes; =20 struct page *__alloc_frozen_pages_noprof(gfp_t, unsigned int order, int ni= d, - nodemask_t *); + nodemask_t *, unsigned long user_addr); #define __alloc_frozen_pages(...) \ alloc_hooks(__alloc_frozen_pages_noprof(__VA_ARGS__)) void free_frozen_pages(struct page *page, unsigned int order); +void free_frozen_pages_zeroed(struct page *page, unsigned int order); void free_unref_folios(struct folio_batch *fbatch); =20 #ifdef CONFIG_NUMA struct page *alloc_frozen_pages_noprof(gfp_t, unsigned int order); +struct folio *folio_alloc_mpol_user_noprof(gfp_t gfp, unsigned int order, + struct mempolicy *pol, pgoff_t ilx, int nid, + unsigned long user_addr); #else static inline struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned i= nt order) { - return __alloc_frozen_pages_noprof(gfp, order, numa_node_id(), NULL); + return __alloc_frozen_pages_noprof(gfp, order, numa_node_id(), NULL, USER= _ADDR_NONE); } #endif =20 diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 39e556e3d263..ea3043e0075b 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2413,7 +2413,8 @@ bool mempolicy_in_oom_domain(struct task_struct *tsk, } =20 static struct page *alloc_pages_preferred_many(gfp_t gfp, unsigned int ord= er, - int nid, nodemask_t *nodemask) + int nid, nodemask_t *nodemask, + unsigned long user_addr) { struct page *page; gfp_t preferred_gfp; @@ -2426,25 +2427,29 @@ static struct page *alloc_pages_preferred_many(gfp_= t gfp, unsigned int order, */ preferred_gfp =3D gfp | __GFP_NOWARN; preferred_gfp &=3D ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL); - page =3D __alloc_frozen_pages_noprof(preferred_gfp, order, nid, nodemask); + page =3D __alloc_frozen_pages_noprof(preferred_gfp, order, nid, + nodemask, user_addr); if (!page) - page =3D __alloc_frozen_pages_noprof(gfp, order, nid, NULL); + page =3D __alloc_frozen_pages_noprof(gfp, order, nid, NULL, + user_addr); =20 return page; } =20 /** - * alloc_pages_mpol - Allocate pages according to NUMA mempolicy. + * __alloc_pages_mpol - Allocate pages according to NUMA mempolicy. * @gfp: GFP flags. * @order: Order of the page allocation. * @pol: Pointer to the NUMA mempolicy. * @ilx: Index for interleave mempolicy (also distinguishes alloc_pages()). * @nid: Preferred node (usually numa_node_id() but @mpol may override it). + * @user_addr: User fault address for cache-friendly zeroing, or USER_ADDR= _NONE. * * Return: The page on success or NULL if allocation fails. */ -static struct page *alloc_pages_mpol(gfp_t gfp, unsigned int order, - struct mempolicy *pol, pgoff_t ilx, int nid) +static struct page *__alloc_pages_mpol(gfp_t gfp, unsigned int order, + struct mempolicy *pol, pgoff_t ilx, int nid, + unsigned long user_addr) { nodemask_t *nodemask; struct page *page; @@ -2452,7 +2457,8 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsig= ned int order, nodemask =3D policy_nodemask(gfp, pol, ilx, &nid); =20 if (pol->mode =3D=3D MPOL_PREFERRED_MANY) - return alloc_pages_preferred_many(gfp, order, nid, nodemask); + return alloc_pages_preferred_many(gfp, order, nid, nodemask, + user_addr); =20 if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && /* filter "hugepage" allocation, unless from alloc_pages() */ @@ -2476,7 +2482,7 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsig= ned int order, */ page =3D __alloc_frozen_pages_noprof( gfp | __GFP_THISNODE | __GFP_NORETRY, order, - nid, NULL); + nid, NULL, user_addr); if (page || !(gfp & __GFP_DIRECT_RECLAIM)) return page; /* @@ -2488,7 +2494,7 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsig= ned int order, } } =20 - page =3D __alloc_frozen_pages_noprof(gfp, order, nid, nodemask); + page =3D __alloc_frozen_pages_noprof(gfp, order, nid, nodemask, user_addr= ); =20 if (unlikely(pol->mode =3D=3D MPOL_INTERLEAVE || pol->mode =3D=3D MPOL_WEIGHTED_INTERLEAVE) && page) { @@ -2504,11 +2510,18 @@ static struct page *alloc_pages_mpol(gfp_t gfp, uns= igned int order, return page; } =20 -struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int order, +static struct page *alloc_pages_mpol(gfp_t gfp, unsigned int order, struct mempolicy *pol, pgoff_t ilx, int nid) { - struct page *page =3D alloc_pages_mpol(gfp | __GFP_COMP, order, pol, - ilx, nid); + return __alloc_pages_mpol(gfp, order, pol, ilx, nid, USER_ADDR_NONE); +} + +struct folio *folio_alloc_mpol_user_noprof(gfp_t gfp, unsigned int order, + struct mempolicy *pol, pgoff_t ilx, int nid, + unsigned long user_addr) +{ + struct page *page =3D __alloc_pages_mpol(gfp | __GFP_COMP, order, pol, + ilx, nid, user_addr); if (!page) return NULL; =20 @@ -2516,6 +2529,13 @@ struct folio *folio_alloc_mpol_noprof(gfp_t gfp, uns= igned int order, return page_rmappable_folio(page); } =20 +struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int order, + struct mempolicy *pol, pgoff_t ilx, int nid) +{ + return folio_alloc_mpol_user_noprof(gfp, order, pol, ilx, nid, + USER_ADDR_NONE); +} + struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned order) { struct mempolicy *pol =3D &default_policy; diff --git a/mm/mmap.c b/mm/mmap.c index 5754d1c36462..73413cebc418 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -855,6 +855,12 @@ __get_unmapped_area(struct file *file, unsigned long a= ddr, unsigned long len, if (IS_ERR_VALUE(addr)) return addr; =20 + /* + * The check below ensures vm_end =3D addr + len <=3D TASK_SIZE. + * Since (unsigned long)-1 (USER_ADDR_NONE) >=3D TASK_SIZE and + * vm_end is exclusive, USER_ADDR_NONE is thus never a valid + * userspace address. + */ if (addr > TASK_SIZE - len) return -ENOMEM; if (offset_in_page(addr)) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 4c5610b45de5..8c673095c11f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1816,7 +1816,7 @@ static inline bool should_skip_init(gfp_t flags) } =20 inline void post_alloc_hook(struct page *page, unsigned int order, - gfp_t gfp_flags) + gfp_t gfp_flags, unsigned long user_addr) { bool init =3D !want_init_on_free() && want_init_on_alloc(gfp_flags) && !should_skip_init(gfp_flags); @@ -1871,9 +1871,10 @@ inline void post_alloc_hook(struct page *page, unsig= ned int order, } =20 static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp= _flags, - unsigned int alloc_flags) + unsigned int alloc_flags, + unsigned long user_addr) { - post_alloc_hook(page, order, gfp_flags); + post_alloc_hook(page, order, gfp_flags, user_addr); =20 if (order && (gfp_flags & __GFP_COMP)) prep_compound_page(page, order); @@ -3955,7 +3956,8 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int o= rder, int alloc_flags, page =3D rmqueue(zonelist_zone(ac->preferred_zoneref), zone, order, gfp_mask, alloc_flags, ac->migratetype); if (page) { - prep_new_page(page, order, gfp_mask, alloc_flags); + prep_new_page(page, order, gfp_mask, alloc_flags, + ac->user_addr); =20 return page; } else { @@ -4183,7 +4185,8 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned= int order, =20 /* Prep a captured page if available */ if (page) - prep_new_page(page, order, gfp_mask, alloc_flags); + prep_new_page(page, order, gfp_mask, alloc_flags, + ac->user_addr); =20 /* Try get a page from the freelist if available */ if (!page) @@ -5060,7 +5063,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int = preferred_nid, struct zoneref *z; struct per_cpu_pages *pcp; struct list_head *pcp_list; - struct alloc_context ac; + struct alloc_context ac =3D { .user_addr =3D USER_ADDR_NONE }; gfp_t alloc_gfp; unsigned int alloc_flags =3D ALLOC_WMARK_LOW; int nr_populated =3D 0, nr_account =3D 0; @@ -5175,7 +5178,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int = preferred_nid, } nr_account++; =20 - prep_new_page(page, 0, gfp, 0); + prep_new_page(page, 0, gfp, 0, USER_ADDR_NONE); set_page_refcounted(page); page_array[nr_populated++] =3D page; } @@ -5200,12 +5203,13 @@ EXPORT_SYMBOL_GPL(alloc_pages_bulk_noprof); * This is the 'heart' of the zoned buddy allocator. */ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, - int preferred_nid, nodemask_t *nodemask) + int preferred_nid, nodemask_t *nodemask, + unsigned long user_addr) { struct page *page; unsigned int alloc_flags =3D ALLOC_WMARK_LOW; gfp_t alloc_gfp; /* The gfp_t that was actually used for allocation */ - struct alloc_context ac =3D { }; + struct alloc_context ac =3D { .user_addr =3D user_addr }; =20 /* * There are several places where we assume that the order value is sane @@ -5266,10 +5270,12 @@ EXPORT_SYMBOL(__alloc_frozen_pages_noprof); =20 struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, int preferred_nid, nodemask_t *nodemask) + { struct page *page; =20 - page =3D __alloc_frozen_pages_noprof(gfp, order, preferred_nid, nodemask); + page =3D __alloc_frozen_pages_noprof(gfp, order, preferred_nid, + nodemask, USER_ADDR_NONE); if (page) set_page_refcounted(page); return page; @@ -5312,7 +5318,8 @@ struct folio *vma_alloc_folio_noprof(gfp_t gfp, int o= rder, gfp |=3D __GFP_NOWARN; =20 pol =3D get_vma_policy(vma, addr, order, &ilx); - folio =3D folio_alloc_mpol_noprof(gfp, order, pol, ilx, numa_node_id()); + folio =3D folio_alloc_mpol_user_noprof(gfp, order, pol, ilx, + numa_node_id(), addr); mpol_cond_put(pol); return folio; } @@ -5320,10 +5327,17 @@ struct folio *vma_alloc_folio_noprof(gfp_t gfp, int= order, struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, struct vm_area_struct *vma, unsigned long addr) { + struct page *page; + if (vma->vm_flags & VM_DROPPABLE) gfp |=3D __GFP_NOWARN; =20 - return folio_alloc_noprof(gfp, order); + page =3D __alloc_frozen_pages_noprof(gfp | __GFP_COMP, order, + numa_node_id(), NULL, addr); + if (!page) + return NULL; + set_page_refcounted(page); + return page_rmappable_folio(page); } #endif EXPORT_SYMBOL(vma_alloc_folio_noprof); @@ -6904,7 +6918,7 @@ static void split_free_frozen_pages(struct list_head = *list, gfp_t gfp_mask) list_for_each_entry_safe(page, next, &list[order], lru) { int i; =20 - post_alloc_hook(page, order, gfp_mask); + post_alloc_hook(page, order, gfp_mask, USER_ADDR_NONE); if (!order) continue; =20 @@ -7110,7 +7124,7 @@ int alloc_contig_frozen_range_noprof(unsigned long st= art, unsigned long end, struct page *head =3D pfn_to_page(start); =20 check_new_pages(head, order); - prep_new_page(head, order, gfp_mask, 0); + prep_new_page(head, order, gfp_mask, 0, USER_ADDR_NONE); } else { ret =3D -EINVAL; WARN(true, "PFN range: requested [%lu, %lu), allocated [%lu, %lu)\n", @@ -7775,7 +7789,7 @@ struct page *alloc_frozen_pages_nolock_noprof(gfp_t g= fp_flags, int nid, unsigned gfp_t alloc_gfp =3D __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC | __GFP_= COMP | gfp_flags; unsigned int alloc_flags =3D ALLOC_TRYLOCK; - struct alloc_context ac =3D { }; + struct alloc_context ac =3D { .user_addr =3D USER_ADDR_NONE }; struct page *page; =20 VM_WARN_ON_ONCE(gfp_flags & ~__GFP_ACCOUNT); diff --git a/mm/slub.c b/mm/slub.c index 0baa906f39ab..74dd2d96941b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3275,7 +3275,7 @@ static inline struct slab *alloc_slab_page(gfp_t flag= s, int node, else if (node =3D=3D NUMA_NO_NODE) page =3D alloc_frozen_pages(flags, order); else - page =3D __alloc_frozen_pages(flags, order, node, NULL); + page =3D __alloc_frozen_pages(flags, order, node, NULL, USER_ADDR_NONE); =20 if (!page) return NULL; @@ -5235,7 +5235,7 @@ static void *___kmalloc_large_node(size_t size, gfp_t= flags, int node) if (node =3D=3D NUMA_NO_NODE) page =3D alloc_frozen_pages_noprof(flags, order); else - page =3D __alloc_frozen_pages_noprof(flags, order, node, NULL); + page =3D __alloc_frozen_pages_noprof(flags, order, node, NULL, USER_ADDR= _NONE); =20 if (page) { ptr =3D page_address(page); --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 AB3543C1978 for ; Tue, 12 May 2026 21:05:53 +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=1778619955; cv=none; b=nb1kJQDeZvt5GHU+n0V0LzFo3RjK+RRldTwzRhlEUXDeZU4LfiVQZkh1jBFbnttQEhgdeDt71TYjSk9R9Bd0E3drtSnyYmDhSXe32dgDT969kUTrXpWdaDCpNERGr0p7r28t21Du4CxLOYUT6NkcZm9sznau4kVoQilxRbi+Uug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619955; c=relaxed/simple; bh=69QG+5KxbknuqowgRzIPAH0Udu09EBE3lvMvWnTXBmg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XbhxvpGGISO6QEwxN9bRQJkptDf/RLb9FP/5gMLUYEyJmtmQ2VsyHFS8JA2z9Y9Sllr2Xaes9W+36yUEXdusa/i87dx8m7jJNEdOEwYYoCfR8E0QmONKRy0jX2RH6REa+Q4RoJ5jGqe0Iwjh/0AO5t+kXH5y/smysLF+N1qj+QI= 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=Lt3SWq6t; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=aN3U3kz9; 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="Lt3SWq6t"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="aN3U3kz9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619952; 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=6dawd7eS61o9/4A+PK33L87yl5/YoiTuIytB/tOyfis=; b=Lt3SWq6tlaBB67aVcMuGqg8zT3mvD/Uo4YfdgzwIOJwz2vnW8RNOk+U0L7nsOHTr7VfjSW 4TC2CxQ/MFoEOZrtlREISyINuZSWCFwhMSkzeujNjs79tVNyzdmWUn+7aUFPAm70+TAbAQ puhItoLHkP3NhTDXFiyRSSrAtZa8nNQ= 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-372-yXS1PNTaMWWtMuHWegcECg-1; Tue, 12 May 2026 17:05:51 -0400 X-MC-Unique: yXS1PNTaMWWtMuHWegcECg-1 X-Mimecast-MFC-AGG-ID: yXS1PNTaMWWtMuHWegcECg_1778619950 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-48e89faa62eso11467305e9.1 for ; Tue, 12 May 2026 14:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619950; x=1779224750; 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=6dawd7eS61o9/4A+PK33L87yl5/YoiTuIytB/tOyfis=; b=aN3U3kz9NumhOTvrnegYYPDcVhQdR+9evIc3NVSDcIWYJBOghZivF3ybT/jEQQ1o0G ItKSbo36D82EP0x7A3N6nZb5JI6gHdr7jEtlLJw4Vy27ApWykWsRPNFnsVQEgc8ZtKxM MHtLxiDYhi7jupqhDGHsS7zb0sbmum2ySvsVkV+L8CfVsWH7PVOA1oJlQlWWcSF2Ns6R 3WYazoPAezlKkUPIyUYoCFz5H1dRlKtuHSfK1wrMfpUOccrf5u6OqzM64QsCUU2SkpZw N0ZovcKuOC/TuDQdSEQxNLh+IpRc0RBB6ema2JMXJ/MJzVZNGmXFVrvndRLUPNKWTtlk vppw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619950; x=1779224750; 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=6dawd7eS61o9/4A+PK33L87yl5/YoiTuIytB/tOyfis=; b=UCwXQUfeX72K75VfrdC44zQEEnyLeu6kKHQ8h4lyh7PWxsf2WMKtTsG5dz065geo1H o+BzOUfBlRzAi7Ag6gIWrppdkEF2gb0rLtvuai8iWJhT91MNTyU4vf/fTA1QMIHvY1H2 gT2oJ86gVlWZgaRm5SilMUosyhLg5v3Elty8dIg2TR24QImku038zyVxEjwCVaALHPLd z+Is08q8E/HW6ndgJOc7es7/5BeRILQi1juxZ6PK8LAdt1OVTlEogtT4Rq6Qe7QdtYoC dtuvck1Xek4quiAYS70CwkhDaZTfLxfpEq9hd1CjYjgHMSczge+I/UUdGCMuE8Le2Mct SfyQ== X-Gm-Message-State: AOJu0Yw/nnW5/1nlbmmEUBXAvNf1BJ6kuTxBNOvwVlaMYl2ZSIAQglsK VTjI2jdB5zjQ3AFdf720KfbUobG1CQ+2WUPcNHtR2xT+V9acVZH6WtvrnwQyAYx9XSIRB+bzuOH OFdKzj4oN4EmS16LWzWDDmiQQGBGar67wdSheG4AyCGzrctxA+TV9ntMyAq8Noh+XjE6I8NMkqU lgMaeXyQXyy6w0ZvSOTaX6PQIHXifNffRQMzYpQ1dcI5o= X-Gm-Gg: Acq92OGa1roCarXpVCz9GxINg8KxVFHUAg1eDNO0ZLKTanUt3bTpRqTdkv8UYM7NBJ3 /PtBg3Thrkt3MaAKhmIl82gLTPngQeqdZs8E//mVW4SSeiF63u4qUg1Zweux6mH4IdfUGI+2fWf 42G+CLy/kJdv3wnB536hp/JlESkpi611EHyJfTO1G9XXbEoEYZ66Zo9aybFrSEHkNrQpHyysYHc tlkb28C6YVZ96nfUFnJfRjFFR5aaSM2CBmXvRe54txOQsIcakAd4T+TpMKic7GHVJf1nmaoKIhQ VFjMgEWDC5mxWasObeKffDrObRqw6Q8BDvbzCKEsYVI3x/FJZtSh80VvaFpuftXtzeQ1hSuO06J XN2pX6/nzoC5+r0a+lo478ndDex9C9sT4tzSf9xg2 X-Received: by 2002:a05:600c:859c:b0:48a:53ea:1408 with SMTP id 5b1f17b1804b1-48fc9a09e36mr4382215e9.8.1778619949609; Tue, 12 May 2026 14:05:49 -0700 (PDT) X-Received: by 2002:a05:600c:859c:b0:48a:53ea:1408 with SMTP id 5b1f17b1804b1-48fc9a09e36mr4381535e9.8.1778619948841; Tue, 12 May 2026 14:05:48 -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-48e8f4247fasm36415055e9.9.2026.05.12.14.05.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:05:47 -0700 (PDT) Date: Tue, 12 May 2026 17:05:42 -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 v7 07/31] mm: add folio_zero_user stub for configs without THP/HUGETLBFS Message-ID: <08b9139bf2329eb7fbc2b2af02d9537219282cec.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" folio_zero_user() is defined in mm/memory.c under CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS. A subsequent patch will call it from post_alloc_hook() for all user page zeroing, so configs without THP or HUGETLBFS will need a stub. Add a macro in the #else branch that falls back to clear_user_highpages(), which handles cache aliasing correctly on VIPT architectures and is always available via highmem.h. Without THP/HUGETLBFS, only order-0 user pages are allocated, so the locality optimization in the real folio_zero_user() (zero near the faulting address last) is not needed. This also matches what vma_alloc_zeroed_movable_folio currently does. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/mm.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index af23453e9dbd..3b1ca90fd435 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -5070,6 +5070,9 @@ long copy_folio_from_user(struct folio *dst_folio, const void __user *usr_src, bool allow_pagefault); =20 +#else /* !CONFIG_TRANSPARENT_HUGEPAGE && !CONFIG_HUGETLBFS */ +#define folio_zero_user(folio, addr_hint) \ + clear_user_highpages(&(folio)->page, (addr_hint), folio_nr_pages(folio)) #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */ =20 #if MAX_NUMNODES > 1 --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 E16BA3C1978 for ; Tue, 12 May 2026 21:05:59 +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=1778619961; cv=none; b=MV9nlxxy5h2L2kerDTnJA2gtYsm/LF3R7+UvPP6mSmKvZ++p5zVxwlZ1hdGJpDO35eRMdSUwUvXLBw27t1cXiqvhGEPvTmLOUaGac2cDU9BCnd5sCC5nTL8RNrQVm9HiVd8HHTlcWdouPARoLPa6mYkRzTlVCbY4Tq/Xf8QJuSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619961; c=relaxed/simple; bh=qfAiB4Mi7HiE1t/8STINyzikxWNwc1bX9dNw7SeomIA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XBOWDRuaGLxlAFcvj78FZ66aynoHY5rpbqpqCZm2Av25cF9RJC2ZFJZ1Hil6iavKA+y+jzMQcpplJjc+lOrQoqQ1mi03m8UVwKDKB7XNnnOFFtiirYO0dGo0/pfkPyA3t9/xcA844urSkGuqH/FPgnND3av/pp+KEMWI+GnuJZI= 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=fySg5UL6; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=eaihUH2X; 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="fySg5UL6"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="eaihUH2X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619959; 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=ScNqY6XGVTvavY3RuaxUGlH8VyMDuF0XI3V7nGekON0=; b=fySg5UL6vojOnk+aa1XzN6fvMTUSNkduRlkS/1bRklLSImVwCNS6oYxCyUa0dgEF6njuVd GLAQWuKLpLJoc5wNfVokyVL4bdUdV5mKzKKMfQIrNrziOEkGb6grrmB28fQQAsBkMfNZbY Vu2a+Udwb8T5TuJ/KLbAgRDB9IhQq3I= 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-465-FVJlKSlfN6GeStOwvfVOmQ-1; Tue, 12 May 2026 17:05:56 -0400 X-MC-Unique: FVJlKSlfN6GeStOwvfVOmQ-1 X-Mimecast-MFC-AGG-ID: FVJlKSlfN6GeStOwvfVOmQ_1778619955 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48e6af7a9cdso31232535e9.3 for ; Tue, 12 May 2026 14:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619955; x=1779224755; 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=ScNqY6XGVTvavY3RuaxUGlH8VyMDuF0XI3V7nGekON0=; b=eaihUH2X1LdQvQm8PAKa2mWJ4ip9vVULjmpaXjtZNsNzC9MPl+DIB7e3KaiQFyY1kd 5M1ptfWuaEihU/LoMHO/5iLkibxZx8YGWuFAilNdH4A0+DGu2Vi3GGHqAbHorAprLDxM Y8Ivly7Fmcr3iv7cZRZ5xJm9jJ5BJ1SimRbcc+Lhi/JqO+/aHdYCLJhHY29MIjFN36Aj S1JudS5WCtFGBFT9OctXcsiUoAp0bJbD0ycGKSyF0BxZtp6Jqi2EQUpAe8pGWzAcC/CL wH733cLjw96XLMEDn1hZPh+NNDLuAnaEXEpug6w179ZUGIpBKzGynAQgUrAVf3DEjIRp W3QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619955; x=1779224755; 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=ScNqY6XGVTvavY3RuaxUGlH8VyMDuF0XI3V7nGekON0=; b=iN8o6X8oPD0xi1CU165DqDvZWXwgmrWT5hJit56tbm49UVYTVV5QS2sSdpkX7DOtG/ xNFj9jscdAL3CHEZsW0Y1+p4pCfKyGFDOGwnBaFNPJ7TGFdFpAf7fDmYVE5s1muTvBt/ zUnsHw7j2T2fogxPC9OowUNubwmSVStG53D8aqGbU0DYn18dvmbGglFJ+wVyqHaYlfw/ Ab+naw/Le1zf5MA9Tv4C+fO3M7Y2VjM/7uZ1EkzE1AdMPQKQKqgr4cqdXh1c2aqrgaUY fRWgm+x3Fi//jda4O0txc0CBFRpmxhYInYN/e4pfN8MutYH0YNPsGhnZrTRLdk9qzBTu Apww== X-Gm-Message-State: AOJu0YwVMSk0rlK33tySPfsxEhXYSJxNAHZrkJbGqiBnjY12GZFmhNH4 E74tNg/v1p1sdd7piI3/ucNALnkcnlGWxwhT1uIO1QvY6ZzqcWrqZqttqtscSF7TF9Ow3pz5Yik 0+jnZOv5Km0W2G9bzhHPee7rpzeTwtwEhJnR96e3EiAxVV7Ri46g34EMTL/WBEIzCgDlCvHr+Zf GWgcXAJYaHK3FDncicDrZRgDI9urIinh89feeda/1wUyA= X-Gm-Gg: Acq92OE5Ebgv37NsNlOd9hB84hEdO9pfGAMlXUVkR1aE5vdeaLYHfF1All14wMk2zsI hdH63bGEW65Hd9vLuBzw1n7sWsEC4zZO2HbL9GEykx0gd0HpEynWL0ADxQvO3dARoMEWm0z5XR7 pe7lVnoXynfYzjZKhkQUe3s6rI/sqKANsu/fWbMfvD79z2K8C0MXomzQCgZjIRSF+ls+tWjf3BI Y9X6NTj3mU6+E6A7epCY5rtOi+EccCIQL71/BEtDIeVXSBiYRB6voKQbnz+1TK0smdB9vkHX5Uc 0iJ79sMHqsmj2PyCRFTHzOeo0IZ2oa7mv08pc2FgcmUpNOsr4W39H6xWpbwoi89/GhbVjcyNwVd 0fzxb4JhEBba/YwaluiDNdyxMgOo9RUeYk7ywlegP X-Received: by 2002:a05:600c:8b56:b0:48a:599a:3716 with SMTP id 5b1f17b1804b1-48fc9a45891mr5020095e9.23.1778619954969; Tue, 12 May 2026 14:05:54 -0700 (PDT) X-Received: by 2002:a05:600c:8b56:b0:48a:599a:3716 with SMTP id 5b1f17b1804b1-48fc9a45891mr5019335e9.23.1778619954287; Tue, 12 May 2026 14:05:54 -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-48e8f429fdfsm24854985e9.15.2026.05.12.14.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:05:53 -0700 (PDT) Date: Tue, 12 May 2026 17:05:49 -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 v7 08/31] mm: page_alloc: move prep_compound_page before post_alloc_hook Message-ID: <71a446816276ef01ce6dde104c4a44993c07e6e5.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move prep_compound_page() before post_alloc_hook() in prep_new_page(). The next patch adds a folio_zero_user() call to post_alloc_hook(), which uses folio_nr_pages() to determine how many pages to zero. Without compound metadata set up first, folio_nr_pages() returns 1 for higher-order allocations, so only the first page would be zeroed. All other operations in post_alloc_hook() (arch_alloc_page, KASAN, debug, page owner, etc.) use raw page pointers with explicit order counts and are unaffected by this reordering. Also reorder compaction_alloc_noprof() for consistency. Compaction currently passes USER_ADDR_NONE so folio_zero_user() is not called there, but keeping the same ordering avoids a future tripping hazard. Reviewed-by: Gregory Price Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- mm/compaction.c | 4 ++-- mm/page_alloc.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 72684fe81e83..4336e433c99b 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1849,10 +1849,10 @@ static struct folio *compaction_alloc_noprof(struct= folio *src, unsigned long da set_page_private(&freepage[size], start_order); } dst =3D (struct folio *)freepage; - post_alloc_hook(&dst->page, order, __GFP_MOVABLE, USER_ADDR_NONE); - set_page_refcounted(&dst->page); if (order) prep_compound_page(&dst->page, order); + post_alloc_hook(&dst->page, order, __GFP_MOVABLE, USER_ADDR_NONE); + set_page_refcounted(&dst->page); cc->nr_freepages -=3D 1 << order; cc->nr_migratepages -=3D 1 << order; return page_rmappable_folio(&dst->page); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 8c673095c11f..db387dd6b813 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1874,11 +1874,11 @@ static void prep_new_page(struct page *page, unsign= ed int order, gfp_t gfp_flags unsigned int alloc_flags, unsigned long user_addr) { - post_alloc_hook(page, order, gfp_flags, user_addr); - if (order && (gfp_flags & __GFP_COMP)) prep_compound_page(page, order); =20 + post_alloc_hook(page, order, gfp_flags, user_addr); + /* * page is set pfmemalloc when ALLOC_NO_WATERMARKS was necessary to * allocate the page. The expectation is that the caller is taking --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 ECA653C9893 for ; Tue, 12 May 2026 21:06:06 +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=1778619968; cv=none; b=iGOUiqDXoW6ctmkjjPwILU3CuAJDHB4cV9SIGC6+MSpLHPXDj0naM9srgobiXiZMC3rGsnvHiZF1sJoL8Zp2kjVCXlY7Uu6rU6ZNDx7A4+J/6gYbvFmNzbGmjIof7FI1KLIUgFv4a1R/sNkBK8wBkSz693D836gScvAHqPyze5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619968; c=relaxed/simple; bh=26OEPP7shIS2Aqo5H6bSRXYq6BtKNsY+s1121au6t2U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=W/KTYExaBsJPU9aGuE7S9JWQovL7ulhIo6KMEcjgNIqApe05LEYnHswhj/TtN9JYKEaYp5na3RpXnZtVWLrop+UgEbvfwiA5LFvwQSe8QX+9jRrxg1jkHB9uQXZdjaPo7flrkAVQueSUUX7l5KOtY0MVsGqiLUC1295eSvFdU/Q= 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=CFftqznb; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q1x3wzTy; 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="CFftqznb"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q1x3wzTy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619966; 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=fHWjppoupYJq6gg1bmhomqZmsJDzmE/Zol9ZNgufzks=; b=CFftqznbmri3HmCqb78OeolNjSzMDgXgfEwwpOJkBXrVgeqiHK0PSmq7FMTKbq6aDhfBLA vueibOgsW7ZfCQQUFB1FIUWTL//2UOJ6Nra5tUJ5JQV9hAd8qCVHFnriit5OPvK+DC6Un5 Xw/+RXLn/AUIhJCP3pj3eFBE7F+2WLQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-zOmfsVjuO_i_ymQv9RHTlQ-1; Tue, 12 May 2026 17:06:01 -0400 X-MC-Unique: zOmfsVjuO_i_ymQv9RHTlQ-1 X-Mimecast-MFC-AGG-ID: zOmfsVjuO_i_ymQv9RHTlQ_1778619960 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-48e6af7a9cdso31232875e9.3 for ; Tue, 12 May 2026 14:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619960; x=1779224760; 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=fHWjppoupYJq6gg1bmhomqZmsJDzmE/Zol9ZNgufzks=; b=Q1x3wzTynKxexJQ3iR4qczKCW/6evmQe2Ib7qaKVJbkaGRF0tkI/2+daICyQ7GZgCy TlN9ZQOac7wGcGlTokaDbYKvYEO0OjQd3H0yHrx0ZUGR8rTEtGM0ofllMsi+iAaJmuNG 5CtlLfK/0W1Jg7spqAWMfpb488pbmP6Evnm9d9m595WgP8l3iODBo/lGqKAvR0nHtZkJ dd1vm9snIsrR4VKYyq9IAw/aQXNThcPeka/s0g0FFnMhv93cDuhVx7NT1hCDIFUnFFjy rLbNGOqZy7F7kZXgcUYzHeY/horGE55551g+KMl0y7XeTtLfx5lDkVdICo6+5GBlagvU MAuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619960; x=1779224760; 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=fHWjppoupYJq6gg1bmhomqZmsJDzmE/Zol9ZNgufzks=; b=oVuq/gVgHKTx0oj7rSUn2KDq7A8XvFWdLWx9rqb7Ob+Dou7cEodGna6PmyI+YJym58 opLElsFTxaZTME9n3XjhHAcR25EUwJN+ciReEQQpVFaNW0EaKGexIw0Qluw1p45hFaUD P49wT3disoYpVxPvgFHWwMKK7DR6S569DMZh0R9/LSaO3xEZsOeGGbWO1b5sB9xWXYPK yR0WiPIrBtAHmYCRDIk6c3odlBL91ky65A9vpjLJzI2zfQzk3JFM+vlbZkd4A8aQyXMf wixpnJ1TyKYAhRWIJPsFY+sOUaRQEIXmRz3oRgxXcYgpbnW2nAyWA3z431z7QsZWL6bA IfEw== X-Gm-Message-State: AOJu0YxEp+cMWav+o/8/BdHb/46HWt2Z/ZaVBeVWxUxwtiCvMfl3ekZ3 ajdnNluk+HCDmj0ldBNY9XxSbhr38RFMrdnBxiFGQ42cnlSd5MMuMnz1iw5qLN6v2/VLDFWPKbJ B6JJnd4AVQGyG9QyhhITS5a91QWS2jDCfiBZAdFvzqBRoM/Ovzp4RZ5G2P2eA7RQUDhGsXxn97L vsH+i7dJlhsoCQ8VXCUKqMt3CaWlhFXv6f3jy+L6BMm8k= X-Gm-Gg: Acq92OFjLb5a5gqOhcH30ZWTVZ8KWwkQjMRyjZCCsw5/OVYxWkUWLXBpjg0WY1gtkJ5 HbsysC0BZCSuDq3a61xXgVI9qMbJYq0GRPxYFBI7QBNeU0Yh3ShADP4i9+RC2/PgMkoIQZzEdvd zmirgtJixU6gbuYB+B+/Lbs6cZq1SXqiV4poJ6Qu9WOBvdkZY5mRgu0qE+bCU8J3eHCHvmG59bz adYnBw6fGztsP+BLlZJ6ipRbsveKtgP4TAPwxdi291m5P8BqkKNvyidNku897GoWztnWfojQtv4 xrHjm59yvaGWgP3f0kAuNJpzneBfapVADL2SdAOqv644/jSTQvVyAg+uyc0eIF97UmresBIyXv7 G3AMXr3H1BFqpHGsFrBEpdlw1rXgUS/ua+zAm+Klw X-Received: by 2002:a05:600c:19ce:b0:48e:7f1c:8778 with SMTP id 5b1f17b1804b1-48fc9a34577mr5572315e9.17.1778619960138; Tue, 12 May 2026 14:06:00 -0700 (PDT) X-Received: by 2002:a05:600c:19ce:b0:48e:7f1c:8778 with SMTP id 5b1f17b1804b1-48fc9a34577mr5571635e9.17.1778619959429; Tue, 12 May 2026 14:05:59 -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-48fcdf63f05sm95345e9.1.2026.05.12.14.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:05:59 -0700 (PDT) Date: Tue, 12 May 2026 17:05:54 -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 v7 09/31] mm: use folio_zero_user for user pages in post_alloc_hook Message-ID: <45d1ea85b574399459a64fdba28fcf04abfa3e7e.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When post_alloc_hook() needs to zero a page for an explicit __GFP_ZERO allocation for a user page (user_addr is set), use folio_zero_us= er() instead of kernel_init_pages(). This zeros near the faulting address last, keeping those cachelines hot for the impending user access. folio_zero_user() is only used for explicit __GFP_ZERO, not for init_on_alloc. On architectures with virtually-indexed caches (e.g., ARM), clear_user_highpage() performs per-line cache operations; using it for init_on_alloc would add overhead that kernel_init_pages() avoids (the page fault path flushes the cache at PTE installation time regardless). No functional change yet: current callers do not pass __GFP_ZERO for user pages (they zero at the callsite instead). Subsequent patches will convert them. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- mm/page_alloc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index db387dd6b813..76f39dd026ff 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1861,9 +1861,20 @@ inline void post_alloc_hook(struct page *page, unsig= ned int order, for (i =3D 0; i !=3D 1 << order; ++i) page_kasan_tag_reset(page + i); } - /* If memory is still not initialized, initialize it now. */ - if (init) - kernel_init_pages(page, 1 << order); + /* + * If memory is still not initialized, initialize it now. + * When __GFP_ZERO was explicitly requested and user_addr is set, + * use folio_zero_user() which zeros near the faulting address + * last, keeping those cachelines hot. For init_on_alloc, use + * kernel_init_pages() to avoid unnecessary cache flush overhead + * on architectures with virtually-indexed caches. + */ + if (init) { + if ((gfp_flags & __GFP_ZERO) && user_addr !=3D USER_ADDR_NONE) + folio_zero_user(page_folio(page), user_addr); + else + kernel_init_pages(page, 1 << order); + } =20 set_page_owner(page, order, gfp_flags); page_table_check_alloc(page, order); --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 7D6983C9EDC for ; Tue, 12 May 2026 21:06:09 +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=1778619970; cv=none; b=FB+1vpAnSqw7D7wH9CIKKjmm11jIdlVyy1NDX9KUxafB0y8XLHzFCVZF5ufraGMwbx9N2p/rp1QUceRNOWtRhdAQmFIe9nk6+IpDM9hvUZZET4rfn2vrFSv9tdfDT4QwvXDGD+4ZYKCPuQwQF6yovMa25A4VZDi35sTW6KVbR8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619970; c=relaxed/simple; bh=B4v7SD6SJ84KapLgBy+iXreANiiaF75HE81bu1RBt3E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i4QWyVt+ckeR1WwwQ7+GY2G+65iZZp6CFrUXtbGrI1NSGJXLXKKIP8WTffZ06UIdxSEC8CulcoPI6T5n3o8wsuGFlrj/QD4pzJhfrd+feWFelFn4lDgPeODCGfs2cUK56gKbbarcVVgTYfTXuLcgbeYVuuhTDmPIv1asS47J/m4= 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=UOyCE8kq; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=H9X6O8pW; 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="UOyCE8kq"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="H9X6O8pW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619968; 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=jpAQ9O1oMgUNlo5ukg9OEno1SM1k+70VK2/jH7/8vVM=; b=UOyCE8kqgxj6DT8d9tnNaicNWKoZ+nlph3hDi2R1thXlSWC3k9dRrhTPKazC7470C2/v4F kTHlqxQahSSnqTa3ynL/+dKZ7C58TvQ8b+Wztq/o27gAWpfHfR/iDn8uMtXzo/nXmTzTP5 Lw3SktYCXBAcN12F1a/aSmBFq2gcPu0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-311-uO_V_KhfPTinfpXqdA7stA-1; Tue, 12 May 2026 17:06:06 -0400 X-MC-Unique: uO_V_KhfPTinfpXqdA7stA-1 X-Mimecast-MFC-AGG-ID: uO_V_KhfPTinfpXqdA7stA_1778619965 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-4411a1f9601so4549359f8f.0 for ; Tue, 12 May 2026 14:06:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619965; x=1779224765; 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=jpAQ9O1oMgUNlo5ukg9OEno1SM1k+70VK2/jH7/8vVM=; b=H9X6O8pWtIstyS6p7gjDDQm7WPTJ6EWaRoAraDcWkanxnNYwFbpadXpzE2v82dVyjQ lgK/Qzu+CnghHkU1r1UL0JpCmsJCccBGejzwYC7ZBKjb3dQahbS7cmf0Y6qw6V8uihPU GA4yCOmiqhN4/AHIiM0TquAup/eUoH71OHxAvlPgr7GZElY75XAOCSKkMvw/8jdNvERG kZORAFyUxI6LaW+Z0kKGNcuYzTRWLm/QwbQ4+Y3fn5eQdm0pUbDxKVIDGMgfjWLRxx/L y/81mvYAFCYH+5uD2Ag8iijur8yDzY9DDhTR8DR8LwMB6TOKhg1d7x1ng5X1Ae84dYDb XxuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619965; x=1779224765; 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=jpAQ9O1oMgUNlo5ukg9OEno1SM1k+70VK2/jH7/8vVM=; b=FX6EgKB/8C07ZtZ9hh7TcSabHBxwsm5br/CO35t6cKPnjQuid8YHbMUcaCfem0pAom XDn35X4oes372K5K/HfJ7UJw5kSLbldvrANzJ2uYYJT8Lyq5y1+/sLpQP794E5q3ULX7 amZUQ27+5mnINzgdQiqAEYhhWxNprt5Mkh0fFVVD8hysd6gvg1XXh/jPFsap1tohczgB rqWQgjFvSQb0/lhz/v1YGM+9UhJhGQDLJFRJPbGtJg+31Jx77Ip7dCuFh0PTb22KuSKn ZpSlBD8tVZzfuP7Rro8EqS0zfzOMyQebKaC8cIyN6EA+2REC1U7aOjtoLfknN8w3eY6A fvkQ== X-Gm-Message-State: AOJu0Yykj1JKlYzVc7jGnruVXeWSh59g3kqZZpYJxaNr9NIUX/dV3kTr EoyFzv3zyl9Bka4C0Sycgu5CTAkINM1d+W+kFbxQikurhFATJxBb+tP4FCIkvkguXmtuFdsls3A EaHVgis6wdn6XmeNB8DY4U76SO4KzOeEFnBWqPXPQsfMryZsGMlcy1RIb3xeidfzgvTkY4P+T82 +DqoLShQyhfcMmRLc3nJxq0gRNE8QIl76n7khEqG7M2Qw= X-Gm-Gg: Acq92OHhVdsTcC9/ttO8HSBQHr/SduAUudw27DklJby1X1jZ3Px2NdDDuefNVi+GP7o vUemstvUuwq8bwCT9bhOb7J2xNHKApC3eGTMt9tZnU+1QqA4y8/rVytBufBmrKkGSF9o6mHVN7o +ICSg3sSV8qAOq7qrctwGErqHNkxV+w63SM5NLaZcX/QzzGEyo+Pkopqj/owyPihvtASJrr+HL1 0Shbi7bFQRKyxpqlDodVsSuY7OWM+ChodfmMPKffwxKBSkOmVeoF2AciSLLN20Cb9xIDLiVBNdf a+g8t5fqYMNptbhMtL2c4909CeZCmBgZVPdXictGpNWmh8QP5aB5BhiHdqU6OBfxYJoMWSFVDQT L+I4kgYCBxV0sWBOUciLvNBhvnQ8PTPVXienrZr1N X-Received: by 2002:a5d:64e3:0:b0:449:9aee:4573 with SMTP id ffacd0b85a97d-45c584a91cfmr556814f8f.18.1778619965041; Tue, 12 May 2026 14:06:05 -0700 (PDT) X-Received: by 2002:a5d:64e3:0:b0:449:9aee:4573 with SMTP id ffacd0b85a97d-45c584a91cfmr556737f8f.18.1778619964519; Tue, 12 May 2026 14:06:04 -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 ffacd0b85a97d-4548ec6b00fsm38840020f8f.11.2026.05.12.14.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:06:04 -0700 (PDT) Date: Tue, 12 May 2026 17:05:59 -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 v7 10/31] mm: use __GFP_ZERO in vma_alloc_zeroed_movable_folio Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that post_alloc_hook() handles cache-friendly user page zeroing via folio_zero_user(), convert vma_alloc_zeroed_movable_folio() to pass __GFP_ZERO instead of zeroing at the callsite. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- include/linux/highmem.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index af03db851a1d..ffa683f64f1d 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -320,13 +320,8 @@ static inline struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struct *vma, unsigned long vaddr) { - struct folio *folio; - - folio =3D vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vaddr); - if (folio && user_alloc_needs_zeroing()) - clear_user_highpage(&folio->page, vaddr); - - return folio; + return vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, + 0, vma, vaddr); } #endif =20 --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 85D4E3C9456 for ; Tue, 12 May 2026 21:06:16 +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=1778619978; cv=none; b=ABdJy9w/uRKO2WNAcZ1FeVAHCndeZLdIFL7Vbd/cLMlXSaBWPi1J7I2GtZUzp/VaiXDkImvIV/PODE94e9qsLDNaBN7O85yvoxQJ/R8Ix0yTRCV1vbsdEbjcRB2Q9h/YWPjjtM+uZqs7rGdPi0E45oEmcZwODq+gA+ITUUi6jW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619978; c=relaxed/simple; bh=xVZpENOTPSkcCw9H72WToBvwV1ZsJAWZkigdtcUbLLU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=r2tG5tunRMiIZQE/hu3XAxyru3kx15jZ+qQWNVZxxpdQh10JbPNjgfsnEIFRNOcnuV/FgD/+9QcFWnluUhkurDinkgOFh3z32auwyci5PkXlKTwBMkZKVbp52iOi3/6Gg3SAkvFeXvrRIz1JuHzCQPKbUaRayZfScySSdaoGLoQ= 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=DcVQVzuY; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=lWc16jQ6; 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="DcVQVzuY"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="lWc16jQ6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619975; 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=+4kzhpMcne9QL/iUfytpcOnuwyhDfw3DKjMmXnNjefM=; b=DcVQVzuYCTrcvesS3JVrcfd2PbyBVgeqBHbxST2Dp8ZdRN7SswyLX+4q4BwyIvzFaunaca T7872FdoOKgw3kuwR/UqJwbRlKlwYa0Auj+sZ+c27Wr1TTUQF0AC6rWez2PJq3hhLYMgtK Xn5AV9H3pJPNarlK2wpiTfiFuZrJmiQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-124-MhtyScZEMLadmnhTfpzu6w-1; Tue, 12 May 2026 17:06:13 -0400 X-MC-Unique: MhtyScZEMLadmnhTfpzu6w-1 X-Mimecast-MFC-AGG-ID: MhtyScZEMLadmnhTfpzu6w_1778619972 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-48d046fac74so35019645e9.3 for ; Tue, 12 May 2026 14:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619972; x=1779224772; 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=+4kzhpMcne9QL/iUfytpcOnuwyhDfw3DKjMmXnNjefM=; b=lWc16jQ6JJ1S6F427WzZqfe9mV3nGCuLtjxhxznbGxuQegURYU35/KwZCfFiUeaet5 OGZp05NqLEfpQZCpYD8pE6s0RNz0kDCgX7DYaM33hX67OcsoiNiyF7K5gRtIAP3OpnYs myx5/10bEG3e3u5451qpV8VYMsGPXMBHUcmsVsuhhFECTVwLzZY2Fy+SEn/J5C55Skze wp1PFZfkQLebNlAx/W50jIX0ZyaQo5hUT5vHrCu2d2Qo8XWx/gSVFLCjKQR4wkwMJxD/ YlzIBc9nMl6jFJYnK8uCv4E3+oBxfrtqmn6jhElRPNvgzrMhWylBUKA3LTdVfmpf1vsa yaQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619972; x=1779224772; 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=+4kzhpMcne9QL/iUfytpcOnuwyhDfw3DKjMmXnNjefM=; b=ba/E/tBAWl7D94uBOpOb8zx6/+9PpMQMvQ0td7sMj//lneRtslb+TCowSS9nanM6LY ncS7VNkFBN0MTOj3gCWXbDT2D0cqJCC4HYCBoB8JtQDgeFy21dHC0X6ccdlFu89MDAr9 BjBLvEmiyXkYjveOTmAfS9882C7FdNYDDiqU/I0Gds0/b8qARMusWB2JMjPz0m5Mpfcm dsZae46oioAhWKr+N+fKfHLj0Wawsw53qKEuCLTonD/ELoaecqO0Q/yi9B1OTeT+eiTk vNKHyPtfDKGZcXJy54lkV+/s2HJwj7QhpWg5rCY8WVVqY2NEICHXEElkx57V9gLP/MQd g0tQ== X-Gm-Message-State: AOJu0YzU3NusxF3FOuakS32YiB/jtUipVuq4Xrc9p0XgzlGcU9mnqV1b YgsThlS3x1rbiFpKi0iwX1DhRWXZRkPgqTcyFNgpaa2PrqtqiJMzZUZT7nZRVIkDz+xrS/dDV4Q Rp56kz3Bi2AZtQ6TBf4vIKb9j/I9F+1Poejtzcq6nddwNotbrCebHImjirXPlp8M2xBH7cBCdTo weoac3NaLABy6L5PwRCXK6T9OIN9y405Srp5Lu0wwqj4Q= X-Gm-Gg: Acq92OHKAa4ZTpSrDaXZbXJHVjdu3ac5XjYjNwGmo0TnCCLfz/NSrCM15klDdbbKV7L KMvF1bWZW5OGM6GDdZid7dDX0VkHjwxVyLV+TvqhybQAULaHTpnPJX64Fh+mC0iDM4BNBmMbRPp 52CRyFAxgsCbarYJvhx3vKSBqYi1yW0FpwIaLWaA+lARCmTd5iuvoHYzyZquftjrMqNtBmZoBMv y8CHRq9wQ/6Uu6eGLCZVEwe3kl3pb/fJNxkrYfHuMZ030el14uJwnKF9/WVlA7XtLN2p8bsO/91 i9TP7LGp1wwMxDjex1/9zo4mezEuuQTPAspmi9d1lME1ydV0qu3rHCQnIQ2G1uANCmqqysEllNx vp7PlJhBCBz4VSPF8hX4S3FHsTqy9DF1TXogZ3kwp X-Received: by 2002:a05:600c:3f1b:b0:48a:6fd4:d3d4 with SMTP id 5b1f17b1804b1-48fc9a50d32mr5863305e9.29.1778619971877; Tue, 12 May 2026 14:06:11 -0700 (PDT) X-Received: by 2002:a05:600c:3f1b:b0:48a:6fd4:d3d4 with SMTP id 5b1f17b1804b1-48fc9a50d32mr5862425e9.29.1778619971141; Tue, 12 May 2026 14:06:11 -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 ffacd0b85a97d-4548ec6c221sm36066581f8f.13.2026.05.12.14.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:06:10 -0700 (PDT) Date: Tue, 12 May 2026 17:06:04 -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 , Magnus Lindholm , Greg Ungerer , Geert Uytterhoeven , Richard Henderson , Matt Turner , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-alpha@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-s390@vger.kernel.org Subject: [PATCH v7 11/31] mm: remove arch vma_alloc_zeroed_movable_folio overrides Message-ID: <7d637bcac4bb5705388136a75f0fdfe2881e5f20.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that the generic vma_alloc_zeroed_movable_folio() uses __GFP_ZERO, the arch-specific macros on alpha, m68k, s390, and x86 that did the same thing are redundant. Remove them. arm64 is not affected: it has a real function override that handles MTE tag zeroing, not just __GFP_ZERO. Suggested-by: David Hildenbrand Acked-by: Magnus Lindholm Acked-by: Greg Ungerer Acked-by: Geert Uytterhoeven # m68k Signed-off-by: Michael S. Tsirkin Reviewed-by: Gregory Price --- arch/alpha/include/asm/page.h | 3 --- arch/m68k/include/asm/page_no.h | 3 --- arch/s390/include/asm/page.h | 3 --- arch/x86/include/asm/page.h | 3 --- 4 files changed, 12 deletions(-) diff --git a/arch/alpha/include/asm/page.h b/arch/alpha/include/asm/page.h index 59d01f9b77f6..4327029cd660 100644 --- a/arch/alpha/include/asm/page.h +++ b/arch/alpha/include/asm/page.h @@ -12,9 +12,6 @@ =20 extern void clear_page(void *page); =20 -#define vma_alloc_zeroed_movable_folio(vma, vaddr) \ - vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr) - extern void copy_page(void * _to, void * _from); #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) =20 diff --git a/arch/m68k/include/asm/page_no.h b/arch/m68k/include/asm/page_n= o.h index d2532bc407ef..f511b763a235 100644 --- a/arch/m68k/include/asm/page_no.h +++ b/arch/m68k/include/asm/page_no.h @@ -12,9 +12,6 @@ extern unsigned long memory_end; =20 #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) =20 -#define vma_alloc_zeroed_movable_folio(vma, vaddr) \ - vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr) - #define __pa(vaddr) ((unsigned long)(vaddr)) #define __va(paddr) ((void *)((unsigned long)(paddr))) =20 diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h index 56da819a79e6..e995d2a413f9 100644 --- a/arch/s390/include/asm/page.h +++ b/arch/s390/include/asm/page.h @@ -67,9 +67,6 @@ static inline void copy_page(void *to, void *from) =20 #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) =20 -#define vma_alloc_zeroed_movable_folio(vma, vaddr) \ - vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr) - #ifdef CONFIG_STRICT_MM_TYPECHECKS #define STRICT_MM_TYPECHECKS #endif diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 416dc88e35c1..92fa975b46f3 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -28,9 +28,6 @@ static inline void copy_user_page(void *to, void *from, u= nsigned long vaddr, copy_page(to, from); } =20 -#define vma_alloc_zeroed_movable_folio(vma, vaddr) \ - vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr) - #ifndef __pa #define __pa(x) __phys_addr((unsigned long)(x)) #endif --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 9798C3C1978 for ; Tue, 12 May 2026 21:06:22 +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=1778619984; cv=none; b=DaTub0lLPuK2bYCSpVra5TaYk4ZJeURlrJeVjaG/etK18DY6EYJlX6czbDk3khy5LT92ze1qFuppSTAdTPCXkpLTmRbQEsA72X7KfUd+paS1T6eIWRcf0Mx4ZE/1+3Uw5GFpms7gPoJ7A7Mqar6ny9KBGJJsYGoLUAEsHkjgkT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619984; c=relaxed/simple; bh=E26K9MtueOnkubczVVC2xXdzWX1Y3Ie61mqNQBLBafY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KX+C6vQS+aa3UjPvVp1mJm6KscSqfJ+NFMfW+ds5l6kfYKhC6msDaBUAu/h75+XKnC93ov53rzkBOZ09FJyRkdL2JFWFbd1tQU6ElyRY1dJ8GD186utk/22EfkNnlYrekBDdsqtbDiZOGqi11IiiOpmmIXj6zkl87Yufl96Hsno= 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=H9P55yu0; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=W8JSHS2b; 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="H9P55yu0"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="W8JSHS2b" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619981; 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=Cj9nBXTM7Pn45uNvAdcesuQTFKdusMRl11qP0Ml19S0=; b=H9P55yu0f+yLDDhxTTk9hI0J8XDwVNnMLoJ6MNiPG7kg40Ww/GtzonZRWfVYVh7N+6rbDt nEk0+yLejizBSWDHd+BtYCDqDApBXbcH8aBfiroAU1sw/BenbhrxwbdngQUHtAoqTc5Ct1 qJYaEkI4ae+3qgTBVsWEZdxdsrfbL5o= 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-360-UZZCCBy6MW6Y3QcYlljsfg-1; Tue, 12 May 2026 17:06:18 -0400 X-MC-Unique: UZZCCBy6MW6Y3QcYlljsfg-1 X-Mimecast-MFC-AGG-ID: UZZCCBy6MW6Y3QcYlljsfg_1778619977 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4411a69f565so5366532f8f.2 for ; Tue, 12 May 2026 14:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619977; x=1779224777; 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=Cj9nBXTM7Pn45uNvAdcesuQTFKdusMRl11qP0Ml19S0=; b=W8JSHS2bPl4w8voYZsO6aQjEqaRg1g7o+GbXPqgP9jrY3T1R0JHCvWjBhvBTKERXHO BHWWa858QjmAIaiRgxx7MD9j4Lv9QqyApRIg3ITn4Mj0urzTIa+LH+6q1SMvqdWO4++a dL5DN8k3kHN+pZom2oXYIaAhz0oCCtnLfxsULxkE104cYgeIQOf9e2CW3DEKALLBKdGD Ie4pQxux8YggVT283MLPHxtgge7fqKq0FOonXqmCB94utfdu/SL0YkE/fXfKygF0k+t3 1LTHMTZYAFmZYxX09iqe0lwphUdt4nhGkJadrHKdHKxavh2O9416IB5xVco9JNiV/+SV 53Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619977; x=1779224777; 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=Cj9nBXTM7Pn45uNvAdcesuQTFKdusMRl11qP0Ml19S0=; b=elacxaXMvf9EKUn8QSQLKKYvNmGewHbi91BIOOjIDG2mR321//1IpWCM7ht4mBDDpt GzlLyBUIy0eEw9cVj225wq8jYQJGREK7k1YvxeiNn8cmYRY5n/NMcSUCwLiunsw84qZ2 MccS/Ic90j0G0aIDJBHyAXlGrIimGsJ7LXyEHiSbqkXzc9zEIo3qDn8p/K6XsqyYhzqs PxzvmOU1yTYBO0aZNhAxncZHt12o8JRFASGOzEcJQSHKD/R+ZPeMtxWCbNV7ZvmBNKx+ 966StonYEzGNXbhqy9eKI9xcoSDhESGkQ62FW5DLiRKHDj3Pw5Lx+oXRqMKCKdkgiirf UsVQ== X-Gm-Message-State: AOJu0YyfWoKY6FFoC8me6SQKfwhlgZVZ9KuZjLhIpRUKt95ottAuKNzh AaVBT6jOL7XEdc1SZY+yznZ0jb5AsMDGITx5EEdEnhHlVmzv5CvAqwZ/RZYIFEXbh/vwvZgWGCW rqNbBuVENykQbXAFDSB+GwMAyxXcRMgPRdyEA4tsYWW9G0ureVLozQ/+/z42h3SWYvweeKTI0/R AGvRQDBKQrYSvmtnURaEaL+ONmmsGXpZHJvpeGmxfVmhs= X-Gm-Gg: Acq92OEqc3+hthVGzp14mDrLEqZQJL28rBysL02N7uFiRJ6lOc/jZF1QoyX1gr7KSHP 1/a8jy/53OlABdFAwtz3FWK7K1qtzlrnnYniNQLdayZ6mKuVQdlDvBKNbGt8D4QZTFwYO4KpygB eLm+zRXy7ogUqPAC4tEDGqEccmU8DDQYEd5QgyuCtOkXactvoINdcnu/iOtwPC7HMwrwx+yIaTU UXSGxEgduxjrYujemsr6S0w8lTEh3DPd32YG15jP3LPeGXtMNaYNxv3sTz/AT4SOCF4muPO8F+Q sxfHTpJ/2ZnasgdsfuwQqtTZwv/HXDKwWXKE37qzm0dqE2LU9AVlujqLj17zw3YnvVraWtTie0X ik+exE9MJ7cr/mX36pac9rbJI3KxteBfxjeYFxGI2 X-Received: by 2002:a05:600c:4e14:b0:487:4eb:d125 with SMTP id 5b1f17b1804b1-48fc9a0eaf0mr6501755e9.9.1778619976898; Tue, 12 May 2026 14:06:16 -0700 (PDT) X-Received: by 2002:a05:600c:4e14:b0:487:4eb:d125 with SMTP id 5b1f17b1804b1-48fc9a0eaf0mr6500975e9.9.1778619976278; Tue, 12 May 2026 14:06:16 -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-48fc8d29c56sm22449935e9.11.2026.05.12.14.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:06:15 -0700 (PDT) Date: Tue, 12 May 2026 17:06:11 -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 v7 12/31] mm: alloc_anon_folio: pass raw fault address to vma_alloc_folio Message-ID: <865e54aad878ac6627ba6633f35ab57a5e2d3c73.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass vmf->address directly instead of ALIGN_DOWN(vmf->address, ...). vma_alloc_folio_noprof now aligns internally for NUMA interleave, and post_alloc_hook will use the raw address for cache-friendly zeroing via folio_zero_user(). 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 --- mm/memory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index ea6568571131..0824441a6ba1 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5252,8 +5252,7 @@ static struct folio *alloc_anon_folio(struct vm_fault= *vmf) /* Try allocating the highest of the remaining orders. */ gfp =3D vma_thp_gfp_mask(vma); while (orders) { - addr =3D ALIGN_DOWN(vmf->address, PAGE_SIZE << order); - folio =3D vma_alloc_folio(gfp, order, vma, addr); + folio =3D 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); --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 5132B3C943B for ; Tue, 12 May 2026 21:06:26 +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=1778619987; cv=none; b=gk3OSWcjVusAceB8TpcQL1k50LT/jakkqQ9c469neY7ET9ZiQeZcAq6Haf00LysBzE2gIQgxOqtL+1ONBfcSTOIueuOmwcTyxYZKTnIQVheAVKqU1Utnm58Py3P2LUfO19EEDKj+sjHJSe7K3XbAUH7J43Rb3M6plzY+frli4eY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619987; c=relaxed/simple; bh=WO4MHxi65GFX0xUNciL8bEMuUsPiR9dGIohoqGtzw3w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OGQ51Arw9eL9ZHdHEf/Lds8D6Qkce+4vs4q9N9jAh5i35ny8HDc6bR2QSM1SucThDdd8/B4+i9mmklISoeVXNftbsQGyGGhacm9nioIe8q+DyYxFZxlA1zwXs/t2pgbHIP/u1dw5ki3Hj034KFJ+Q3tK7xkRdsdc2DBb5Y9SwtE= 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=QkKq1OGt; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=KA26UHov; 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="QkKq1OGt"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="KA26UHov" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619985; 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=XL/pBrxkXlfOOto9pZb2YfWp+jJTrqFtHfQ0Ihv6FSM=; b=QkKq1OGtm1T9q34SByaG4Bpz/gibJm6IJo3ZXY58k22T0cQWLzvMMpb4ItjJIlNejy86Em 8+SHxf2SZm15xEfTnOwdyYH+uBAFBc3ttnCZMhAJ2z6WldJ0zoHLZ8yXDc5NH6/PBs6GKE XBI4gJ8gXywJ9mlima53Lc843KQvkm8= 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-317-Uydhw8WZNPq7uosrx_v2WQ-1; Tue, 12 May 2026 17:06:24 -0400 X-MC-Unique: Uydhw8WZNPq7uosrx_v2WQ-1 X-Mimecast-MFC-AGG-ID: Uydhw8WZNPq7uosrx_v2WQ_1778619983 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48eb0da933fso5867785e9.0 for ; Tue, 12 May 2026 14:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619982; x=1779224782; 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=XL/pBrxkXlfOOto9pZb2YfWp+jJTrqFtHfQ0Ihv6FSM=; b=KA26UHovV07ax0MDRN/CahufvtSaoFX0uo6XOGufWdTgSPOIOVpVzJ/UONNMbUnFDa moFLG2EJzVdhaX19qE6uubHB4zhdCiTUolgZrGjyFdc4Bwvlb6PzwZlqpVYo0OfPS0NG 79KtewKBjD7wdtSZpei+EnCx1KXpKSmTnJCHLRIA/c/6RzzW++duw9ZsnJWmuGhHt2g5 pa37p/zoOY6MBcDk9T6Uk7zT0JgogDh7FWQsxP2bpeMhn8WJtjt558K3tvUqe+wSYdy8 SX7b5mSJXo4FqvIZ0LrUHQQbxz0SHFa78LkvjMxet9NBk2/PN978vLX/B1sgNoDibpFM RjOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619982; x=1779224782; 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=XL/pBrxkXlfOOto9pZb2YfWp+jJTrqFtHfQ0Ihv6FSM=; b=W/hn2SKgJ1G+HnjjT6arJxmoXJZTxcMMFlsMRWJ591ODElzoDfrlEPRQPa62EcYWw0 rxhZ/cVQb1Nx/6uY/qaqFKUvdPL24E03Hzs3FmbfkYamhdGSvdfa8B02cwijMKXhKiye DhO3mJDlZ/4F2WD/vRhjPGFcU4tgk1wIKnPUJLWuVXpto1X11PjAtacLZrjudWyNoSgU dcMU/MzklHIMr64jlfw0jOnSdsZB2shCkQ4lyTeD/9pCNIhhrDUN77JrGrInBHxExr/g tjrT7is9efE3r2vqhUhyLFJxrai2WityNb+PCSbG8xuwv6VyVaPDeUp418VBeK0oGljk ty9g== X-Gm-Message-State: AOJu0Ywu3yqGw5yGYlChknRsv2E8AjaB+o8vUanLlRN07kNNG6eHgtZQ 48V5icDlHzQr3BwcOKth2xl/sqY1tp3o3P2OsKNODTVOASDFfhhr3bIfXHm3biBE5fDFj53jMiK Hh2emYNPazcKWzCV3prZT1p7cqEfvTKxEMVPJyLwrYJdStMD1R+TgGbmDEeK9cxOhUGoIwCuJLo PkXH5HMq7HGCU17w5hvC5IZmCNoMIPQyTMuJgZmGmpl0Q= X-Gm-Gg: Acq92OGF3OzgzgaxT747I0ebT+9yaRiXMJo2D8ewNQcJcnaBo4LAKAKQCbyRAnNDn4R LehWyDcc2b6W96iRlJQVE0ecn0tEPJExMFedSEVygyA4OiDkVxQJcKcsFxEv9ctpLf/3f7bwzuv BerIQ7mm9X2wUmK81+//SLsGtdikLPS/9hA/1g1k2ZOWEQMy0AEl2Eq7DtNTsrwX6eqtxQA99GB czlN3Jxk4LVp3LRudufm6aR2AcCLg9PIGXvg//51bvwkwCvL3se5+FvoQSNNflRfRjEUIx6zRMY ROfzexF3Cch1EJqMpBP0Cuu+4S5tA6kj9eQVnO1D/gOsJodi4Q2KTvzNBaCQbCMwGAubK4tVE2U mdX13y7j9C/0snKloW4G34lAtqnhJUPbJfN/JW1Z2 X-Received: by 2002:a05:600c:444b:b0:48e:706b:53e3 with SMTP id 5b1f17b1804b1-48fc9a0231emr7733435e9.1.1778619982452; Tue, 12 May 2026 14:06:22 -0700 (PDT) X-Received: by 2002:a05:600c:444b:b0:48e:706b:53e3 with SMTP id 5b1f17b1804b1-48fc9a0231emr7732775e9.1.1778619981835; Tue, 12 May 2026 14:06:21 -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 ffacd0b85a97d-45491cab9c2sm37226840f8f.31.2026.05.12.14.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:06:20 -0700 (PDT) Date: Tue, 12 May 2026 17:06:16 -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 v7 13/31] mm: alloc_swap_folio: pass raw fault address to vma_alloc_folio Message-ID: <66119d3bab318d74c1586b99dd70fb74e2da1ec0.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Same change as the previous patch but for alloc_swap_folio: pass vmf->address directly instead of ALIGN_DOWN(vmf->address, ...). Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh Reviewed-by: Gregory Price --- mm/memory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 0824441a6ba1..74523bc00d8a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4734,8 +4734,7 @@ static struct folio *alloc_swap_folio(struct vm_fault= *vmf) /* Try allocating the highest of the remaining orders. */ gfp =3D vma_thp_gfp_mask(vma); while (orders) { - addr =3D ALIGN_DOWN(vmf->address, PAGE_SIZE << order); - folio =3D vma_alloc_folio(gfp, order, vma, addr); + folio =3D vma_alloc_folio(gfp, order, vma, vmf->address); if (folio) { if (!mem_cgroup_swapin_charge_folio(folio, vma->vm_mm, gfp, entry)) --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 053943CA4A9 for ; Tue, 12 May 2026 21:06:33 +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=1778619995; cv=none; b=V1pw8YSq0Vy+hEgQ0zLlmNMD+sonebxXsY6jZlzl+XYKDGZULVx4/OXgYbSHWHjiAib5scavZtdkLsH2cXqKuOaL+HQbB/xpqaxKR2UO8i0YGqfUOb8tIiXTz1HR16SvSdHr6+v8Hx9QUw8b+0Js3mX+UwqvMzyWpdSOqBQHZ2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619995; c=relaxed/simple; bh=Y4i87gvPLne8uDYdZdRz0YtVJ2giC7sgZxD0jT2a23c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nvDpPLhpur/Hw7DHFLwM7LE7j7Byc50/c/0Rs44ZEKMMXmRpmYMpi3mlmHd50d7vYrsYdfYkXx2s2KSZ1viUQRADcNWADh7tCVbb2uey7Mgph4+oBv8QMsYsAfTEqtqzBILB8/JhXMH8wqa7uIGkawetmiZJdx49PeTc55rgA3o= 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=DLr/6nnG; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=UcfPrVSz; 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="DLr/6nnG"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="UcfPrVSz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619993; 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=kWQzvk6rjiRPyM3eAZla3ajwvkAoYuOsF+wH5y3nY6E=; b=DLr/6nnGLw6lc5GKpJsJ73VvZo6HAjQDeK4gz00vXMoa/r4Zj2FvJbP2pF+6lK/RRdq3il LEs6v4CtYN7ysKbD+6YZXH2u+8crt41zmpUPEKAfG+f+i5bZYD+26Oda8IxrbVhXkHTPs5 RDoH5+aIcCQEM22ApiD+8+0Xouc1ea0= 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-669-URPAurvuOWyfVkhHPVzw5A-1; Tue, 12 May 2026 17:06:29 -0400 X-MC-Unique: URPAurvuOWyfVkhHPVzw5A-1 X-Mimecast-MFC-AGG-ID: URPAurvuOWyfVkhHPVzw5A_1778619988 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4411a36715dso4308104f8f.2 for ; Tue, 12 May 2026 14:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619988; x=1779224788; 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=kWQzvk6rjiRPyM3eAZla3ajwvkAoYuOsF+wH5y3nY6E=; b=UcfPrVSzoswrZCdAktrRBfiPwj6QGRMyrxiTfs14j3x5Fh8u1J/Zs3A3kjB+XdDyKd Cy1lnWpxbfaI9JskMFMBe2p9dOArc6Gg+998CfOsodPYKy7j3KXKTyfC9zaUSYG2lPBc bu+WkfYiAhOjyTPgUDiUKISuW878DuGF1msfkKKiPB7jqVHe1LVzMZPfWQpps7Shkcyt y2hR0XvRpjssrDwHMmHCLQgYUfcWr3Mdb3JNVGMSAneMxG2HzNqcQFf1PaTDBaJUl1Z2 +iOonup1mZohCesJoqEQuOU67zaf1mkERrH1XVZ8PvSOEhfYQerZ9LJbVjFM15n07FS+ 6EYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619988; x=1779224788; 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=kWQzvk6rjiRPyM3eAZla3ajwvkAoYuOsF+wH5y3nY6E=; b=sriiwgrwxybd1T3ZExiQeGbTWbLyT8BAqJiNFqhF75puVAIAP41Y1+/2pYVMgSkFNL n7JmA07s9G7GXtzJkYMq9nIOvQj7yQtg70mn0VWgdIRc121zJTPclEirucOLPzaCAAJn hm4mYtzSS6oa9syzT5u+y5jpDBKXbCSvaYbf4AqXy+JJqa/Isw/57eUxaxcpSwXYV75k P9TgJc0sFTOBkgHdgwCB+3a0OnqD66lkCSE4OzDRblgYhQdZ1trOGojvDGnxp/9Em0hM SCobppSr239ecXnZr5ueRYqmV9SN4+KEcpgE3Coe2cv8gK7dkg39LKd8UQJqcOyxZQ+/ aGNQ== X-Gm-Message-State: AOJu0YyjqSv7lcMMOg3TLtcNiRSBHOfWf0vGH++nNaDK969NYOSvnXa7 qGgrqnZWZ4P7+CMB1dIByYR3+2aXXeJC/O3SlrZaTIuX2JMHEgR9bi1zVRqwT5FR+UiZfxChRPP VsZO+5B4gCDtkZp5VKEoC08gN5Gkk5xttYG8hd8LRBsGiZnFHpbtm88hrnZqwUnfV/UGjikfyHA hfkks9oJxDXJcFgb2EYXH3AynLnXB3tstUcTzJ5cVM4mA= X-Gm-Gg: Acq92OFB6CJm+xE36Hom/FFzER/pesRA5Tigsx6cfYp//Z/1M2/F1xaCeCzV4sV2iy0 /gwN3nhhbdEFc3gifOKRgZiyFyuxXpAULha8Rm+TSQksnC4ftZMwrOZIW1lnvU1LCa2AH9RXFBK stQGcNt8JySudn7Ysn515VbXPcXSKPbaUV0CNXEPaeuvRutVlgs63mFueGNIJZPl3do1uUesfPd qhKmEvrx7EvhXRuhhWuKhnx54gmFEndOH0d+iBR4bZZ6NvzvcBpaWqaVl0Z8ULtUkLdfuCTMk0j VB6FGRqi37RN3TTp6swgQvBwiijn8gYkMHc0PNNTO/S3pt6v/xmI1EqYH/KoscMYe7MGEsBllZl ZnlcZ22OJNxaeyd5hkzO4lePt+g+em4xBbJ0znzh3 X-Received: by 2002:a05:600c:4fc9:b0:48a:7a10:4f47 with SMTP id 5b1f17b1804b1-48fc9a023a6mr5599415e9.3.1778619987664; Tue, 12 May 2026 14:06:27 -0700 (PDT) X-Received: by 2002:a05:600c:4fc9:b0:48a:7a10:4f47 with SMTP id 5b1f17b1804b1-48fc9a023a6mr5598765e9.3.1778619987004; Tue, 12 May 2026 14:06:27 -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-48e8f3f5174sm40737105e9.5.2026.05.12.14.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:06:26 -0700 (PDT) Date: Tue, 12 May 2026 17:06:22 -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 v7 14/31] mm: use __GFP_ZERO in alloc_anon_folio Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Michael S. Tsirkin Reviewed-by: Gregory Price Assisted-by: Claude:claude-opus-4-6 --- mm/memory.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 74523bc00d8a..f3f1bc66366d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5249,7 +5249,7 @@ static struct folio *alloc_anon_folio(struct vm_fault= *vmf) goto fallback; =20 /* Try allocating the highest of the remaining orders. */ - gfp =3D vma_thp_gfp_mask(vma); + gfp =3D vma_thp_gfp_mask(vma) | __GFP_ZERO; while (orders) { folio =3D vma_alloc_folio(gfp, order, vma, vmf->address); if (folio) { @@ -5259,15 +5259,6 @@ static struct folio *alloc_anon_folio(struct vm_faul= t *vmf) 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: --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 8E17C3CAE97 for ; Tue, 12 May 2026 21:06:36 +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=1778619997; cv=none; b=Lp06ctbZrIAflLFspnrGjpGYPd6pH36g8CUEYi0C7A8MSmg7SfeqUyqTd5YFO6IrbH2c0Z2NvQj418djEsj28dGD9hZSffWxJ9i/4QIy/vWpGKb3u3K8oQeuIWa+OnO+f+PP3iLHFhvYG7ZVnW0fVYX/S3w65jrOnzDJhwxDeQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619997; c=relaxed/simple; bh=m8forpKa92wSEANoV2LwX8iYn506Fg/3SPdqojZoxqY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=o/O48owQwMHFJETXV7hlwC8JMGv8vL14B0ecojeey8x2loVtrWnl9fpSEyd57Vk39Pui5VRI1r4+aoq0SQpY2eUnoaRJveypNwyqLaVIEsWr6GEhGcUzkk3zb6WLqqikrOFWujliraZJMGqi+OHvRtFlsAmbaUg2un05LDFjN68= 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=Pw4qXWOQ; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=sYVllhg1; 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="Pw4qXWOQ"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="sYVllhg1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619995; 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=awVRqRC+b/AmjARdxVJbu/50IYPO1xelbVaktsnFd6g=; b=Pw4qXWOQcZcW3kbLl6yjRrf+c2OPoSWA+W+X8712TMtWwDXtTH+2qbyWzv73pYQtmaXn70 /hAaPUzq1BIg+MFGjGP0YFbq2Xdz341Kj1VzjOzXirDjqSrhKiGbU6PRYH7K+hzGxkGzqS vtNgsVyNv0+UC7DVqgvQa0L3tFmWl+w= 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-357-eY4Gkh4YOYG3utM3COalfA-1; Tue, 12 May 2026 17:06:34 -0400 X-MC-Unique: eY4Gkh4YOYG3utM3COalfA-1 X-Mimecast-MFC-AGG-ID: eY4Gkh4YOYG3utM3COalfA_1778619993 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-45aeac88af4so1005280f8f.3 for ; Tue, 12 May 2026 14:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619993; x=1779224793; 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=awVRqRC+b/AmjARdxVJbu/50IYPO1xelbVaktsnFd6g=; b=sYVllhg1yUHM0Q4TBAk/NNHOCTdRxgQuFU/duSwEKh0ZnDo6vPuhQyOabJA7eMF/j/ OjYBQKna9iBGQwE3r3FpVfBqEp4dssdbwAyDYWv02LTHX5KJEWHryis3YlEM17vy3Qjm JWsHXjbXfjNtkWgQe5vxjT2ZQu2SnmkiEj9O2cFOeL6khwDEXGVNhinKFU6xC+QpP30I i+SPC9m9JF+0LUAku0iMhYkdNU34cd4VBCNnOIf56oO3nph4lhjNSnBLLr0OfZzSOrWQ AdmQJkO0DBYFWJzu+63a11yl+cvRsd0EfAfqxTfiA/9jPUQIsfK0SFWLVy8D1lJXFYXZ Po0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619993; x=1779224793; 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=awVRqRC+b/AmjARdxVJbu/50IYPO1xelbVaktsnFd6g=; b=RCw+PFTnoTb5qGOG5QDMgdAI7u7Rzvahh3W3pYePoMTYhghu6yXjoVSAc2ZxvNH1Ya qwOLEfgUMn0gwppfUXMqAAS6jSARhzTuuTf/FKApEwdfENd8vsIDsPdkTKAln4WBsWFm wBcwvkhCizFBOVqvIfabwSpUOiEuz02a/tCcmQOjMvZXdDO0tm/no6OhK2nGjm4YH+kR Qc7LN8wC86U+3B1OZ6UOYk9+irEieU5lUOJpM6+PfrxafIB6N2bstuGwT4ADlyEF5gi+ E9i8Iz15rmOARkw3PyU9PYNX5epJpYXszQMKUn+yLJT2Fh5GuQhNOoXeT/bWmP3K3NQZ ogVw== X-Gm-Message-State: AOJu0Yz7o068LAA2mPJy+kO5pjm3bZYstNE+vFOKL3+eReiulcqOoolZ 75EvZHE2YnD/bzAbAJr/QgNnheVCqbuVSGeHYO/q18IQoKUeaJDYVK2aOjehAhl6IoEG6xOtPMB roVufQBuT/nnj/CdGiPK8meDV8/N0qZA2oZvrDnpogF7mhHVRCoEXZYneZ1Ov3c8CG7An0sPwj1 n4hu5Zi0VdCVy86ckkV79RD+QnwU5IWzXIIMXsMCkSxy4= X-Gm-Gg: Acq92OFUbxLTD6qhSnNm5LunJwZlDq3J6qSgjdrd9niUPRd0lyzkM61yheom2cV33Yq rjTTRPZMfzSthdWv3ocZ2bSeoKk49xf6Ai9chXVnmFdvkt+mT/M2VSgvpM0cCgQ84BqJAEpLn4j 6NVZJmJxbFS4K90h39dvB1QURM9U8HSVhkWshXfmiBDW6REY4Wg68kVxAg26k9rTcZ8klS6QhFw x1duk6I7rC5HZd5JnPank4EdJN0JcK/1E/l6fmnOimm2wwK12LWp8NkTIho9OjxHb+LhH2/9GvK ZLZu/0KGb5LclSdAFZ5hwlYb8NJ0Bngf8kelicaazI5XF3oeOkYAutefnB1Dh6b3yPOqxZko7Iz dIBlZPGsDEVqvRuxsCg9pvW7P1u/8udjJ74ECXGiT X-Received: by 2002:a05:600c:871b:b0:48a:75b9:b0bc with SMTP id 5b1f17b1804b1-48fc9a5ed3amr5818545e9.29.1778619992915; Tue, 12 May 2026 14:06:32 -0700 (PDT) X-Received: by 2002:a05:600c:871b:b0:48a:75b9:b0bc with SMTP id 5b1f17b1804b1-48fc9a5ed3amr5817805e9.29.1778619992358; Tue, 12 May 2026 14:06:32 -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-48fc8d19854sm24100025e9.1.2026.05.12.14.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:06:31 -0700 (PDT) Date: Tue, 12 May 2026 17:06:27 -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 v7 15/31] mm: vma_alloc_anon_folio_pmd: pass raw fault address to vma_alloc_folio Message-ID: <411a7b6a750c1904b99be92fad0e678ad791ca82.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that vma_alloc_folio aligns the address internally, drop the redundant HPAGE_PMD_MASK alignment at the callsite. Signed-off-by: Michael S. Tsirkin Reviewed-by: Gregory Price --- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 970e077019b7..d689e6491ddb 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1337,7 +1337,7 @@ static struct folio *vma_alloc_anon_folio_pmd(struct = vm_area_struct *vma, const int order =3D HPAGE_PMD_ORDER; struct folio *folio; =20 - folio =3D vma_alloc_folio(gfp, order, vma, addr & HPAGE_PMD_MASK); + folio =3D vma_alloc_folio(gfp, order, vma, addr); =20 if (unlikely(!folio)) { count_vm_event(THP_FAULT_FALLBACK); --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 BB0933C988D for ; Tue, 12 May 2026 21:06:41 +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=1778620003; cv=none; b=URyA1IhfU4dROioGanGaDGn9+y8DsmNiOTvQHBeYfit2VE2DPz4JEJ+SxyFx4Ce8lPE+jeXEptB9a6sdd6hznDQVdZETXy0oUzbNR2xIy5tO8YLKLsaCa7a6jyOBNLnBq4+4myyn5OuaAR4fjBhdVG975LEmyaPM0JopAGxoc/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620003; c=relaxed/simple; bh=xei+ncw22Azpj2W0VX9NF9tpXBP3CShNLWL9kEAMTtQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UgxSAhA6oVuoVVMe24lMFmbqRQhywQqXHhTY+X88rhzwcv/QRTh9UrSFQ5idRqf6XtTRqd6bgpmCX5KWGZkhK51/8JH7MqOYQ51dmTpB37pkWfRJ9f2LzIEfeqcYXRJrQuGimyWZGPNmPfuZ4ap9/Hx7XVXENACP0BVuburoC6M= 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=FN9EkYSy; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=GO/3Cfn2; 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="FN9EkYSy"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="GO/3Cfn2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620000; 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=igR9Hw7C9olHKTfwoHAKRKmu59bne/n7R/dh04grefg=; b=FN9EkYSyeDOcQSPDViEWO8v/SeEIB9+cDCee4/+2d/WNlkwZRkvT9KQq54PY4a8Xjtn4wu jaMuQUXD6jECrc727lTaeujkEyfc3eMvjm0MY579O7FWaZXpiXZEnI8oYPo0kvkzrqB/9J S45niQqvSN3ySG373h6SVlBpcA9hoHk= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-330-Kd8CNrFnPqGC_sQvTdOVUA-1; Tue, 12 May 2026 17:06:39 -0400 X-MC-Unique: Kd8CNrFnPqGC_sQvTdOVUA-1 X-Mimecast-MFC-AGG-ID: Kd8CNrFnPqGC_sQvTdOVUA_1778619999 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4518f777225so3894568f8f.1 for ; Tue, 12 May 2026 14:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619998; x=1779224798; 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=igR9Hw7C9olHKTfwoHAKRKmu59bne/n7R/dh04grefg=; b=GO/3Cfn2pT2pONSv7TXlyD8zXDucod65OUBNYTChIVCEyIoK/TGjLmhdXUDc2oWIIM +46Fxj+2hgRqebTGqMIoNdhgoUnjyBz2rUF1847xf+wyXFOy9KuKIx7KimA7g4b1GWGj 9Gzr+xuzeN0cbONIJZI0yBbU9yvae5q+/s/sok4bzYS4QU4A7cAa4JZkOhPFvJ9Ku+pQ gukR727hTgQacV6z8OE+KRCl+ZIWDi9gjFn6b60v71p5UeBsuN+ntGFC0ySi9VSHukKI NOEpcFodwBpTP5BZ1vxtEL3SP8BBKtu2TK5wQeqE34RMUu0qy1mpQ55K1Fftit07P56e 1DGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619998; x=1779224798; 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=igR9Hw7C9olHKTfwoHAKRKmu59bne/n7R/dh04grefg=; b=qP0qLyV5y+2DTleW8VHBEuzQRGH5ul3s7jTYynE5HQL4duYOfQgJHPFwjgiX5udcjZ 4lYzqmEOZLPcUjBDL8iqu8H2+hn1f8yaZ+P2P0zy1yovrkvpdn2acPTIDM2ODEIDFTtI zJTKQHVHcLZ9DQ6P5FhsKojr6g5SgIyvmrpgPkzEA3iGpyAiZe8m9WvxHMXDSTDnWvKF g88vHzAoAEm58fEVvBN+4u/zu7HirrxjFha0qwBfpWCkARcOMcNMBYinSGl8qypjG63U p28XSqsIuv65PDWGarLaZ6vHrn19AN1T8wreGBHaawnFcGd/Rfmi/34mMGdsGnaf8oDL 6YHg== X-Gm-Message-State: AOJu0YxqWAUaH8uztcCjEfKPPvKmWsg/pwoJJHqco2UAX+pczwzjILau 6wRDBk95kL7orbOWw4OancBDjejZ2+HdDT+loKLDWN/KHbJcOUSXeUw1zCBy2W9MtcC+ie2gZEA mBZBDbEabt+W/5gI17CTxvID20OnPmYw8cQmQMcgUYIohtwTZiFG4IYEHQvW+bWxwDcXv+D6ZlB 8K9wiV2hixmyZeKzRYwPSdCC3HoNH1NfiwyTLPVHF/sXg= X-Gm-Gg: Acq92OFSSktZF7EKb7LgyDfioa2vwFV3qsVT7L7ZteCeZRiOlBBuyrPwpWXe8Io20w2 BkeMOt0cfJaUOxpKGILIzK4SbSD96anN8CWCCE0pO+aXybcry/HEXAa5pe49gPDbny/YAjk0la0 +YhUAhb81dzONGZ7gLpUZ8f7kADmEnrcRRSIx1r7btWPpcohyVk6JKIw6WBoBE1unZh/4ey/i9G L4yexjR+Y8h9Ssx2PkxEJTHGZkGOfdtUciui4weLLNNn9OMquMXrWbgaUwE6y+M+zAFW2XJHyMH HKyWVioPQtO45nNsjhdLa5QHlf6+7cVhQQ4LMN68OaGbyp+o01UuhuXoSzWelpCtPRqfSzUnOLb 06DjxS0KPGjDi+58KSfGkgmCVPm1CU9gv0OoPQX8z X-Received: by 2002:a5d:5f50:0:b0:43c:fbfa:20a0 with SMTP id ffacd0b85a97d-45c79f29848mr16491f8f.25.1778619998302; Tue, 12 May 2026 14:06:38 -0700 (PDT) X-Received: by 2002:a5d:5f50:0:b0:43c:fbfa:20a0 with SMTP id ffacd0b85a97d-45c79f29848mr16404f8f.25.1778619997694; Tue, 12 May 2026 14:06:37 -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 ffacd0b85a97d-4548ec6b071sm35131308f8f.14.2026.05.12.14.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:06:37 -0700 (PDT) Date: Tue, 12 May 2026 17:06:32 -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 v7 16/31] mm: use __GFP_ZERO in vma_alloc_anon_folio_pmd Message-ID: <94f20c24024cde2587026ca881a6a7ec64e264d4.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. 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 =3D vma_thp_gfp_mask(vma); + gfp_t gfp =3D vma_thp_gfp_mask(vma) | __GFP_ZERO; const int order =3D HPAGE_PMD_ORDER; struct folio *folio; =20 @@ -1356,14 +1356,6 @@ static struct folio *vma_alloc_anon_folio_pmd(struct= vm_area_struct *vma, } folio_throttle_swaprate(folio, gfp); =20 - /* - * 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() --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 8D2013C9EE8 for ; Tue, 12 May 2026 21:06:48 +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=1778620010; cv=none; b=aMfBuWwC1AalCdYmeJKaTMqnwvQm3GfSUUfgrxs8j+1FT52TXyJWVTmKeP6v29kg7ILQpNCAi+iC5d4i9hXi6dP6EKlitn9/9nYGEp0wei6iw73Nwo805uhLVwq/8jFFx2w6VJwe4tFPSogy71yoDyQchgq/zdVkIkB8Oh8FKnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620010; c=relaxed/simple; bh=Fr/n3byBI3/9vce54lTpx0wBWLZF4RYfr6e87KulLpI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z8zh6CWlaEpL78QAqffw0TPEaqLzADFPIZImWVE4kqWmHt6OgjCrRuIIydfHo9vkUiOOnrBacfKMNueUeDFGsUlaJ9+nOmlGgTMgMu972FHpTYdMXF1zTL1hRO9FovHo/1DwX0P9Oaal4zcrRAXDDjxwMX3kTUgdTrhhrOZMBeo= 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=IizAbap1; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=AfbLaRpm; 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="IizAbap1"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="AfbLaRpm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620007; 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=g/Cxk+5FcCUhBSxOxnUb0BunlHOXkLH/UUFvsIViUiI=; b=IizAbap13feK6O1ModG3g9Key6JIVqmCNDuN2nlDtksaHtyazI+wPcxRnvA2rSXpzf89JO 504lF6PD/6x8W5sgBlBQf07nXkCfLrXQfXKrzcfJUEjjCwN2w7E6gz/guinY7QBo0Kj2Tc hAVioOqdgLJK59v3WeBQt7QDnEBPyQo= 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-327-d_wqmtirNNyaUcT6wUzGgA-1; Tue, 12 May 2026 17:06:45 -0400 X-MC-Unique: d_wqmtirNNyaUcT6wUzGgA-1 X-Mimecast-MFC-AGG-ID: d_wqmtirNNyaUcT6wUzGgA_1778620004 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-44ffa15dc73so5625988f8f.1 for ; Tue, 12 May 2026 14:06:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620004; x=1779224804; 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=g/Cxk+5FcCUhBSxOxnUb0BunlHOXkLH/UUFvsIViUiI=; b=AfbLaRpmxCqJQtsg6qSWVSF3u1KtxBQ5UYroCcx+JriddgFBQzgGNoirUCLee8yEk5 tl1U4vQKhQqLPJOW/ddmPOf5gLN+B123ds8N8V7/ClS94iZI9G49+Vo1lIwgwseINTHZ wSJoMZEeqhcrNMnmiMNzyCj/RKFa3s9r98vxugrtPcdOUyk3YvL+s72/f3hxXEqGcOHq SiEM3w9kuSXbtk1LEJNFYMOycNdvNQo3xzj+pd5xnsUc3Wc0cR4xbE03IeKCnd45KCdu xQ8dDXA2uDxkY0JhWYTNCgCt7bsqOrpuNF+N5vhU45OWi/E3ygi5oEUwI29/S/SERlp2 FRoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620004; x=1779224804; 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=g/Cxk+5FcCUhBSxOxnUb0BunlHOXkLH/UUFvsIViUiI=; b=SwN4SdxI4+Y3It0AJojqMtFQ9NWMdEF4O/nXhrL3U+3dA6776kQAkWqdCD29ZnK8Ui Qji2tNGIbO9moAtoP206lAZmxByybtE9COWIlsrIMM/+qMajsBLfnFW/sWX6ix51SSqc vUHFpptipra1z2POnwnCGk/egsN9ZyQGe3Cj/RqmlSRtTCf90GdqRHlMGe6LE3qosCkT lf933mAnrKgZ7ppWqDBJiTiUbJolCQYEh3lh2W9PMQUcAVxNTCrO7M8kLSARMexENffa CZsgYgW61y5RAdVWjptH0VuNhX2fVvxiM2FYDGsH53OZ6HNroOi/Sqc8W1Fgd2EvDT8W IMbQ== X-Gm-Message-State: AOJu0YyXM04iSjgJcAb0zpCtrwmtbM+JYKbQ2qk/napiI1h2uBZ7vghb exnQKOT2Ux0rx072Uoe+ngm3KJb+kOMga/ya5U7ylXaLWV/Tqfs0aQLP6wh3zIT8pBzN/ndFJrW 0BmpKxSdj8EOsEpER4/BbH3NocJuw7oc7ih/Xwex6QDK2ZvYhD3gy5XUzizDQH5m10pqXVVzC+Y irsoakoCNi3QWW9Iabetq2vpvipvCblSuK+ZcNBemXLfw= X-Gm-Gg: Acq92OHLyWH36oBQbqXEjnwEhlL9RdNpLcHdtYZvzWUgfiS8mhkwsfoOrM6V+zd+UFD GRJqB2ENv1yuunMvDHZahtsqPVouLAoKAI3Ek0kEqoS8QvR3lS3dfAxoRyKoJElHs7S/V4y59jj zyjle2a55M3WzrajQbXWFbTs1pmJlAVmMxRou1jE9tcqnnp1Mij1xgEiSqGfgII2phqUUqLDgNf Nqq+HpQP9AdsYUL30M3i0ak68zm6wNU12nE+RAV0sIl6yI4nxAZKnVvSgvFya4aNsNCxa3BdIxn kiA8bzmsqx+1QAwdP5Iumfdozy13U+HK/LbWgxm67VTI6b9ew6YLFg4a5711q6cNqa8y/vZSn77 8PY6z/NkFNBbfiynY/P3DPHtuQbwSpMtrLROa8ych X-Received: by 2002:a05:6000:2506:b0:452:c246:ab69 with SMTP id ffacd0b85a97d-45c7814a806mr40271f8f.13.1778620003621; Tue, 12 May 2026 14:06:43 -0700 (PDT) X-Received: by 2002:a05:6000:2506:b0:452:c246:ab69 with SMTP id ffacd0b85a97d-45c7814a806mr40192f8f.13.1778620002975; Tue, 12 May 2026 14:06:42 -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 ffacd0b85a97d-45491ca383asm34333795f8f.28.2026.05.12.14.06.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:06:42 -0700 (PDT) Date: Tue, 12 May 2026 17:06:37 -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 v7 17/31] mm: hugetlb: add gfp parameter and skip zeroing for zeroed pages Message-ID: <4039b0b96594b69b15ad4bcd64cbb33de3cec350.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a gfp_t parameter to alloc_hugetlb_folio(). When __GFP_ZERO is set, the function guarantees the returned folio is zeroed: - Fresh allocations (buddy or gigantic): zeroed by post_alloc_hook via __GFP_ZERO. - Pool pages with HPG_zeroed set: already zeroed, skip. - Pool pages without HPG_zeroed: zeroed via folio_zero_user(). The address parameter is renamed to user_addr; the function aligns it internally for reservation and NUMA policy lookups. For pool pages that need zeroing, user_addr is passed to folio_zero_user() for cache-friendly zeroing near the faulting subpage. All callers pass a page-aligned address; the hugetlb_no_page caller passes vmf->real_address & PAGE_MASK for consistency. HPG_zeroed (stored in hugetlb folio->private bits) tracks known-zero pool pages. It is set when alloc_surplus_hugetlb_folio allocates with __GFP_ZERO, and cleared in free_huge_folio when the page returns to the pool after userspace use. Suggested-by: Gregory Price Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh Reviewed-by: Gregory Price --- fs/hugetlbfs/inode.c | 3 +-- include/linux/hugetlb.h | 5 ++++- mm/hugetlb.c | 47 ++++++++++++++++++++++++++++++----------- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 8b05bec08e04..5856a3530c7b 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -810,13 +810,12 @@ static long hugetlbfs_fallocate(struct file *file, in= t mode, loff_t offset, * folios in these areas, we need to consume the reserves * to keep reservation accounting consistent. */ - folio =3D alloc_hugetlb_folio(&pseudo_vma, addr, false); + folio =3D alloc_hugetlb_folio(&pseudo_vma, addr, false, __GFP_ZERO); if (IS_ERR(folio)) { mutex_unlock(&hugetlb_fault_mutex_table[hash]); error =3D PTR_ERR(folio); goto out; } - folio_zero_user(folio, addr); __folio_mark_uptodate(folio); error =3D hugetlb_add_to_page_cache(folio, mapping, index); if (unlikely(error)) { diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index f016bc2e8936..49e5557d6cc0 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -599,6 +599,7 @@ enum hugetlb_page_flags { HPG_vmemmap_optimized, HPG_raw_hwp_unreliable, HPG_cma, + HPG_zeroed, __NR_HPAGEFLAGS, }; =20 @@ -659,6 +660,7 @@ HPAGEFLAG(Freed, freed) HPAGEFLAG(VmemmapOptimized, vmemmap_optimized) HPAGEFLAG(RawHwpUnreliable, raw_hwp_unreliable) HPAGEFLAG(Cma, cma) +HPAGEFLAG(Zeroed, zeroed) =20 #ifdef CONFIG_HUGETLB_PAGE =20 @@ -706,7 +708,8 @@ int isolate_or_dissolve_huge_folio(struct folio *folio,= struct list_head *list); int replace_free_hugepage_folios(unsigned long start_pfn, unsigned long en= d_pfn); void wait_for_freed_hugetlb_folios(void); struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, - unsigned long addr, bool cow_from_owner); + unsigned long user_addr, bool cow_from_owner, + gfp_t gfp); struct folio *alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred= _nid, nodemask_t *nmask, gfp_t gfp_mask, bool allow_alloc_fallback); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a999f3ead852..2ea078d4e5a8 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1708,6 +1708,9 @@ void free_huge_folio(struct folio *folio) int nid =3D folio_nid(folio); struct hugepage_subpool *spool =3D hugetlb_folio_subpool(folio); bool restore_reserve; + + /* Page was mapped to userspace; no longer known-zero */ + folio_clear_hugetlb_zeroed(folio); unsigned long flags; =20 VM_BUG_ON_FOLIO(folio_ref_count(folio), folio); @@ -2110,6 +2113,10 @@ static struct folio *alloc_surplus_hugetlb_folio(str= uct hstate *h, if (!folio) return NULL; =20 + /* Mark as known-zero only if __GFP_ZERO was requested */ + if (gfp_mask & __GFP_ZERO) + folio_set_hugetlb_zeroed(folio); + spin_lock_irq(&hugetlb_lock); /* * nr_huge_pages needs to be adjusted within the same lock cycle @@ -2173,11 +2180,11 @@ static struct folio *alloc_migrate_hugetlb_folio(st= ruct hstate *h, gfp_t gfp_mas */ static struct folio *alloc_buddy_hugetlb_folio_with_mpol(struct hstate *h, - struct vm_area_struct *vma, unsigned long addr) + struct vm_area_struct *vma, unsigned long addr, gfp_t gfp) { struct folio *folio =3D NULL; struct mempolicy *mpol; - gfp_t gfp_mask =3D htlb_alloc_mask(h); + gfp_t gfp_mask =3D htlb_alloc_mask(h) | gfp; int nid; nodemask_t *nodemask; =20 @@ -2874,16 +2881,20 @@ typedef enum { * When it's set, the allocation will bypass all vma level reservations. */ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, - unsigned long addr, bool cow_from_owner) + unsigned long user_addr, bool cow_from_owner, + gfp_t gfp) { struct hugepage_subpool *spool =3D subpool_vma(vma); struct hstate *h =3D hstate_vma(vma); + unsigned long addr =3D user_addr & huge_page_mask(h); struct folio *folio; long retval, gbl_chg, gbl_reserve; map_chg_state map_chg; int ret, idx; struct hugetlb_cgroup *h_cg =3D NULL; - gfp_t gfp =3D htlb_alloc_mask(h) | __GFP_RETRY_MAYFAIL; + bool from_pool; + + gfp |=3D htlb_alloc_mask(h) | __GFP_RETRY_MAYFAIL; =20 idx =3D hstate_index(h); =20 @@ -2951,13 +2962,15 @@ struct folio *alloc_hugetlb_folio(struct vm_area_st= ruct *vma, folio =3D dequeue_hugetlb_folio_vma(h, vma, addr, gbl_chg); if (!folio) { spin_unlock_irq(&hugetlb_lock); - folio =3D alloc_buddy_hugetlb_folio_with_mpol(h, vma, addr); + folio =3D alloc_buddy_hugetlb_folio_with_mpol(h, vma, user_addr, gfp); if (!folio) goto out_uncharge_cgroup; spin_lock_irq(&hugetlb_lock); list_add(&folio->lru, &h->hugepage_activelist); folio_ref_unfreeze(folio, 1); - /* Fall through */ + from_pool =3D false; + } else { + from_pool =3D true; } =20 /* @@ -2980,6 +2993,11 @@ struct folio *alloc_hugetlb_folio(struct vm_area_str= uct *vma, =20 spin_unlock_irq(&hugetlb_lock); =20 + if ((gfp & __GFP_ZERO) && from_pool && + !folio_test_hugetlb_zeroed(folio)) + folio_zero_user(folio, user_addr); + folio_clear_hugetlb_zeroed(folio); + hugetlb_set_folio_subpool(folio, spool); =20 if (map_chg !=3D MAP_CHG_ENFORCED) { @@ -4988,7 +5006,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, st= ruct mm_struct *src, spin_unlock(src_ptl); spin_unlock(dst_ptl); /* Do not use reserve as it's private owned */ - new_folio =3D alloc_hugetlb_folio(dst_vma, addr, false); + new_folio =3D alloc_hugetlb_folio(dst_vma, addr, false, 0); if (IS_ERR(new_folio)) { folio_put(pte_folio); ret =3D PTR_ERR(new_folio); @@ -5517,7 +5535,7 @@ static vm_fault_t hugetlb_wp(struct vm_fault *vmf) * be acquired again before returning to the caller, as expected. */ spin_unlock(vmf->ptl); - new_folio =3D alloc_hugetlb_folio(vma, vmf->address, cow_from_owner); + new_folio =3D alloc_hugetlb_folio(vma, vmf->address, cow_from_owner, 0); =20 if (IS_ERR(new_folio)) { /* @@ -5777,7 +5795,13 @@ static vm_fault_t hugetlb_no_page(struct address_spa= ce *mapping, goto out; } =20 - folio =3D alloc_hugetlb_folio(vma, vmf->address, false); + /* + * Passing vmf->real_address would work just as well, + * but PAGE_MASK helps make sure we never pass + * USER_ADDR_NONE by mistake. + */ + folio =3D alloc_hugetlb_folio(vma, vmf->real_address & PAGE_MASK, + false, __GFP_ZERO); if (IS_ERR(folio)) { /* * Returning error will result in faulting task being @@ -5797,7 +5821,6 @@ static vm_fault_t hugetlb_no_page(struct address_spac= e *mapping, ret =3D 0; goto out; } - folio_zero_user(folio, vmf->real_address); __folio_mark_uptodate(folio); new_folio =3D true; =20 @@ -6236,7 +6259,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, goto out; } =20 - folio =3D alloc_hugetlb_folio(dst_vma, dst_addr, false); + folio =3D alloc_hugetlb_folio(dst_vma, dst_addr, false, 0); if (IS_ERR(folio)) { pte_t *actual_pte =3D hugetlb_walk(dst_vma, dst_addr, PMD_SIZE); if (actual_pte) { @@ -6283,7 +6306,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, goto out; } =20 - folio =3D alloc_hugetlb_folio(dst_vma, dst_addr, false); + folio =3D alloc_hugetlb_folio(dst_vma, dst_addr, false, 0); if (IS_ERR(folio)) { folio_put(*foliop); ret =3D -ENOMEM; --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 725383CB2FC for ; Tue, 12 May 2026 21:06:52 +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=1778620014; cv=none; b=KC4cQ920Ya4h4EVehLW2vCiFEA1rmkXL65sTbaZyf86BnVJnNXdae4w0/tAdnKd/ag11brWToskjDt3OC9dJA6IGGJt1426SgceFqCC5sp9kjaFRhj2pvYTZXd8giFgDn+ND4PcFbQSDJk0RUJboFBc6hUJtEVkr/0SVJ38z/mE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620014; c=relaxed/simple; bh=yxS5pGAT+aBz/tCSPnjyQeoSUdyPcongdUsCoZ0a1X4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jspJXoBMtay7gms2c8sDKyayVx9BSkhv5ubXa5ZjsZqtFhO1rYeoJkCA1uVdjTW+3xIeGxNK4zFUjjY65cpF2XIc9Mi+c46Ef3gICLIa3LFE4FykX/nqdx/uEdjqhJ3QKXmrxtNt2CmfP919qTbAJlNB7A48HcJebh3dDBr1eKk= 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=b3tTjBPb; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=EsTEa7JM; 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="b3tTjBPb"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="EsTEa7JM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620011; 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=vgzEDqlvhoYP0aAGYME8rWUPvmasj5/ucpL5w8urRD4=; b=b3tTjBPbVDQGNXjfJz7pLiU27TlvDJ03gqrMPTwCQjtvyZgNFk0NkTYgsKaaQ/zZyJ3oke sdp4y+bt5Aq/zMWQmk2ZyXmikF6ic50Krdy49zhGhK0c4Btcla+sBhgyDPwz6PfRqLrQPx xmH/WDNG9i47spf8eOuBT3VBJRb+j3E= 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-589-n3MXBJdzNQCv4WhBIlGhCQ-1; Tue, 12 May 2026 17:06:50 -0400 X-MC-Unique: n3MXBJdzNQCv4WhBIlGhCQ-1 X-Mimecast-MFC-AGG-ID: n3MXBJdzNQCv4WhBIlGhCQ_1778620009 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48a589c7879so53152045e9.1 for ; Tue, 12 May 2026 14:06:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620009; x=1779224809; 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=vgzEDqlvhoYP0aAGYME8rWUPvmasj5/ucpL5w8urRD4=; b=EsTEa7JM8lS1iWMESN/KSPb8X4EPD80fJhy9TZiUkoBv9Qhux2bL/+3crIjIXyxpQw RjyoS9ujCb6Aj4JFsgj3wI+a08aDwLbpDpoAtQfn+/ZcPkDxiRwqUvNXFhM0rQXtG7fj TxlkXH05KqTP5mUIs9Vvr1frfIUy8OH3PytSQDzqQCelGeLZpBHL8HTEnnQrgldRUSBr QMVaoVLl/Y4Q6Q4lC5n16ZQOQD8jP+SbWJEviQjLJIBCNxZ+ApEWtCuMRm+YGEYivr2j kXAsEbzJZ4rGT0k3+PofpCYs61DL4C7fcjVXTJRsFMSvgl+azRh8FQarwVg+2J4QzrEJ dIIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620009; x=1779224809; 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=vgzEDqlvhoYP0aAGYME8rWUPvmasj5/ucpL5w8urRD4=; b=lOXVJK5T6PKEv4h1DJsgz65KSEWq2BMt4o9/aCagFIObv9ppTEZewWUkS00MaAUnhD MUkvRBnywH3bGi44rpLsSTKp6XKibnL8IAIzS9F1B86tAHnRqXAh4+1FGYzZVfxj9OlM p8eznK11ZMZACKdl/2g/CTi/bl9AxD3WLNKeDJ33dlHEZcAEBHt8nQNyB1c0F0K1CsVX XNYEuFiV1M0Vpi77LgZ3/v3oorUxEtFuz3MfKtBoi4X6HHfrpQz8E7YYlTYSJKI378t+ oOQj6PCm/EBHNEoNJG3APLqIL4D5SkidsY2co04UXiaKgh3Lg2GICR+Gjk+/FIc2nR/l v47Q== X-Gm-Message-State: AOJu0Yw7eb/WD8zT818k1If+CVQnGNGNrjv+kXtxIBfCDHJocsOUnfvB mHCyk/+1DYmkxpDJ0xuUpGLXheZmvR/UVzw+486mlbPb90JLCl25bUnbJcrWnOvw2G2cTO/0IIR 3VGkKrVD+Dj/wpgOrDtNN8wM7HYAaYq6T8QoJqsCC9mllf9Ngg4n/ZMPisIVjiBSysEG/byrAtm o6Kp1WZ8zHrYAw8S3pB19jGbHqy8WNn4ksiRAmqwSbqhU= X-Gm-Gg: Acq92OFmMMXMoJNdVOMenaOog6UJAWM/6sx4p6GVxMTc5zMIOFk1gneIH3quHIzCb+Z e8bT5vpMzgL/NPu1rKCvfAy0GBFaMY+EHMfvXg1AIL2LhN3nChhI3LgrXq1cHaMyiebBoOOn1kn ZdKmDOXs37EC4Tcz7T6JyCg/6ifV6/d81xGCpUvtfyFIADwmtGy626d1LBSL4KkvPp0/mjF9vH5 LF3BmoIj6SYSJpXUY6TZxV5mPWkgzhxMSTEauRStVvwh+u4dckG41268aerWBJXIs/JcSoSGaKh R/CCSX270IsuZG5V/BY10Wa2QeKqsjcZnoYp7sUNVOiyaRHL/Qdp+EKmCL/p+kNwJxpV1aof8Sn jOsOxAXw938OSH1qpmcdhRAcmRsNtpkygXyCGVKAc X-Received: by 2002:a05:600c:4ed1:b0:488:aa33:dc8f with SMTP id 5b1f17b1804b1-48fc95a5989mr7783835e9.0.1778620008969; Tue, 12 May 2026 14:06:48 -0700 (PDT) X-Received: by 2002:a05:600c:4ed1:b0:488:aa33:dc8f with SMTP id 5b1f17b1804b1-48fc95a5989mr7783135e9.0.1778620008280; Tue, 12 May 2026 14:06:48 -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-48fce065732sm23005e9.6.2026.05.12.14.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:06:47 -0700 (PDT) Date: Tue, 12 May 2026 17:06:43 -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 v7 18/31] mm: memfd: skip zeroing for zeroed hugetlb pool pages Message-ID: <0ec51a9091b5ed3f61a49935953dd537d6c87428.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" gather_surplus_pages() pre-allocates hugetlb pages into the pool during mmap. Pass __GFP_ZERO so these pages are zeroed by the buddy allocator, and HPG_zeroed is set by alloc_surplus_hugetlb_folio. Add bool *zeroed output to alloc_hugetlb_folio_reserve() so callers can check whether the pool page is known-zero. memfd's memfd_alloc_folio() uses this to skip the explicit folio_zero_user() when the page is already zero. This avoids redundant zeroing for memfd hugetlb pages that were pre-allocated into the pool and never mapped to userspace. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- include/linux/hugetlb.h | 6 ++++-- mm/hugetlb.c | 11 +++++++++-- mm/memfd.c | 14 ++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 49e5557d6cc0..3d23267014e6 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -714,7 +714,8 @@ struct folio *alloc_hugetlb_folio_nodemask(struct hstat= e *h, int preferred_nid, nodemask_t *nmask, gfp_t gfp_mask, bool allow_alloc_fallback); struct folio *alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_= nid, - nodemask_t *nmask, gfp_t gfp_mask); + nodemask_t *nmask, gfp_t gfp_mask, + bool *zeroed); =20 int hugetlb_add_to_page_cache(struct folio *folio, struct address_space *m= apping, pgoff_t idx); @@ -1134,7 +1135,8 @@ static inline void wait_for_freed_hugetlb_folios(void) =20 static inline struct folio * alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid, - nodemask_t *nmask, gfp_t gfp_mask) + nodemask_t *nmask, gfp_t gfp_mask, + bool *zeroed) { return NULL; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 2ea078d4e5a8..0a19a078d860 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2205,7 +2205,7 @@ struct folio *alloc_buddy_hugetlb_folio_with_mpol(str= uct hstate *h, } =20 struct folio *alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_= nid, - nodemask_t *nmask, gfp_t gfp_mask) + nodemask_t *nmask, gfp_t gfp_mask, bool *zeroed) { struct folio *folio; =20 @@ -2221,6 +2221,12 @@ struct folio *alloc_hugetlb_folio_reserve(struct hst= ate *h, int preferred_nid, h->resv_huge_pages--; =20 spin_unlock_irq(&hugetlb_lock); + + if (zeroed && folio) { + *zeroed =3D folio_test_hugetlb_zeroed(folio); + folio_clear_hugetlb_zeroed(folio); + } + return folio; } =20 @@ -2305,7 +2311,8 @@ static int gather_surplus_pages(struct hstate *h, lon= g delta) * It is okay to use NUMA_NO_NODE because we use numa_mem_id() * down the road to pick the current node if that is the case. */ - folio =3D alloc_surplus_hugetlb_folio(h, htlb_alloc_mask(h), + folio =3D alloc_surplus_hugetlb_folio(h, + htlb_alloc_mask(h) | __GFP_ZERO, NUMA_NO_NODE, &alloc_nodemask, USER_ADDR_NONE); if (!folio) { diff --git a/mm/memfd.c b/mm/memfd.c index fb425f4e315f..5518f7d2d91f 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -69,6 +69,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff= _t idx) #ifdef CONFIG_HUGETLB_PAGE struct folio *folio; gfp_t gfp_mask; + bool zeroed; =20 if (is_file_hugepages(memfd)) { /* @@ -93,17 +94,18 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgo= ff_t idx) folio =3D alloc_hugetlb_folio_reserve(h, numa_node_id(), NULL, - gfp_mask); + gfp_mask, + &zeroed); if (folio) { u32 hash; =20 /* - * Zero the folio to prevent information leaks to userspace. - * Use folio_zero_user() which is optimized for huge/gigantic - * pages. Pass 0 as addr_hint since this is not a faulting path - * and we don't have a user virtual address yet. + * Zero the folio to prevent information leaks to + * userspace. Skip if the pool page is known-zero + * (HPG_zeroed set during pool pre-allocation). */ - folio_zero_user(folio, 0); + if (!zeroed) + folio_zero_user(folio, 0); =20 /* * Mark the folio uptodate before adding to page cache, --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 33E4E3CAE76 for ; Tue, 12 May 2026 21:06:59 +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=1778620021; cv=none; b=Dv/UMFdBo/hpa6Rys3Mric9VxJsFaTO300N5gkx9+YRwzw1algTGwqMcqJlFagHICslUo/xKOg8fKZ0W0ifQVKqNWO3hz99LPzXpuLuorHDKhUXMq34s1BtmL3FMuKDBwigx+GZq0pFCWFXhCrwkyTx3DYsgdWA215GnbL4rx/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620021; c=relaxed/simple; bh=dX64WbBAaz3t3ZSO0w4KwC4lTRHxR460P/X0S2tgmOw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bQNrzPJmm7k6LDViqYvTPnj7vIW+RdwSroutOFVsY/dhWuxpw03z7nNTH9QluHovhDIan2BjYPVL23Ffo4VmdvWDUas/jPKigurY92tiqiI7imeIctAKgL5kOuiF9gJsN+clWGUdl21hutXcUmofymlEbQuF8twI8svHA+P3DZA= 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=DnZ0tkDJ; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=AvU0A8JR; 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="DnZ0tkDJ"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="AvU0A8JR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620018; 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=n7ug8Z4kui901Eg+tMJ5hLVMh87nMDvb3T5J3R0m9NQ=; b=DnZ0tkDJuLnBf4I5nzcMzIiDw+1IYGRZtR1AF/SiUZGjianfSCDJgRetfTQHle5DxgDIeo L+VA+vkkzR/675yx2b9RKq6v1wLVQu9vrX8j7YF8mBfB1S+gqZmpLW+FYEfMAMMcbkjvlF HGn1lPmQ6vJEwr+UebiUDbHNICtnr5A= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-XGdVCTeGODCCS4ofl_gzmA-1; Tue, 12 May 2026 17:06:57 -0400 X-MC-Unique: XGdVCTeGODCCS4ofl_gzmA-1 X-Mimecast-MFC-AGG-ID: XGdVCTeGODCCS4ofl_gzmA_1778620015 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-44f56d5523eso4882482f8f.1 for ; Tue, 12 May 2026 14:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620015; x=1779224815; 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=n7ug8Z4kui901Eg+tMJ5hLVMh87nMDvb3T5J3R0m9NQ=; b=AvU0A8JRxNWDdzU8v1hxSPtLB2KPON4TwxzmSUtONVgfo68s2Nv5JzMeLSW4Kx6m+M n4l5SlvKAxh2Kmr0o+f9ea+vu//hVIIOihe6fu/5tCkvXpbfJxOWlr4Xez2l3ugtRhA/ 13f/6xISXEf23+CJKtHUv6rdrjlpO7hmJqu3bdEsiRGjSrxZUI1K327Zu7eYnMmV3Vl8 gbhakAsPfut+psmpEeMqQz0nyEyEYSvcUrJpGrSZZwbOHGRDGwu/MhyjRbHx28Jbc4F+ KsWJwDTc/yxuLsGPQtmJXWolEQzBhdbOCwr47EUqyjyPF5Kw3xAEWo2W2ZW+U8kmMMEC ZxUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620015; x=1779224815; 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=n7ug8Z4kui901Eg+tMJ5hLVMh87nMDvb3T5J3R0m9NQ=; b=UWGoPB2E9wyExELnFs1dmeKAtLQ8QmIFOhrzoZTPNxmgqtO+rESaDGuBgVesX8xZA8 IUmW+oTB2kTjDoNwPH09rKs08O1fu4rpGq5AfHyU4uxv+rL6O36CU7LwJwn2itoN6YX5 PsDe/Oo26pf2CDgaMgwUvK15n5txGThEFsK3qAIndZkAhhgr932b/AHLOIlamIV+4ls6 ZsUr2rFflUNFDUBmRU9WC7BN0bbGjPzAXVTAtkXoMsFIdk3XJvAj0LaX33ow4SxrzAKL 2Iu9Dg6DruhKDeG2ssYxF+/0ncEquO6HtGP5YW6a5xRnE9rlsd6UisVynKCGc4VmNzoS rreA== X-Gm-Message-State: AOJu0YwXX58fPOOmcKP/vXJvhwTpfJHJr8TY5r9L7VuixDXpBqEUwKJU 10Av9ArXgbYnsEU4pO39JM/Ldh4fTctSfXbL9hXstrR3MqovUIsC9wlvX8e5o9+NmZ/qf/t4Anj Fv99lN3DdfdfQ1RgDAuiXZ4jlHsAk+5b4DrG1Hbu5S1AJ/gIks4WgwDoYi9kqCNpVo7JRCpdEgY YiVx0cFWlJxx8U5q/VIxtzDu9ZVCMfz9veULUbKb9ZS8Q= X-Gm-Gg: Acq92OGgLPQv/y6kPoMzL9fqj3prTcKsytVVzgIh1dSjCNb0PWXG8Ym/NFkiAKrr2es rJdBUH2KS6m9zMy4y+1GkwiBEleNkugBaap1sqhtRO1CoTTWj0TrebaG7EO7ue0eN/WqNfpWngm IrGbqWbA4C400h/EeCd6MzDvvw7QylKIUwYkOY1TIhJmLDxe0sGhBHG9UagH46Lvy+ScasMRxHD FVfg/pOLkwG9n1Jhvssco3stNPTXz8m1psdDX1GaWVsyR+z4pyLjpO6KlmWf+3VGONhmh3kWisc 8tDB7zPaU3ryOMdJ1OKQOfBdg6Ep5vzRV3ieEEYib5LTLm69SOjqpcwDW/UgZLStow3PZcyNh7H FH1OdLRlKHTmWae2A8W7SqnqCtzhe6xMDRn99BevG X-Received: by 2002:a05:600c:6303:b0:48a:592c:e632 with SMTP id 5b1f17b1804b1-48fc9a2b921mr6297475e9.16.1778620014424; Tue, 12 May 2026 14:06:54 -0700 (PDT) X-Received: by 2002:a05:600c:6303:b0:48a:592c:e632 with SMTP id 5b1f17b1804b1-48fc9a2b921mr6296645e9.16.1778620013630; Tue, 12 May 2026 14:06:53 -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-48fc8d1986fsm19666505e9.3.2026.05.12.14.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:06:53 -0700 (PDT) Date: Tue, 12 May 2026 17:06:48 -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 v7 19/31] mm: page_reporting: skip redundant zeroing of host-zeroed reported pages Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a guest reports free pages to the hypervisor via the page reporting framework (used by virtio-balloon and hv_balloon), the host typically zeros those pages when reclaiming their backing memory. However, when those pages are later allocated in the guest, post_alloc_hook() unconditionally zeros them again if __GFP_ZERO is set. This double-zeroing is wasteful, especially for large pages. Avoid redundant zeroing: - Add a host_zeroes_pages flag to page_reporting_dev_info, allowing drivers to declare that their host zeros reported pages on reclaim. A static key (page_reporting_host_zeroes) gates the fast path. - Add PG_zeroed page flag (sharing PG_private bit) to mark pages that have been zeroed by the host. Set it in page_reporting_drain() after the host reports them. - Thread the zeroed bool through rmqueue -> prep_new_page -> post_alloc_hook, where it skips redundant zeroing for __GFP_ZERO allocations. No driver sets host_zeroes_pages yet; a follow-up patch to virtio_balloon is needed to opt in. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/page-flags.h | 9 +++++ include/linux/page_reporting.h | 3 ++ mm/compaction.c | 6 ++-- mm/internal.h | 2 +- mm/page_alloc.c | 66 +++++++++++++++++++++++----------- mm/page_reporting.c | 14 +++++++- mm/page_reporting.h | 12 +++++++ 7 files changed, 87 insertions(+), 25 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 0e03d816e8b9..4ee64134acc3 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -135,6 +135,8 @@ enum pageflags { PG_swapcache =3D PG_owner_priv_1, /* Swap page: swp_entry_t in private */ /* Some filesystems */ PG_checked =3D PG_owner_priv_1, + /* Page contents are known to be zero */ + PG_zeroed =3D PG_private, =20 /* * Depending on the way an anonymous folio can be mapped into a page @@ -673,6 +675,13 @@ FOLIO_TEST_CLEAR_FLAG_FALSE(young) FOLIO_FLAG_FALSE(idle) #endif =20 +/* + * PageZeroed() tracks pages known to be zero. The allocator + * uses this to skip redundant zeroing in post_alloc_hook(). + */ +__PAGEFLAG(Zeroed, zeroed, PF_NO_COMPOUND) +#define __PG_ZEROED (1UL << PG_zeroed) + /* * PageReported() is used to track reported free pages within the Buddy * allocator. We can use the non-atomic version of the test and set diff --git a/include/linux/page_reporting.h b/include/linux/page_reporting.h index 5ab5be02fa15..c331c6b36687 100644 --- a/include/linux/page_reporting.h +++ b/include/linux/page_reporting.h @@ -14,6 +14,9 @@ struct page_reporting_dev_info { int (*report)(struct page_reporting_dev_info *prdev, struct scatterlist *sg, unsigned int nents); =20 + /* If true, host zeros reported pages on reclaim */ + bool host_zeroes_pages; + /* work struct for processing reports */ struct delayed_work work; =20 diff --git a/mm/compaction.c b/mm/compaction.c index 4336e433c99b..8000fc5e0a2e 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -82,7 +82,8 @@ static inline bool is_via_compact_memory(int order) { ret= urn false; } =20 static struct page *mark_allocated_noprof(struct page *page, unsigned int = order, gfp_t gfp_flags) { - post_alloc_hook(page, order, __GFP_MOVABLE, USER_ADDR_NONE); + __ClearPageZeroed(page); + post_alloc_hook(page, order, __GFP_MOVABLE, false, USER_ADDR_NONE); set_page_refcounted(page); return page; } @@ -1849,9 +1850,10 @@ static struct folio *compaction_alloc_noprof(struct = folio *src, unsigned long da set_page_private(&freepage[size], start_order); } dst =3D (struct folio *)freepage; + __ClearPageZeroed(&dst->page); if (order) prep_compound_page(&dst->page, order); - post_alloc_hook(&dst->page, order, __GFP_MOVABLE, USER_ADDR_NONE); + post_alloc_hook(&dst->page, order, __GFP_MOVABLE, false, USER_ADDR_NONE); set_page_refcounted(&dst->page); cc->nr_freepages -=3D 1 << order; cc->nr_migratepages -=3D 1 << order; diff --git a/mm/internal.h b/mm/internal.h index 389098200aa6..fd910743ddc3 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -928,7 +928,7 @@ static inline void init_compound_tail(struct page *tail, } =20 void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flag= s, - unsigned long user_addr); + bool zeroed, unsigned long user_addr); extern bool free_pages_prepare(struct page *page, unsigned int order); =20 extern int user_min_free_kbytes; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 76f39dd026ff..bd3b909cacdf 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1743,6 +1743,7 @@ static __always_inline void page_del_and_expand(struc= t zone *zone, bool was_reported =3D page_reported(page); =20 __del_page_from_free_list(page, zone, high, migratetype); + nr_pages -=3D expand(zone, page, low, high, migratetype, was_reported); account_freepages(zone, -nr_pages, migratetype); } @@ -1815,8 +1816,10 @@ static inline bool should_skip_init(gfp_t flags) return (flags & __GFP_SKIP_ZERO); } =20 + inline void post_alloc_hook(struct page *page, unsigned int order, - gfp_t gfp_flags, unsigned long user_addr) + gfp_t gfp_flags, bool zeroed, + unsigned long user_addr) { bool init =3D !want_init_on_free() && want_init_on_alloc(gfp_flags) && !should_skip_init(gfp_flags); @@ -1825,6 +1828,14 @@ inline void post_alloc_hook(struct page *page, unsig= ned int order, =20 set_page_private(page, 0); =20 + /* + * If the page is zeroed, skip memory initialization. + * We still need to handle tag zeroing separately since the host + * does not know about memory tags. + */ + if (zeroed && init && !zero_tags) + init =3D false; + arch_alloc_page(page, order); debug_pagealloc_map_pages(page, 1 << order); =20 @@ -1882,13 +1893,13 @@ inline void post_alloc_hook(struct page *page, unsi= gned int order, } =20 static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp= _flags, - unsigned int alloc_flags, - unsigned long user_addr) + unsigned int alloc_flags, bool zeroed, + unsigned long user_addr) { if (order && (gfp_flags & __GFP_COMP)) prep_compound_page(page, order); =20 - post_alloc_hook(page, order, gfp_flags, user_addr); + post_alloc_hook(page, order, gfp_flags, zeroed, user_addr); =20 /* * page is set pfmemalloc when ALLOC_NO_WATERMARKS was necessary to @@ -3154,6 +3165,7 @@ int __isolate_free_page(struct page *page, unsigned i= nt order) } =20 del_page_from_free_list(page, zone, order, mt); + __ClearPageZeroed(page); =20 /* * Set the pageblock if the isolated page is at least half of a @@ -3226,7 +3238,7 @@ static inline void zone_statistics(struct zone *prefe= rred_zone, struct zone *z, static __always_inline struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone, unsigned int order, unsigned int alloc_flags, - int migratetype) + int migratetype, bool *zeroed) { struct page *page; unsigned long flags; @@ -3261,6 +3273,8 @@ struct page *rmqueue_buddy(struct zone *preferred_zon= e, struct zone *zone, } } spin_unlock_irqrestore(&zone->lock, flags); + *zeroed =3D PageZeroed(page); + __ClearPageZeroed(page); } while (check_new_pages(page, order)); =20 /* @@ -3329,10 +3343,9 @@ static int nr_pcp_alloc(struct per_cpu_pages *pcp, s= truct zone *zone, int order) /* Remove page from the per-cpu list, caller must protect the list */ static inline struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order, - int migratetype, - unsigned int alloc_flags, + int migratetype, unsigned int alloc_flags, struct per_cpu_pages *pcp, - struct list_head *list) + struct list_head *list, bool *zeroed) { struct page *page; =20 @@ -3367,6 +3380,8 @@ struct page *__rmqueue_pcplist(struct zone *zone, uns= igned int order, page =3D list_first_entry(list, struct page, pcp_list); list_del(&page->pcp_list); pcp->count -=3D 1 << order; + *zeroed =3D PageZeroed(page); + __ClearPageZeroed(page); } while (check_new_pages(page, order)); =20 return page; @@ -3375,7 +3390,8 @@ struct page *__rmqueue_pcplist(struct zone *zone, uns= igned int order, /* Lock and remove page from the per-cpu list */ static struct page *rmqueue_pcplist(struct zone *preferred_zone, struct zone *zone, unsigned int order, - int migratetype, unsigned int alloc_flags) + int migratetype, unsigned int alloc_flags, + bool *zeroed) { struct per_cpu_pages *pcp; struct list_head *list; @@ -3393,7 +3409,8 @@ static struct page *rmqueue_pcplist(struct zone *pref= erred_zone, */ pcp->free_count >>=3D 1; list =3D &pcp->lists[order_to_pindex(migratetype, order)]; - page =3D __rmqueue_pcplist(zone, order, migratetype, alloc_flags, pcp, li= st); + page =3D __rmqueue_pcplist(zone, order, migratetype, alloc_flags, + pcp, list, zeroed); pcp_spin_unlock(pcp); if (page) { __count_zid_vm_events(PGALLOC, page_zonenum(page), 1 << order); @@ -3418,19 +3435,19 @@ static inline struct page *rmqueue(struct zone *preferred_zone, struct zone *zone, unsigned int order, gfp_t gfp_flags, unsigned int alloc_flags, - int migratetype) + int migratetype, bool *zeroed) { struct page *page; =20 if (likely(pcp_allowed_order(order))) { page =3D rmqueue_pcplist(preferred_zone, zone, order, - migratetype, alloc_flags); + migratetype, alloc_flags, zeroed); if (likely(page)) goto out; } =20 page =3D rmqueue_buddy(preferred_zone, zone, order, alloc_flags, - migratetype); + migratetype, zeroed); =20 out: /* Separate test+clear to avoid unnecessary atomics */ @@ -3821,6 +3838,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int o= rder, int alloc_flags, struct pglist_data *last_pgdat =3D NULL; bool last_pgdat_dirty_ok =3D false; bool no_fallback; + bool zeroed; bool skip_kswapd_nodes =3D nr_online_nodes > 1; bool skipped_kswapd_nodes =3D false; =20 @@ -3965,10 +3983,11 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int= order, int alloc_flags, =20 try_this_zone: page =3D rmqueue(zonelist_zone(ac->preferred_zoneref), zone, order, - gfp_mask, alloc_flags, ac->migratetype); + gfp_mask, alloc_flags, ac->migratetype, + &zeroed); if (page) { prep_new_page(page, order, gfp_mask, alloc_flags, - ac->user_addr); + zeroed, ac->user_addr); =20 return page; } else { @@ -4195,9 +4214,11 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigne= d int order, count_vm_event(COMPACTSTALL); =20 /* Prep a captured page if available */ - if (page) - prep_new_page(page, order, gfp_mask, alloc_flags, + if (page) { + __ClearPageZeroed(page); + prep_new_page(page, order, gfp_mask, alloc_flags, false, ac->user_addr); + } =20 /* Try get a page from the freelist if available */ if (!page) @@ -5170,6 +5191,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int = preferred_nid, /* Attempt the batch allocation */ pcp_list =3D &pcp->lists[order_to_pindex(ac.migratetype, 0)]; while (nr_populated < nr_pages) { + bool zeroed =3D false; =20 /* Skip existing pages */ if (page_array[nr_populated]) { @@ -5178,7 +5200,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int = preferred_nid, } =20 page =3D __rmqueue_pcplist(zone, 0, ac.migratetype, alloc_flags, - pcp, pcp_list); + pcp, pcp_list, &zeroed); if (unlikely(!page)) { /* Try and allocate at least one page */ if (!nr_account) { @@ -5189,7 +5211,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int = preferred_nid, } nr_account++; =20 - prep_new_page(page, 0, gfp, 0, USER_ADDR_NONE); + prep_new_page(page, 0, gfp, 0, zeroed, USER_ADDR_NONE); set_page_refcounted(page); page_array[nr_populated++] =3D page; } @@ -6929,7 +6951,8 @@ static void split_free_frozen_pages(struct list_head = *list, gfp_t gfp_mask) list_for_each_entry_safe(page, next, &list[order], lru) { int i; =20 - post_alloc_hook(page, order, gfp_mask, USER_ADDR_NONE); + __ClearPageZeroed(page); + post_alloc_hook(page, order, gfp_mask, false, USER_ADDR_NONE); if (!order) continue; =20 @@ -7134,8 +7157,9 @@ int alloc_contig_frozen_range_noprof(unsigned long st= art, unsigned long end, } else if (start =3D=3D outer_start && end =3D=3D outer_end && is_power_o= f_2(end - start)) { struct page *head =3D pfn_to_page(start); =20 + __ClearPageZeroed(head); check_new_pages(head, order); - prep_new_page(head, order, gfp_mask, 0, USER_ADDR_NONE); + prep_new_page(head, order, gfp_mask, 0, false, USER_ADDR_NONE); } else { ret =3D -EINVAL; WARN(true, "PFN range: requested [%lu, %lu), allocated [%lu, %lu)\n", diff --git a/mm/page_reporting.c b/mm/page_reporting.c index 006f7cdddc18..37e4fce9eb38 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -50,6 +50,8 @@ EXPORT_SYMBOL_GPL(page_reporting_order); #define PAGE_REPORTING_DELAY (2 * HZ) static struct page_reporting_dev_info __rcu *pr_dev_info __read_mostly; =20 +DEFINE_STATIC_KEY_FALSE(page_reporting_host_zeroes); + enum { PAGE_REPORTING_IDLE =3D 0, PAGE_REPORTING_REQUESTED, @@ -129,8 +131,11 @@ page_reporting_drain(struct page_reporting_dev_info *p= rdev, * report on the new larger page when we make our way * up to that higher order. */ - if (PageBuddy(page) && buddy_order(page) =3D=3D order) + if (PageBuddy(page) && buddy_order(page) =3D=3D order) { __SetPageReported(page); + if (page_reporting_host_zeroes_pages()) + __SetPageZeroed(page); + } } while ((sg =3D sg_next(sg))); =20 /* reinitialize scatterlist now that it is empty */ @@ -391,6 +396,10 @@ int page_reporting_register(struct page_reporting_dev_= info *prdev) /* Assign device to allow notifications */ rcu_assign_pointer(pr_dev_info, prdev); =20 + /* enable zeroed page optimization if host zeroes reported pages */ + if (prdev->host_zeroes_pages) + static_branch_enable(&page_reporting_host_zeroes); + /* enable page reporting notification */ if (!static_key_enabled(&page_reporting_enabled)) { static_branch_enable(&page_reporting_enabled); @@ -415,6 +424,9 @@ void page_reporting_unregister(struct page_reporting_de= v_info *prdev) =20 /* Flush any existing work, and lock it out */ cancel_delayed_work_sync(&prdev->work); + + if (prdev->host_zeroes_pages) + static_branch_disable(&page_reporting_host_zeroes); } =20 mutex_unlock(&page_reporting_mutex); diff --git a/mm/page_reporting.h b/mm/page_reporting.h index c51dbc228b94..736ea7b37e9e 100644 --- a/mm/page_reporting.h +++ b/mm/page_reporting.h @@ -15,6 +15,13 @@ DECLARE_STATIC_KEY_FALSE(page_reporting_enabled); extern unsigned int page_reporting_order; void __page_reporting_notify(void); =20 +DECLARE_STATIC_KEY_FALSE(page_reporting_host_zeroes); + +static inline bool page_reporting_host_zeroes_pages(void) +{ + return static_branch_unlikely(&page_reporting_host_zeroes); +} + static inline bool page_reported(struct page *page) { return static_branch_unlikely(&page_reporting_enabled) && @@ -46,6 +53,11 @@ static inline void page_reporting_notify_free(unsigned i= nt order) #else /* CONFIG_PAGE_REPORTING */ #define page_reported(_page) false =20 +static inline bool page_reporting_host_zeroes_pages(void) +{ + return false; +} + static inline void page_reporting_notify_free(unsigned int order) { } --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 2A9C53CA49A for ; Tue, 12 May 2026 21:07:03 +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=1778620024; cv=none; b=p0HcoR/cDfA6JH1xtKpBStlr0VZpu8PmNUKpranXpphAcxJVbME0pVSBFSBT9Ww8jAs/P/lwV7SmsEe6DsJV6VqnFv9jI9fXBtjei8X9jvyuvLvfKliMFzytoKuKE3OL7ZDtOOroIzbBH4Ctr40XHzbQGtl+qiCf2J4lzdOhC60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620024; c=relaxed/simple; bh=S3lspdseAiA9VDFP1z5oU53ONzTmuB9EAtNlvAmS1xQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GaPCd+ue4/bTfcQYgIayDP0OfRRKoLg2xpm7A5vQ9BA2zM+Ats6pTkKbwBF5OA9fNqzmJK6KsKnWG+exehbr20duRzL2FzIfGQQQJvs9jFbLS39h0jdvHHpv5ZVu1vKn2yLRFcSkIXCQYk8VTNS45UBZi5GQ3lOWCvKfSGrz958= 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=LtYtIIDi; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=HXpk3uTb; 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="LtYtIIDi"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="HXpk3uTb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620022; 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=MrvzrHYJp3qtzaZog5kuCX8qehdfFd6F9etMXff3gHQ=; b=LtYtIIDib7iHZUhkzRwiep8gStQBfSm5oC5DU1iL0XgfEFe5B5VIZbVREkpTElgDG0QJNn Qpbu+vNfXfoTC9VOfWkdldgilViM9uSVJ116bKewh2+x6ggC+ibWRrUI95Wa/PKNpQEglK vy2/o9dHfbMlUBHOihuw6kCnRGTXZlA= 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-235-ZeoJ5R3HMuqws3VgJBEsQw-1; Tue, 12 May 2026 17:07:01 -0400 X-MC-Unique: ZeoJ5R3HMuqws3VgJBEsQw-1 X-Mimecast-MFC-AGG-ID: ZeoJ5R3HMuqws3VgJBEsQw_1778620020 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-44d9ace59efso3950392f8f.1 for ; Tue, 12 May 2026 14:07:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620020; x=1779224820; 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=MrvzrHYJp3qtzaZog5kuCX8qehdfFd6F9etMXff3gHQ=; b=HXpk3uTbcH5piHJgiQFw4NDC7LZcqlobEp7S6UJSe7uQwEvMznQPT+cpw56vO28swX Ut4gXoSSZ+g7ZmEE9ciUiBSpUrrwxndXiYha5uwZUoIfyzzB9RuZ6s2rQcxbO4cfVJbC yWw3WSkKmjcMcyRnUnhj9ItYxzYY5m+j/AVI4k2HnYMf47XISXO6ZAeXoG5xsuTD/a2Q rlWH2qgJH2QPPPXpAVFwE4WvbrzVlOdoMxG7DNHqVSEa/gkub53sk5sLdzDPSeaLKuBf 64JhZlwNr7BH2EpOQ1EXbVUAVPeR1gZxboPaPuGIfSWzaBl3VUdsd56K8mReOEznBWT6 YK6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620020; x=1779224820; 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=MrvzrHYJp3qtzaZog5kuCX8qehdfFd6F9etMXff3gHQ=; b=TzNo45EHoiYUHAuP1ie2INajPKrpnmJC0DLJ4MNEk0hgnL+/UP3sNwgREAOpTKAR1X zePMzpas2Ak9QHrx3ToXcgcGoUlqotBJPHCCto6ayQCFjmH9oqMmdxZ5F4DcE9ekfQPA NQciPmils2KbzLXQkMn7nJhGoZjfagMSazgMM8Myp7WbmROcq9PVN5b4PR+WaDgYV6Hc T/XKG4d71ctZ/b6HD5dradqx2W+JTwxgXT4cM9azIGipdyOX5sZ9+qYzNrEYcfm6DOFb wBCbryV8xzy8SyRERpRrvxT/lpXoEG33zs9q9rjbb6xeazohUrI3CYiaUEYlhRf0Mwm4 5uxQ== X-Gm-Message-State: AOJu0YzlV42bJpNI4bGt+RdAQ77TLTp704ySnUZhaJBnyb99V3zdIOjW DIH1Mq0HpDd4zMDMJ3u0WnxNygnGgOm8h2Ij9L/ZL/S9ItfeNGyv8+qsX+tgZDWXXuG021VbHE7 N4k+CzLcsOy45evg97ROdNCDdPl+jAB24GaczsvPJkriBsf9QHPsxuIcNngR4l/VbCiP9ES+53P f5PiUk6y5sAL72uufvkht7Z0uRaiiP/QK95bEumGgIlm4= X-Gm-Gg: Acq92OEELsa/JekETY//tiLCSgZ75dB5ouLHJo4s/2KeObqJm6tV/w4wRT6zaKf3pVj /2DKrAqWHf2YgxC0k2jDnCaZltb+tmQtc5qKxSQFxix2vWch457a1S3H9jv6KfUW+71HAH7JIxb Ka+jvZF/oNDEkiU+X8MDdNtvfgTSEOVIOf11CFqYrfNBNZyqdpHJjaltmpb3JlIbLfB/I8PAGZS PmSRAnjB8q4Q70RzxA0DzREcfSaMyE9k/dREooUoo6fC0pd0MoS4nd7GhvZpsuL3fx2ATU2hV2j Gn7s7bBz+28xdTTtloeiWgymRt4tBTVGv4B560OnX8a4gYeUPn6oKpP6ZuvC+MjDnP5hcvbRjHZ TMaeXfhA201CP9Jsxf/9XKZg8X9jir8He01wfYZi6 X-Received: by 2002:a05:6000:2081:b0:454:86d:b4d2 with SMTP id ffacd0b85a97d-45c57536c87mr530504f8f.8.1778620019599; Tue, 12 May 2026 14:06:59 -0700 (PDT) X-Received: by 2002:a05:6000:2081:b0:454:86d:b4d2 with SMTP id ffacd0b85a97d-45c57536c87mr530415f8f.8.1778620018807; Tue, 12 May 2026 14:06:58 -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 ffacd0b85a97d-454916df968sm36702334f8f.25.2026.05.12.14.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:06:58 -0700 (PDT) Date: Tue, 12 May 2026 17:06:53 -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 v7 20/31] mm: page_reporting: add per-page zeroed bitmap for host feedback Message-ID: <929bcbf8d4bdd51c038ec302e2db26d82d942ba9.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The host may skip zeroing some reported pages (e.g., due to alignment constraints or bounce buffer fallback in QEMU). Currently, when host_zeroes_pages is set, all reported pages are unconditionally marked PG_zeroed - even ones the host did not actually zero. Add a zeroed_bitmap to page_reporting_dev_info that the report() callback can use to indicate which pages were actually zeroed. The driver's report() callback is responsible for managing the bitmap: zeroing it before sending pages to the host, then setting bits for pages the host actually zeroed. page_reporting_drain() checks the bitmap per-page in addition to the global host_zeroes_pages flag. No driver sets host_zeroes_pages yet, so the static key is off and the bitmap is never read. Behavior is unchanged. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- include/linux/page_reporting.h | 7 +++++++ mm/page_reporting.c | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/linux/page_reporting.h b/include/linux/page_reporting.h index c331c6b36687..e2e6a487ddab 100644 --- a/include/linux/page_reporting.h +++ b/include/linux/page_reporting.h @@ -17,6 +17,13 @@ struct page_reporting_dev_info { /* If true, host zeros reported pages on reclaim */ bool host_zeroes_pages; =20 + /* + * Per-page zeroed status, indexed by scatterlist position. + * The driver's report() callback must clear the bitmap, + * then set bits for pages that were actually zeroed. + */ + DECLARE_BITMAP(zeroed_bitmap, PAGE_REPORTING_CAPACITY); + /* work struct for processing reports */ struct delayed_work work; =20 diff --git a/mm/page_reporting.c b/mm/page_reporting.c index 37e4fce9eb38..6c957a9daeef 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -108,6 +108,7 @@ page_reporting_drain(struct page_reporting_dev_info *pr= dev, struct scatterlist *sgl, unsigned int nents, bool reported) { struct scatterlist *sg =3D sgl; + unsigned int i =3D 0; =20 /* * Drain the now reported pages back into their respective @@ -122,7 +123,7 @@ page_reporting_drain(struct page_reporting_dev_info *pr= dev, =20 /* If the pages were not reported due to error skip flagging */ if (!reported) - continue; + goto next; =20 /* * If page was not commingled with another page we can @@ -133,9 +134,12 @@ page_reporting_drain(struct page_reporting_dev_info *p= rdev, */ if (PageBuddy(page) && buddy_order(page) =3D=3D order) { __SetPageReported(page); - if (page_reporting_host_zeroes_pages()) + if (page_reporting_host_zeroes_pages() && + test_bit(i, prdev->zeroed_bitmap)) __SetPageZeroed(page); } +next: + i++; } while ((sg =3D sg_next(sg))); =20 /* reinitialize scatterlist now that it is empty */ --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 65C6E3CB910 for ; Tue, 12 May 2026 21:07:09 +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=1778620030; cv=none; b=agZyra31Slif3tQp5gHWOWLAO7sWZ6tmwRsfuRJF/bfT4ZHdSOxZsvDJA3fDZO9GNfs9kZAGMOLyCk6EZIWhIERu1Lsk7mmz0lI5dXEAQf3607XcoDp8mgzywqRuMXbDhUtjVQBOCFo+r24MpS20ajXxzV0mRsae/LAqKIaxaHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620030; c=relaxed/simple; bh=qkFNOprhooUNjKQ1PSjbgi8DkKCpI8tpPK659v+JSEw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eNgccZD44l08NTg+8IQQr4b/lUZTRrg6jW7rOMSDG50QcGXqdpjPFc/2MCnPNnaUiYFoEQcyamzcw2fOl2YQYgLEXgvU0mrXot+TIwpNQ7AzAkuCAAkFtk80n2n1XHjY/FfVoyT5Hjqyh4fs6c3t9taWF82UlBkYBvlS+HfA/pA= 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=aZ+Eg4Tw; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Zknx/kHL; 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="aZ+Eg4Tw"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Zknx/kHL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620028; 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=nFn1v/uAu4PP6s5g6sRwXKMfyXh1YJ87r2wzrnOTcOk=; b=aZ+Eg4TwJ/pME31dLRK1LGV3bldQHgLDA7rlwthNu7jFNJ4ItjO+PH82TzOt5WD2hsccCH ze8/gnJMZALD7HtDRFECAoGoKvjSs13zkJX4IBdtlhpzxRIkTaubSPhk9kREqzErM+usiL uudelBK5BT9ZaVnPCdAp5yBpNM4kR24= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-634-SVXZCzvMNsacwozJFbkKvQ-1; Tue, 12 May 2026 17:07:07 -0400 X-MC-Unique: SVXZCzvMNsacwozJFbkKvQ-1 X-Mimecast-MFC-AGG-ID: SVXZCzvMNsacwozJFbkKvQ_1778620026 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-488d8deb75fso46034285e9.3 for ; Tue, 12 May 2026 14:07:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620026; x=1779224826; 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=nFn1v/uAu4PP6s5g6sRwXKMfyXh1YJ87r2wzrnOTcOk=; b=Zknx/kHLvWTgPHhp/GGWdtdnQvrIy5r9SAn/StpJiJ29CBcGdmjKDOGWrknVTZkomI uCtf1rq25Cm3suMObbBHwaZq9ccEeQH5aw6FbQsiALezbWSd/GC5L/Phocjf11DZF0Yk Hhu4cuNDwxLVX4b0sNJZmTHP7tKH8fNtR9/6XULMhic3zioNjAKBdCRf6NsZqd6wpqsQ blG9Hnla3w/u8juvBr/lzXeA8/QcCPnMQESY3vRSGT7tItbMEtIxy08gP1Xvsebp1dHO 9KrM2A94N5V1k7iJJtnYlliUWz2ZqzjPDRQxzLbARHPGNcM98ksw/A9EzDA5TnLensuO B/xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620026; x=1779224826; 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=nFn1v/uAu4PP6s5g6sRwXKMfyXh1YJ87r2wzrnOTcOk=; b=FvMpFRKEDoVBxwvSPOkWfQUEw34Weul9WYSPXQbithyMG6a4kop7LJa+iiAJHwKwWe nzIsmym1bHvITIIuqdwMfzRmofrWLTQAmH8QANb2Rey+VXSvuw6DD3ObJSJ3SkZGZesG JhoIztSeDmuX4CjHHDtNnVdKIPXz9t1YqLeB0f+9wpnv2eEZPRZuC76P9iNKSrSKO2b6 R7QRGIIc+dmlWgNepxMZ1567rvzx/g6MWf1oAzMLXpwpupj8xj5B9MjvPMGxh1yfgSp0 mK8JNqlxoEjaFMuy3Ez3YkCNmuUnKyGsIyC5BZQL/7jLZoaMBZoKFsG/TrPuv+D3vuLm VaTA== X-Gm-Message-State: AOJu0Yy65XR71/WXc3kKeGpy2EJ/jEI74S5zRt3ANHg0Omf4aB3z2OXw 3+KzzVA9FCumIrY/SvflkZxPO1hki+7LNQx7n+ExpOy/XAGWCOjdkncQge1ltD6y763y9T6mMnc w+dWfzjLZYbLrxQYtR/RAagK8QJnu5zqUrsNy+3ACi6LI6UDk2CXjb7Uc1pTcdT6Agr/xry3WML IM+rDii1M/bkz8WSc3wLzpw8erA4dXwdDOQl9ES+KYbBs= X-Gm-Gg: Acq92OHpd+J+srV1C0RpnRfvjm6dck1GhY5EIgvhqRLg8r8qS0lCnx7VFJceQM/+pil fryy1CFU+vgCeJ30qNzMs6fWTDJVflDh0KcPzrruyiquDHE/IW+lTyra7P0ieRw5/tAPWOi8inR hbvsDmfwBUZP5Fc9CjNAncqP1mxRTfyx0OwigavyzAWO7lDPxVhYk3uSI/w7uRQ9AiQSJ3PbKkF EzTbEdQ/HI5m5Xey7b7VOSEHaZ2+dHtVZh9DT2Ti+WfzKaOO6aF2tZvRUaDViHox0t4z5AWgVOa HsU7asvJ4EWwuUDoLUOmT4HOohVuYm6EcT3J1x20bFxJZ6Ktr9jy5dMiZnED8oVHhxOjFH36uRh +G6zQhpeoGy7B4K55Lx0Fy0DeIbJyOo/EnCOLDEA9 X-Received: by 2002:a05:600c:3b20:b0:487:2439:b7c8 with SMTP id 5b1f17b1804b1-48fc9a029d4mr6486475e9.1.1778620025581; Tue, 12 May 2026 14:07:05 -0700 (PDT) X-Received: by 2002:a05:600c:3b20:b0:487:2439:b7c8 with SMTP id 5b1f17b1804b1-48fc9a029d4mr6485625e9.1.1778620024852; Tue, 12 May 2026 14:07:04 -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-48e8f42a845sm24872145e9.20.2026.05.12.14.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:03 -0700 (PDT) Date: Tue, 12 May 2026 17:06:59 -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 v7 21/31] 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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D 0; unsigned long combined_pfn; struct page *buddy; + bool buddy_zeroed; + bool page_zeroed; bool to_tail; =20 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); =20 VM_BUG_ON(migratetype =3D=3D -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; } =20 + buddy_zeroed =3D 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); } =20 + page_zeroed =3D PageZeroed(page); + __ClearPageZeroed(page); + __ClearPageZeroed(buddy); + combined_pfn =3D buddy_pfn & pfn; page =3D page + (combined_pfn - pfn); pfn =3D combined_pfn; order++; + + if (page_zeroed && buddy_zeroed) + __SetPageZeroed(page); } =20 done_merging: --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 CE8933CAA3B for ; Tue, 12 May 2026 21:07:13 +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=1778620035; cv=none; b=fvQLLJAJt+mu+NCWFZLvlM0gNZZrHsMlAeQgvMKmA8e8aSgw7fqrJZOpbNvFzWMsPokLUe/imiZf2g+4xArCDOx5pDhxLFJc+HFcc27n27g9bAd+2V5/JQ2eAjWa8HxoB7ncWb7xyeG6epLdsJQNUnAA5H1W0kmqdiZ3bkm1rvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620035; c=relaxed/simple; bh=Noe25cYGU37yEnBN/uCs4h0K5JHYLW0DyCxvIEDnqFg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=joBk9tZVYIiNajf1tFaKfZyPqn5C37Hkqve9a4NYg7eKoONA/7J7HUZAADQ3uL7DmzqXsUzwYA35ZC6I4I+EdWY98eVt/JWhiEMELcfBadv+RJS5ZbXVQFVHy3rmbCkxXwV7mCkzt8BsBE9AmViQc1x6kCI6vdIxRLLO/JCPQfc= 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=X+EGiJ7W; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=kyxfOFCN; 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="X+EGiJ7W"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="kyxfOFCN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620033; 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=KozvVjbx/oxts5t0d1Kf0c1bCJ+8LaI82XbCSjPbc9g=; b=X+EGiJ7WTExI5/+oORAb3hnWDgNevVCzUpVAhXtSPr5ibhjIobNxEa0Mdx+16SWSuEoI4s pbbyMuy8uyXmgOLvsOc5uipGyks1h7LFNAy/E/LTjflHe4UtmyZlTXDDYXpQyfQDEokwb5 fWAK1jCdAs0g3/D61Xtpgn+dMk/8nK4= 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-693-pyADZfETOeSP9FVtuB6AnA-1; Tue, 12 May 2026 17:07:12 -0400 X-MC-Unique: pyADZfETOeSP9FVtuB6AnA-1 X-Mimecast-MFC-AGG-ID: pyADZfETOeSP9FVtuB6AnA_1778620031 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4497a0e3acaso5488136f8f.0 for ; Tue, 12 May 2026 14:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620030; x=1779224830; 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=KozvVjbx/oxts5t0d1Kf0c1bCJ+8LaI82XbCSjPbc9g=; b=kyxfOFCNCyP7j2jPjx1G7ZEe98i5I2o7m1lcmuLnD4vhz8LwhlpuooZNENNC2jgwI6 bMxW+DT6molGLXjbvEFIgpqLHi9wrQNrPCfaA8NiVtx986fb8fQkuE413q7bfYYxh8z2 Lb+lBz+9AAcm9OJWfS7iMSjXPivZWhQeCJDQdXrsXehqSzYlH8tXwjIsD96YhRHvkRZ2 BJmLNp1WLI3T0ggs+uHljG1i8+a0XzUtTKdzLyjWYpypxJbNCNNwaR9w78yED/tySjWb hF/e5oFbjLn7WIzVsvyGRoZ1puMHzbw7gDJs1ivUYjq3P3C8G72nc99IEZHEyOB6IFVy /48w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620030; x=1779224830; 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=KozvVjbx/oxts5t0d1Kf0c1bCJ+8LaI82XbCSjPbc9g=; b=JnuDQY2FtnYihPjQf4Fe+atXijPeHAUCpC3dTqGpDkaofxSfvGZyvAZdSs42/NF/ZA E/kfQkpxFH9duJvlAbangWtRk7e3en2XNg5jkhe2p5AoLvJ/tCrEqiU8b0Fyv1JqXTiI 7PfBplUfvToxIC4z+BDWhPWiKUzBH1ROdrPBbaV54JI3i6XJvQy3/gdDkpncJtxxjill LHrHZIs0E+XClKpSDN9NKREy3Tl8HaxEt4wK/XrHiUw4OxKHPiFf1cqlMzIr/2SNocFA EyMhLdKmq5n+OkyDzlkfrN5/ydq7aaLQmrtwVjObAph6RqgP9vbDmEoSPkJ1l4Z8pdZW zrUQ== X-Gm-Message-State: AOJu0YzqoWyf6qaSR0PRhZGltKpgHBkoHVRIYWlGQQQhuQAoeO/Gn52v AfAGaO5d0aDkrW9yawAxV7qjTcqgLRGd2z8PwTiGbjVdDnlw+6vDS19y5k2TazDUP8LvbI+U23f VpisNoiTNJTl6GQNkMl6QgzQwWYKDuEnwv4qLpDq0LzPSSxgaxRLOADeCaHac/nZkb3DFvNQFNL 0vN84TOeqeMWvWFEd4ftkbCFvugWlWM0lUD2MNBQOKni4= X-Gm-Gg: Acq92OE+s9oijoC4Zwzt6yo0vIEWBlrmIb2hAHLddsOc5D89jaDupvGaborCS9LOBFV 4UJSfnp/v5eo4vwyFAw+9Au5He6u5ghegtE5hhfoSK6t3NEay7QCMabMcN3fCCrKQC1SlcoRCms Be2Vh3plo1aja9EueSoFLanMRew8unSikx0nTsTSmsgjCVWClkjyqjYXyG7X8W21hiKByv1COzP 7vHBQ4faehtgaxkkpsrHyaGTvC+m7993YRzFxLMwvpONvQVlTP43GkWbd61eSHHlDrP5fSflwvD +cborJAHO2frgUiaenvDR+0TOkc9PW18YCYqdApybERBcXyzUKRrFcHp2Iu4WrVlmHjatBpYLNJ vq9DOfE1p/gaWPVwIundZkGK7fFpNCl6zmSCUrOfa X-Received: by 2002:a05:6000:4021:b0:43d:77e1:6a69 with SMTP id ffacd0b85a97d-45c5a6894fbmr498522f8f.38.1778620030479; Tue, 12 May 2026 14:07:10 -0700 (PDT) X-Received: by 2002:a05:6000:4021:b0:43d:77e1:6a69 with SMTP id ffacd0b85a97d-45c5a6894fbmr498437f8f.38.1778620029903; Tue, 12 May 2026 14:07:09 -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 ffacd0b85a97d-45491f8d4c3sm34970009f8f.34.2026.05.12.14.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:09 -0700 (PDT) Date: Tue, 12 May 2026 17:07:05 -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 v7 22/31] mm: page_alloc: preserve PG_zeroed in page_del_and_expand Message-ID: <9a22e0f9bbe1278913754db6df76e291a006181a.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Propagate PG_zeroed through buddy splits in page_del_and_expand() and try_to_claim_block(). When a zeroed high-order page is split to satisfy a smaller allocation, the sub-pages placed back on the free lists keep PG_zeroed. 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 --- mm/page_alloc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d70c9ba6b329..468e8bde7d34 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1712,7 +1712,8 @@ struct page *__pageblock_pfn_to_page(unsigned long st= art_pfn, * -- nyc */ static inline unsigned int expand(struct zone *zone, struct page *page, in= t low, - int high, int migratetype, bool reported) + int high, int migratetype, bool reported, + bool zeroed) { unsigned int size =3D 1 << high; unsigned int nr_added =3D 0; @@ -1743,6 +1744,8 @@ static inline unsigned int expand(struct zone *zone, = struct page *page, int low, */ if (reported) __SetPageReported(&page[size]); + if (zeroed) + __SetPageZeroed(&page[size]); } =20 return nr_added; @@ -1754,10 +1757,12 @@ static __always_inline void page_del_and_expand(str= uct zone *zone, { int nr_pages =3D 1 << high; bool was_reported =3D page_reported(page); + bool was_zeroed =3D PageZeroed(page); =20 __del_page_from_free_list(page, zone, high, migratetype); =20 - nr_pages -=3D expand(zone, page, low, high, migratetype, was_reported); + nr_pages -=3D expand(zone, page, low, high, migratetype, was_reported, + was_zeroed); account_freepages(zone, -nr_pages, migratetype); } =20 @@ -2335,11 +2340,12 @@ try_to_claim_block(struct zone *zone, struct page *= page, if (current_order >=3D pageblock_order) { unsigned int nr_added; bool was_reported =3D page_reported(page); + bool was_zeroed =3D PageZeroed(page); =20 del_page_from_free_list(page, zone, current_order, block_type); change_pageblock_range(page, current_order, start_type); nr_added =3D expand(zone, page, order, current_order, start_type, - was_reported); + was_reported, was_zeroed); account_freepages(zone, nr_added, start_type); return page; } --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 A16F63C0A18 for ; Tue, 12 May 2026 21:07:20 +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=1778620042; cv=none; b=LN2bhI8RK8DDSZdWZ3EJNjLaphMjnZZanHHPc3Z8ruaE8593VtKuo0tLFhxSUq70WGwItdXlJnsZ9gy1gYNzWSzExE5zpTqpAfIiJqzxPpM4wIbfAQu/nKlU/kvkAoZLBfGoBjt5sc6/mys7XIrN9dhfbSm0ON/EUk7Z2kiYp3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620042; c=relaxed/simple; bh=7NdesRjgSv1b1kpIKOcJU3ghhlgl5tyDeUkJhLpnmYA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BOIHPOceZ8ypcLJlfmwGdeZOYNpf4XB/ZAfi6H5HtfpNWoBcAJ+MDrZOXxWu/G1wIw+JoreDzJQjT8LmB65EEhl877CZqB0BwA70tXMwnyL17k963SG/DTOqwUcH6Ls5XcjrLSwpUt72+6MFBcQKtDQAgkGwdVqgyRJa/xoBhDY= 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=Lu9fGC3G; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=IWNr1JTH; 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="Lu9fGC3G"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="IWNr1JTH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620039; 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=IXi+uVqRnkqRNPO9A5xD9TyHb3ak5Pg5n5rhgIRfmL4=; b=Lu9fGC3GDbj0+5WvYBp5LjwNgF1nTgWXKkprAICXDe7cWLnqvwd4etRv3x/PZdKVnapw7G 8/qIOkqmwQbGlPGr1o5IwqB2VONl9Rrah+Oqq1oBS8zrndi9/DJ0ZLxAafg4vvSZ2YZYik p881m12DVIeXyrpbbl8tz/D2z613/+A= 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-104-1G3OOE-FPeKfjCoNtPkmIQ-1; Tue, 12 May 2026 17:07:17 -0400 X-MC-Unique: 1G3OOE-FPeKfjCoNtPkmIQ-1 X-Mimecast-MFC-AGG-ID: 1G3OOE-FPeKfjCoNtPkmIQ_1778620036 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-447f2ce5556so3916939f8f.2 for ; Tue, 12 May 2026 14:07:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620036; x=1779224836; 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=IXi+uVqRnkqRNPO9A5xD9TyHb3ak5Pg5n5rhgIRfmL4=; b=IWNr1JTHMdaiH5kN2pZC9g0F+ek66MZ2H7/upfznIaUrSOUF6iQdZFURGbPS6FbZOk XAPjvPhjnOgwIoh6/oqVf9TunAbmif/3ibYTkwGV9oun+xF02kKfPBx9KLKdQhojBPAK U62pxUAqOYSPTrH0MsBON5qM4I4l5YXB4aqZO4eLrS1vSsBaEFZbsmi9jOXS1uUB79Tr 1aNlYa/BxQJQpGCaZvyZ3qQtNSOB6OeqVcjsWPyOusYKwoYkO4UI+jJkmDZKV0LXx+Kn z/ONj4FMmTRQh0t4u7v6zvbNV5+PXJyMRwnSTyf+P1ig36HejukfaweDPxAvXPlq9p3z BSPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620036; x=1779224836; 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=IXi+uVqRnkqRNPO9A5xD9TyHb3ak5Pg5n5rhgIRfmL4=; b=Hoh8Y13Lq2AtA4TIJpkVBytUvslw/AUJK9IQ3zk4aPGG1eYbFoQV9Qtsy/yi3iB2wy wc5YAC896REsR/0pJfiIUBJDtPVXNU1yHpItBf6uX03yE+AVEWLGn4TetZ5SelcbE/l0 xyieyu9h8ajboBiitGwtJAC+bBj9I/npe2mIXHoU5vISF5Os7dQxM6UvLeDJspkRF20j sXpgi7kTnP8nM6Y1kOHS+QjNa/3B+yGlj0QgI3chGvaPVSfaWjrq8TKEO8XhKddjnsM3 osjRW3VCq+Int2/XMTSpRMAXoYEKLfr7FVMqMtCRX+lzZyPjqD0lc7UABoIDV10iKPXF POpA== X-Gm-Message-State: AOJu0YyYxPiviL8rRTLqOiZa1+jEslwHUE750ofb5oWCdwIcgFI9VRA0 cq1SdgZ3Vv8dOSh5MktmrdVkPxMYkLZZxdN2b0l+0f3xcBFXWoxtLlw+t1CaHpwyOSv7XnlcPlK wwKWaTzj9L5wylMYkdxlPhRId2DlOZx+0YsLUBYuSOnegu2y6XDGqphcY2FqliJqUhxyq1TGrdz HWhJlBUkvwe4MJcdoP8inXRHypTc7UmB/zMKpQbRE5nqs= X-Gm-Gg: Acq92OEpAKsSAeLkY94F7QqpKB9mFHY6F/RUWmsCq32T+EVfxXG7UeBYiOLxDAxByly NtsQFmoGnUFr3UdOnRALbYj7nSStXBzW1Vkm96T6Sb4s7XcsfGUjjetVO3w8OOAUQ5+jc7ASDbD F8Gqvs6jtB9CHaQxdrI3pAhtJAmzdbFb3ZmpPl9mPibbAggQXpmaHv/oLKuOjEfcJUAyVQS2wRS YWjZ2utWZ7CkOfMLQBmC8j3FQu7mXFudvyxnishjdaT8/S1QVNnPEGw7O2ZGLEv9ioQGimGMm4P i1I21EEqfSwIqBtnt8VkwKTOycKcxMKdCV3967KhvD+IvwO3UfKWP3E2m3WSdDnOjbs7eJkjKR8 Zl2d6QegARh1TcGoSOAOTDqRokI4qwp6FDOnfK0hs X-Received: by 2002:a05:6000:40da:b0:44f:d9f8:c0e7 with SMTP id ffacd0b85a97d-45c77e635bfmr41918f8f.5.1778620035766; Tue, 12 May 2026 14:07:15 -0700 (PDT) X-Received: by 2002:a05:6000:40da:b0:44f:d9f8:c0e7 with SMTP id ffacd0b85a97d-45c77e635bfmr41834f8f.5.1778620035141; Tue, 12 May 2026 14:07:15 -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 ffacd0b85a97d-458b3664e3esm19560446f8f.3.2026.05.12.14.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:14 -0700 (PDT) Date: Tue, 12 May 2026 17:07:10 -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 v7 23/31] virtio_balloon: submit reported pages as individual buffers Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Submit each reported page as a separate virtqueue buffer instead of one buffer with an sg list of all pages. This avoids indirect descriptor allocation (kmalloc in the reporting path) and gives per-page used length feedback from the device. On error, the already-queued pages are kicked and drained before the error is returned. The caller (page_reporting_drain) then marks the batch as unreported, which is conservative but correct. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- drivers/virtio/virtio_balloon.c | 36 +++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index 6a1a610c2cb1..fc43d0d7bbbc 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -202,25 +202,35 @@ static int virtballoon_free_page_report(struct page_r= eporting_dev_info *pr_dev_i struct virtio_balloon *vb =3D container_of(pr_dev_info, struct virtio_balloon, pr_dev_info); struct virtqueue *vq =3D vb->reporting_vq; - unsigned int unused, err; + unsigned int i, err =3D 0; =20 /* We should always be able to add these buffers to an empty queue. */ - err =3D virtqueue_add_inbuf(vq, sg, nents, vb, GFP_NOWAIT); + for (i =3D 0; i < nents; i++) { + struct scatterlist one; =20 - /* - * In the extremely unlikely case that something has occurred and we - * are able to trigger an error we will simply display a warning - * and exit without actually processing the pages. - */ - if (WARN_ON_ONCE(err)) - return err; + sg_init_table(&one, 1); + sg_set_page(&one, sg_page(&sg[i]), sg[i].length, + sg[i].offset); + err =3D virtqueue_add_inbuf(vq, &one, 1, &sg[i], GFP_NOWAIT); + if (WARN_ON_ONCE(err)) { + nents =3D i; + break; + } + } =20 - virtqueue_kick(vq); + if (nents) { + virtqueue_kick(vq); =20 - /* When host has read buffer, this completes via balloon_ack */ - wait_event(vb->acked, virtqueue_get_buf(vq, &unused)); + /* When host has read buffer, this completes via balloon_ack */ + for (i =3D 0; i < nents; i++) { + unsigned int unused; =20 - return 0; + wait_event(vb->acked, + virtqueue_get_buf(vq, &unused)); + } + } + + return err; } =20 static void set_page_pfns(struct virtio_balloon *vb, --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 46FC03C76AC for ; Tue, 12 May 2026 21:07:26 +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=1778620047; cv=none; b=sJbVDzINubMVmZ7WNSzDUwoZmv+RqaGSjj/2GrRpEJecMQETQLQ4OuaF0HRH7N+ZOmIbIsOH1omDL3G+ctTqj9DHxNa8cndu5OXMhV7Eqs41DuPeHdE4KCqhvjx/CO8JNH8wNglQP4dssM7PxSrNdy7PFboDl6Dn4Z2Q1r1DUqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620047; c=relaxed/simple; bh=gA+GhqYvwNlglcAAc+7safd3uN5pLfpD+OD4nI/Ceeg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=r+taUazwQrB0LKYQrm+kC4dokXqCSDQgkL09t7wtsqEaz419mE4El4UFy7M8oczSxOennAKAuUfJ6M7E/mrZBq8z+GsFFFW13NdbKLZXlNhY280Y5BpzTsLGj75Y/O6Po+yI3DcCyYeTwQt9T+sLJmRZ9gqjaKzDtB1qb/2iPsI= 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=d/XcsfQn; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=fZYGZnBs; 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="d/XcsfQn"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="fZYGZnBs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620045; 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=RuTcBXOBEgIcnIT/SeHSDJKAZ2vX9yg2mawsRplntmg=; b=d/XcsfQn0hWhqNo2+FbUMhHplDQwwyJQ/GvoyYLzrvSOq+xVEZfAZ0bmVDxJc6NcpTJFiQ OfoTO87lZ+cUsBJo69kbwjOrfvN86Zp62hi4YOM5bEpyF3dS4m+KTB6AB/QzPe1YXEG42U 1bSiFaXilb1Wa2IcOCO3nGurcuRwJrQ= 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-356-WX2FDgWzMmGwXP2ifSHvRw-1; Tue, 12 May 2026 17:07:22 -0400 X-MC-Unique: WX2FDgWzMmGwXP2ifSHvRw-1 X-Mimecast-MFC-AGG-ID: WX2FDgWzMmGwXP2ifSHvRw_1778620041 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-48d0677b5f7so34066155e9.1 for ; Tue, 12 May 2026 14:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620041; x=1779224841; 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=RuTcBXOBEgIcnIT/SeHSDJKAZ2vX9yg2mawsRplntmg=; b=fZYGZnBsezaNB924X/Kxou7kP+pK/jxlJUqjsvOeiEDxPYm2yM1hrBTbhEB00G3T5j qpkJNnrk0yGTD9OHgLCTi2ey//+SowasbLeOhTV3sJiEAkDMwsaiIdEV3DINZgyTdiW+ cs6VG2IrKvBHilF42/EZ4Hx6kkZp91URFkxi9CDeKlz2WLklr0lW2+uzgvGnsdncDevI xHNy8bjpOnPe98/aY1yWI8qmn65isQrBXVspxbUDC3WOQ+HzB2aSRRBK04kbrbifSNUo 5qlCZ92q/oq7XUMrHeZ2/otrCtJZqvUx+s8AipbqQaHD+2TYomz9ofIlqY2SAzP2Y0HC 3RPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620041; x=1779224841; 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=RuTcBXOBEgIcnIT/SeHSDJKAZ2vX9yg2mawsRplntmg=; b=en+Ma8uO++VH6ItIZTaxfhcUr92/SEZqrxh8dfsx+XBiWYnDqRj+TlzlgWv0XCOnTR nwtRiNI1PA+Gp6itYjB0+ZSw4Gf2uMWZ1c0vl51gk7lBj6gEfQAi5Nj9fub8SgkTM7yW J0vJeLNve6RcwA58cOqsR1hdBhBdNnhrTnDkpgrGCkS1RZaYKyP2MQltq+4yMf1+ayeW xo//f+hkueDe5GD+8sd69FDVHs2WirJkcleDtiJ3//zVPjJA/KYT1P2UmnRUgIYz9Qyb isL/VAm9NSRkF6ksSjdrgEMfvsXqrIIhr21PtLiT+yG8zyPnMI9D91KvPx9FvH8khkTi PD+g== X-Gm-Message-State: AOJu0YxJl3OHoDeCKbHZKLsh0t9xX3EYRKbxydbyTqEjynEuPNR813uA qTsrMKIfggoZQx0mVuB89WYUJB6/yY69s8Xk++GseW3ZacX48UNed/IIRa72UdQlQJr44U+QYgg wMBmF3d5f4y23hubT85R/feOVbQBLFN3XAdmV7foQU4dNjbxQdupuNSGnUXCMtwtA82n/qtv7SR wTSZYavaI5133WJx5WYG3sRdFDa+ze2lEe9eKEhddN5Sg= X-Gm-Gg: Acq92OH02ThCXsB7U+TS6CFXeVV7eDSK2AD0Vr9Gcd59Zl6lsFnvtm0fCHiUcI1tCkE qUyo13amdckmDpyBnB9SOKH+Uss6fmsLtEjEjzVQD5AwLW2MWqWsFNJ2NIxCv3H5Lw69i2Nj8tm ADV7az4uu0aDYbmg2Xo/IjjX3PCdC94b4j0jzQioumtDtZvIoAfkdg4AEPyQSdNfu1DD/qdpDWZ irUSmhvxaM1ELQpi0oCTNKpexkRILVTzoJ8OEu8bUSY0NGmOS8+R7gWYVyDYnEQb58tmq0PLZaR Cq0J/OvGAKOkPrwquTdaICi1nm6rQBlBjllnbGSy/tOPIQA9Z1p42DdeApTeK7GPLFQNpUqWvo5 q3n16rFVD9rNwVDD3duDpnPGq5lDG4UjGL9jca0DS X-Received: by 2002:a05:600c:a011:b0:48a:563c:c8c0 with SMTP id 5b1f17b1804b1-48fc9a0e65emr6519645e9.7.1778620041081; Tue, 12 May 2026 14:07:21 -0700 (PDT) X-Received: by 2002:a05:600c:a011:b0:48a:563c:c8c0 with SMTP id 5b1f17b1804b1-48fc9a0e65emr6518995e9.7.1778620040393; Tue, 12 May 2026 14:07:20 -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 ffacd0b85a97d-4548ec6be40sm36486377f8f.12.2026.05.12.14.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:19 -0700 (PDT) Date: Tue, 12 May 2026 17:07:15 -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 v7 24/31] mm: page_reporting: add flush parameter with page budget Message-ID: <7970645404129ef31ca7035c7d6b5ff960bf14bb.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a write-only module parameter 'flush' that triggers immediate page reporting. The value specifies a page budget: at least this many pages (at page_reporting_order) will be reported, or all unreported pages if fewer remain. The actual number reported may exceed the budget since each reporting pass processes a full cycle across all zones. This is helpful when there is a lot of memory freed quickly, and a single cycle may not process all free pages due to internal budget limits. echo 512 > /sys/module/page_reporting/parameters/flush Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- mm/page_reporting.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/mm/page_reporting.c b/mm/page_reporting.c index 6c957a9daeef..f4a0e27ac7fb 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -358,6 +358,48 @@ static void page_reporting_process(struct work_struct = *work) static DEFINE_MUTEX(page_reporting_mutex); DEFINE_STATIC_KEY_FALSE(page_reporting_enabled); =20 +static int page_reporting_flush_set(const char *val, + const struct kernel_param *kp) +{ + struct page_reporting_dev_info *prdev; + unsigned int budget; + int err; + + err =3D kstrtouint(val, 0, &budget); + if (err) + return err; + if (!budget) + return 0; + + mutex_lock(&page_reporting_mutex); + prdev =3D rcu_dereference_protected(pr_dev_info, + lockdep_is_held(&page_reporting_mutex)); + if (prdev) { + unsigned int reported; + + for (reported =3D 0; reported < budget; + reported +=3D prdev->capacity) { + flush_delayed_work(&prdev->work); + __page_reporting_request(prdev); + flush_delayed_work(&prdev->work); + if (atomic_read(&prdev->state) =3D=3D PAGE_REPORTING_IDLE) + break; + if (signal_pending(current)) + break; + } + } + mutex_unlock(&page_reporting_mutex); + return 0; +} + +static const struct kernel_param_ops flush_ops =3D { + .set =3D page_reporting_flush_set, + .get =3D param_get_uint, +}; +static unsigned int page_reporting_flush; +module_param_cb(flush, &flush_ops, &page_reporting_flush, 0200); +MODULE_PARM_DESC(flush, "Report at least N pages at page_reporting_order, = or until all reported"); + int page_reporting_register(struct page_reporting_dev_info *prdev) { int err =3D 0; --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 8A6D73CA491 for ; Tue, 12 May 2026 21:07:29 +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=1778620051; cv=none; b=MxA7DnSOUzL3Vcmo5SzAxrkXkBYsw1EED5anrhHP52YZykfE2Jsh8wCc7lgIUa7d43qeD9sej4VTz4/WhUqmrJJyPFZGqbmy5pmBuNs2acIsg1/5p5KtuqVZjjUEhOpI8HkaY7hTqZamgTDUQBK7pYKYGG199IOvA2XWEm6AJVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620051; c=relaxed/simple; bh=UthrZxmdWcO06HJ9ALdgvYEd0atl77MZdyNsS+qUmSA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dRGUfJKEcl9wiNwZKRZHVQW5mDiNoUpbDVl+bXQ7B3Hdd9TvAei0py9Nz4I7f0VSww4m/2TAgvN7PbiDIKCz0S3lHUclzcc11Kp9thzlA3mroOOtrKmU4u1MU1RdQrHA6LPs/GDKhv1Zj/MIEqHOzW4nWFbklA0x88nTd+cnbbM= 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=dTIiO68L; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=K3jKthrz; 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="dTIiO68L"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="K3jKthrz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620048; 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=91FyDo4lvxPgkiSt2vN5y4yAYQZnqJbtxElmqdOrkw4=; b=dTIiO68L9uFJr3EIx+YbJjGv3Ps9krBg7fIzG46hPi0VpuzOkyb2ZfotTQ6MsVnuJn4D5Z Xgap/2sFm/UFiSvSnyQPdpfoLOR8qB0ijcv+qOJJAULQ/30eJ6JGqdHk9Zi1EZ5CiPxEEB LABrUz072AGuB1yBP/lS/3FPrji/HUQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-I3qv6RYSNvevRKTIhMSKxQ-1; Tue, 12 May 2026 17:07:27 -0400 X-MC-Unique: I3qv6RYSNvevRKTIhMSKxQ-1 X-Mimecast-MFC-AGG-ID: I3qv6RYSNvevRKTIhMSKxQ_1778620046 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-48919890a95so41184645e9.2 for ; Tue, 12 May 2026 14:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620046; x=1779224846; 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=91FyDo4lvxPgkiSt2vN5y4yAYQZnqJbtxElmqdOrkw4=; b=K3jKthrzFsdzArRpDTWffGSqbvyw0gTYoTgXj3wLrioPDmO9DLhWfy/MqHQV64avwL svAHMfLnHlIIHLGNHUSUR8W1cSFOn1uXqXak05fSpmD3IqjOJ1p14SUuWkDE4pDAEudi cbwyPuu/T7vTOMRWr+AMh+FyxRCsPExRCshAcuk5hR+vMiBvAJck8MeSRgNKqVsZwSga F4YBoATnJOoPLuKy9qN+IbPwaYTiCtt5cBpNSzPvzg3YA18GPQT4JCjCl/D2yrLttwOS 10QCAZUmy0thN9YafQPFdtKJgLy5qfLzTXdIESstA1GZtLA2UA5aL+kjNsmkS/6J/cA2 +ILg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620046; x=1779224846; 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=91FyDo4lvxPgkiSt2vN5y4yAYQZnqJbtxElmqdOrkw4=; b=IIn/9+fNA9gTZxKIVoDslGR1J8AkX3xrUDyUAMWa0ob3bAAx/LLpJXPF9CzTM+OP54 yD8L8+f/PVTVYzCA67LkVNrOYYsT1wS/dWF+aDe2XPtyagTYTJIicywigtMkoGuTDdNq kZ3sHqRk1+SH/K+C6oPuUr8ARb4fQJFz5VsO3kxuCqzEBoNohn8RagFj4cxCBj29OPrk yIhX5MshAaJDBfT2+WF2SxmrUcgrBTNY9ax6cbkpaWNsUP/N8WcK6ALj1cNddfGwvNaR K7mNyMSyqtTwIrp0beulE8D+3ZvrXi1ybhEb6lwXOq6+2F64LTPsGvMvBy7Kcs/nvjOz p73g== X-Gm-Message-State: AOJu0YzPYHrNQMP+JRodZKqR19wlvjEwo/nHtiD0WVk1kgO8D30x6pEZ yvnpI42GAS/z/UsFDWaWikSdDpxkQ1HAZvh51Ow47wOBQxzesCXxVYq0c+QGfS/mvqry3QWk2Ai xOk1TZKPr11NX6MFs+sMLZmAExGRAO/3PtcZvHf/kYRJvnR+Zq8csZsm6S8hYxAkYxKTtDZ8s/0 UulWY9dP+eXYa6mI6evdkfc5JFXQ1fGZyF1cgVmKmKrdg= X-Gm-Gg: Acq92OE5aBFpLiRCpHfxAynF3GJGg0bsBRDFgPSqaOcjbsZWFqeSPIBix2jRhvqC3hd OmyYtYKbviQjkuDEVcJvcREmHrJXoyKTYbqh/ogUAbhLPpqPxH7iyo0KFWeBiLC/GVUjaixhGeF Bjfi9q1NesANyLVUIhFin9/uGbtv+Ak+fzKf9lfUTIYgNEkKo3a+xQy8D3rBWMIV8DdXUwUl9gv M05OEPiW52+WrxnibGwYesmBYtgHlMiaXd0h9GSW1AbqrTEol86MLxeB0jEJ+dkjpeCB4m1zEy8 KazDaUmCbH5hJfQ3rkwEmqTNSkypEEIn03IYTruQsNrjiZzlX4RjsIdll/UFKUW0x9+B8nXoCGb //PXrrY3KY7DWxSr8FVO5I8eCoXsYKKfvoqW3wUTr X-Received: by 2002:a05:600c:3b19:b0:48e:8dec:19ad with SMTP id 5b1f17b1804b1-48fc9a11b29mr6570175e9.12.1778620046175; Tue, 12 May 2026 14:07:26 -0700 (PDT) X-Received: by 2002:a05:600c:3b19:b0:48e:8dec:19ad with SMTP id 5b1f17b1804b1-48fc9a11b29mr6569415e9.12.1778620045558; Tue, 12 May 2026 14:07:25 -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 ffacd0b85a97d-4549120eb95sm34339020f8f.20.2026.05.12.14.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:25 -0700 (PDT) Date: Tue, 12 May 2026 17:07:20 -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 v7 25/31] mm: page_alloc: propagate PG_zeroed in split_large_buddy Message-ID: <2db0d124c647e711c0bf95b1c7f1316a0d1408ae.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When splitting a large buddy page, propagate the PG_zeroed flag to each sub-page before freeing it. __free_pages_prepare clears all flags (including PG_zeroed), so the flag must be re-set on each fragment after the split. This ensures that the buddy merge logic can see PG_zeroed on pages that were part of a larger zeroed block. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh Reviewed-by: Gregory Price --- mm/page_alloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 468e8bde7d34..ce43f5a3dbaa 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1523,6 +1523,7 @@ static void split_large_buddy(struct zone *zone, stru= ct page *page, unsigned long pfn, int order, fpi_t fpi) { unsigned long end =3D pfn + (1 << order); + bool zeroed =3D PageZeroed(page); =20 VM_WARN_ON_ONCE(!IS_ALIGNED(pfn, 1 << order)); /* Caller removed page from freelist, buddy info cleared! */ @@ -1534,6 +1535,8 @@ static void split_large_buddy(struct zone *zone, stru= ct page *page, do { int mt =3D get_pfnblock_migratetype(page, pfn); =20 + if (zeroed) + __SetPageZeroed(page); __free_one_page(page, pfn, zone, order, mt, fpi); pfn +=3D 1 << order; if (pfn =3D=3D end) --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 AB96A3C988E for ; Tue, 12 May 2026 21:07:36 +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=1778620058; cv=none; b=OOOiye4lP01JKgWNiwLoTac+UfEEXv7Q6j1H1CVt4G+rQ5yxcoVB8y6gjh76mV7dKc3KaaH/fDEr51QjJa5aIu+Mg5Ip3SiFsGB0pavozYeBg6iW6UzZ1SAno1Csx1fi92GXthPDHHDZmEYftQeR2YqDtj0pUYkNNnbtQZtVjH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620058; c=relaxed/simple; bh=rB0kVuhS6FNGgugvmVFgpcyoiK50boSLb3yg8KWs/3U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hni5yrkfupxzdlrkfG491PIDnKWUxLmm4Ki3W7BiYNxC4AAxfqG03KAQSWoKqOKMvzknuBR4NTGzyAM4yJZG8oqehRRBc1VCrq4y/+gkc6oj4obistzph9M8X6GZiDDIvB3Qfv0FVKoY9PSIIi6JNjbtps3FK9VvcrgL9lUiN/Q= 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=AOR9wSGb; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=hg3GFU39; 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="AOR9wSGb"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="hg3GFU39" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620055; 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=FdwmuXhJZ1tztt+MOga5Lk/KutygLpMr1MIyeSBc//s=; b=AOR9wSGbKDaKQMNV5kzoXHWCiIrDmiVlNWwoCCyQSwg5IQGiKVZQhS2LMcWCpMG6i1kUbl /zcvjgEGtZlU0KiFUoCNP1DvsEbYNzgRNobYUDQywNTlxdq0RFEe/nUtZ1nJ/vwCmqOxhw +vdCvBT2azgBONnWcP+8NAhDJ5fP2wo= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-196-NalAIJjCPnqdg8UmeqKS4g-1; Tue, 12 May 2026 17:07:34 -0400 X-MC-Unique: NalAIJjCPnqdg8UmeqKS4g-1 X-Mimecast-MFC-AGG-ID: NalAIJjCPnqdg8UmeqKS4g_1778620053 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-44cc3c9b2feso5499691f8f.1 for ; Tue, 12 May 2026 14:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620051; x=1779224851; 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=FdwmuXhJZ1tztt+MOga5Lk/KutygLpMr1MIyeSBc//s=; b=hg3GFU39J1yEkp5luuV70QoU9OU7iXFf4Yk3s5Ry+ox5Fr7zmEpjiZm8Qr4YHhDudw jAVQ6vClDVuhJFTHM9K4cUQwxqQyWI0Y6P1yuRScVRzqFCs6/06+qXHeF5hzoCisVgC9 yk9zgPoiHjRMS+ygNQxLyvj2fEYa7LQM5cU/AGmL9YUPe4HyzDat312ttGiKdekd0XK1 Kot34TvZ9dRugz2QLq9+BPi1a6CKN+7ZkPkbdpQyIRFXodsq1vazCLU5ltCpZ3jyTCWX j0fSISUu58/Ev30bk5h3tLUP9PiBghTrja9HaeltyCtn1lcfxZJnO6Z0KraOwfn7HGXL s7Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620051; x=1779224851; 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=FdwmuXhJZ1tztt+MOga5Lk/KutygLpMr1MIyeSBc//s=; b=oxRuM/Dl+SRos+DJXrkHtyJGptsuJN9fg4FEVqu2fCYv202P8K4DflgzwFXUf7KsuP aHQlMLShOT2ymO7042/p8me/AbOwrCRqwsRUpdXHaxgl7DBzpD8ur/4/IXdLvPU76x+T 2SA+xn42LaTjVPg5kzMqi3IkduOKQ/kSXgFmfvhKXjJhO+Vc2edMK5z9LOxCSXpFlPbU wicnkkcx+O830fOy7NuipkTtIbguSn9XDs1QtntMbj/9CF3nggX03C58z1wIB3by3qTd RYugN4qA3w75mwDx5RWJE3HyFELGya+ivW1OI9EfIh9DmSxgQB3BVt6suKd8R4i9NNix t7Aw== X-Gm-Message-State: AOJu0Yx6sq8vDdI74ClIpbPLDEUyPemk/VAImubZaKKF+Xu9R3+J95Vb BC3idZRnRf7EJ3i061F683U0RJIsY3cqSJLG/ICwc99il9AEqfGPeNc5gcXgGLeoVStuzbvqlmS BSAatftjwJy95WFxjusA5iaLwuzAjkZDJygQkgiQacuwsIDy3TpGQ+sPV+vyVy72SxnJmg7U6Ow bjiRg2Eu4UzxsL7puw9rD7Z7S3dyhGl9bCENiMbIKeL4o= X-Gm-Gg: Acq92OG80GXSf6bzrnwBZ46F/DA1KhDZ6GzE/2KTYFoftp5Z00fzDjNb8gmvRSx2hOH 9iPtk1Sr4ZQKmeIhxgWmQUcs6CQWnVfC/5N+PXB3ltcE04oE92xZ9C8KduZ7143UBe/E4d4zRVQ OKETL6TSpHQJYEQtr5u7dSe4XVdEtHLy/USOvf35B/lg/I34A77XEjvrf2NtG7AURGXiuX4AoKi QiwA+D/SWjsuKojI5vm8UPE20FexnDs0NOyaVmLFgo9n/MHFSK+rLxrUR8nADXBXXjBy2QJ/cus Wlc6+fajqs1lMrg2xxhAJPkAsdTsPyyQWuMgweFBFk7ePA+OxZQ4WdNKOrfIOMBuFuLPaYeRPt8 Pcp4VlPDAbfLxS7QF6JsCTv1Emgt+hqX/DMAna7eY X-Received: by 2002:a05:600c:3111:b0:48a:568f:ae6d with SMTP id 5b1f17b1804b1-48fc9a0b778mr6279155e9.8.1778620051372; Tue, 12 May 2026 14:07:31 -0700 (PDT) X-Received: by 2002:a05:600c:3111:b0:48a:568f:ae6d with SMTP id 5b1f17b1804b1-48fc9a0b778mr6278315e9.8.1778620050644; Tue, 12 May 2026 14:07:30 -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 ffacd0b85a97d-454917d57aesm35649963f8f.26.2026.05.12.14.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:30 -0700 (PDT) Date: Tue, 12 May 2026 17:07:25 -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 v7 26/31] virtio_balloon: skip zeroing for host-zeroed reported pages Message-ID: <73b896d7fc1b4bb6127f234f5e1964d2764cbf9a.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED (per virtio spec proposal): when negotiated, the device initializes reported pages (zeros, or poison_val if PAGE_POISON). Check per-page used length returned by the device to determine which reported pages were zeroed. If used_len matches the page size, the device successfully initialized the page (e.g. via MADV_DONTNEED), and we set the corresponding zeroed_bitmap bit. Gate host_zeroes_pages on the feature bit and page content: when PAGE_POISON is negotiated with non-zero poison_val, the device fills with poison not zeros, so pages are not zeroed. Clear the feature in validate() if REPORTING is not present or if PAGE_POISON is active with non-zero poison_val. See the virtio spec change: https://github.com/oasis-tcs/virtio-spec/issues/244 Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- drivers/virtio/virtio_balloon.c | 22 ++++++++++++++++++++-- include/uapi/linux/virtio_balloon.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index fc43d0d7bbbc..6586699396b7 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -204,6 +204,8 @@ static int virtballoon_free_page_report(struct page_rep= orting_dev_info *pr_dev_i struct virtqueue *vq =3D vb->reporting_vq; unsigned int i, err =3D 0; =20 + bitmap_zero(pr_dev_info->zeroed_bitmap, nents); + /* We should always be able to add these buffers to an empty queue. */ for (i =3D 0; i < nents; i++) { struct scatterlist one; @@ -223,10 +225,14 @@ static int virtballoon_free_page_report(struct page_r= eporting_dev_info *pr_dev_i =20 /* When host has read buffer, this completes via balloon_ack */ for (i =3D 0; i < nents; i++) { - unsigned int unused; + struct scatterlist *entry; + unsigned int used_len; =20 wait_event(vb->acked, - virtqueue_get_buf(vq, &unused)); + (entry =3D virtqueue_get_buf(vq, &used_len))); + if (used_len =3D=3D entry->length) + set_bit(entry - sg, + pr_dev_info->zeroed_bitmap); } } =20 @@ -1048,6 +1054,9 @@ static int virtballoon_probe(struct virtio_device *vd= ev) #endif =20 vb->pr_dev_info.capacity =3D capacity; + vb->pr_dev_info.host_zeroes_pages =3D + virtio_has_feature(vdev, + VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); err =3D page_reporting_register(&vb->pr_dev_info); if (err) goto out_unregister_oom; @@ -1173,6 +1182,14 @@ static int virtballoon_validate(struct virtio_device= *vdev) else if (!virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON)) __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_REPORTING); =20 + if (!virtio_has_feature(vdev, VIRTIO_BALLOON_F_REPORTING)) + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); + + /* Device fills with poison_val, not zeros; disable zeroed hint */ + if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON) && + !want_init_on_free()) + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); + __virtio_clear_bit(vdev, VIRTIO_F_ACCESS_PLATFORM); return 0; } @@ -1184,6 +1201,7 @@ static unsigned int features[] =3D { VIRTIO_BALLOON_F_FREE_PAGE_HINT, VIRTIO_BALLOON_F_PAGE_POISON, VIRTIO_BALLOON_F_REPORTING, + VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED, }; =20 static struct virtio_driver virtio_balloon_driver =3D { diff --git a/include/uapi/linux/virtio_balloon.h b/include/uapi/linux/virti= o_balloon.h index ee35a372805d..13074631f300 100644 --- a/include/uapi/linux/virtio_balloon.h +++ b/include/uapi/linux/virtio_balloon.h @@ -37,6 +37,7 @@ #define VIRTIO_BALLOON_F_FREE_PAGE_HINT 3 /* VQ to report free pages */ #define VIRTIO_BALLOON_F_PAGE_POISON 4 /* Guest is using page poisoning */ #define VIRTIO_BALLOON_F_REPORTING 5 /* Page reporting virtqueue */ +#define VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED 6 /* Device initializes repo= rted pages */ =20 /* Size of a PFN in the balloon interface. */ #define VIRTIO_BALLOON_PFN_SHIFT 12 --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 6B48E3CAE83 for ; Tue, 12 May 2026 21:07:41 +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=1778620062; cv=none; b=gDfVnzu2YQJ2iJMsemeU+Pit3RJnip53In7GrCsIb4ghi1NkYmMExZxEAm2/I4DsZPQ+69d9QI3KSwmSi34faSn6ErK/gV/NUrvCQnFyxZfVCLlq7k9RjL+KXy0evuesGRUG2BH1gHHoIk+EL0yrmblu70UeoTHMjVVip1Eqj+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620062; c=relaxed/simple; bh=dUSL7eroMCveC7qL1a8RxQsVNz0x+gAKUklqgXhGMFI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=th2HjYHT7ULI89TpxULhzbB51wwDSa/weaIdcTHQArGdBLVSUWmWuSoyq8UVyYjtDzSyUsOd9+VpEaDM8d+9zuyWJQ5r+0DwfTwnNyUf5WytiWPYaNBazPNmuNMUQl2Ypl1Rg6Enlbwj4N05eWWkSpRJRn8WIabzcpXmvhm3csM= 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=f6oZPxAS; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=k5shMr/a; 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="f6oZPxAS"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="k5shMr/a" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620060; 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=carebiiwA0WkwpCm1TTKgYlVMa/8U14hyqClEOGQapg=; b=f6oZPxASmNfFerhXuJ3uUadYqe5fYEQs132GNXXS2BY6AMH5gH5VQGK7mXVQLHnWv/yGnw HmYPACphMmBis6IfOqTmaaDJjommlULmlx5hVe2fL0nl/aNDBA+rGppy7+MQjEnRsdMFW1 TuUbDIliT5ZBHmh8bXmMioNtyyjd9Cc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217--hXhWy9ZPwGPn2OsRcHuhA-1; Tue, 12 May 2026 17:07:39 -0400 X-MC-Unique: -hXhWy9ZPwGPn2OsRcHuhA-1 X-Mimecast-MFC-AGG-ID: -hXhWy9ZPwGPn2OsRcHuhA_1778620058 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-48a589c7879so53154215e9.1 for ; Tue, 12 May 2026 14:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620056; x=1779224856; 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=carebiiwA0WkwpCm1TTKgYlVMa/8U14hyqClEOGQapg=; b=k5shMr/agha1taxb3r7vIwhfeSwZ+A0NINv0lfuZHs5qXxrI2OeQbkoD475OSvOr2I +SeIKCDzChfaO43nG7BchZQzWzJDWkAvpwBknFvBEAM/JyMGzI4t9vpggFa0lVtsqKFi eRnpFvp432PeRM9VXbyoa1tYtR+sx4wyXgGysZh9fh6ip9s1OtKlkDxnRk9B8gGC7tiL /Lnw2IWepYsHiWNzWgUN1wqxoX5J96FVMNaMqJE+MswoaDofyLbMUW94xKzSr8F0+DY0 DUgzNSRc/S/EZXNUP06VTsd6jXJxdVlq+9SQFdnegcg95QO+6o0V/ks90OElMNk4nrnm JzIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620056; x=1779224856; 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=carebiiwA0WkwpCm1TTKgYlVMa/8U14hyqClEOGQapg=; b=qEK9QsMc11v25NO3RprZEzNaGdq3lpXDIajcR+4jbjRdKOywPOTvxlmcP3/g0KZg8a uuEXppnZQg8I8KsRHkOlt70WA0rpVXYiSqYpgUezKkJFhs7GOzdGbhMW8bpPeIYhU9YW M51cj0ku3N55hUENbdNfGK9mcS7m0QG9KTVczMjIG0gxQ8cVOAXSYUfrcVv/SSc8+H7d 5hrRzLBGfZzN4IDVpOfmrcqbkir1Z4UWIjAkDJ0MmeoOZ8ThBDpVH3nlbEmuV4SvSQPi lUPZqEisOGuFCLG8NkTQZhd15Pta6mg3NbUWzRmSjEMma6uzPSYxQEtTJPZ5mnRlqr0V mwQA== X-Gm-Message-State: AOJu0YxWQyXVKIbgorj/6gknKL0D+kBRedNbOKRQMTvQsjo0jCEiPYH5 cl5I00ZpF/GxyhgnncgJfeoAL7GOS+47bW9nEJF7yyOt3f8qgZf7lzMeWhSAD/WMd3yn1zzuqGf SV+F7HFt+Xbnv30EAJ9fIYjpk/qT9D92Wu9kr2B/Q/MZ4JQSS/xjM/fMHHFE8TJOfH0yFH37IB7 MzlDpgX90wq9NU8FxNBndB6/xncRZrQdXSGYD989FJcK8= X-Gm-Gg: Acq92OF0R40Jvv2e3PxiMVNIJ06xsw1gMX/XGdid34xP0jEVqe6vmlb3Eh0GHzj5NqG vihDauGMrkvjMNrOq+2q0Hu02bEES3extmkgl67evYvwIImXBa0feDnFCfyeSQUGhoSl/lZ5e2H 6aZZUSZsfcvIOHoxnnlsguHQQr8hZnkWh3saj0Z6/26hqe0XoF6a9bl0LlfJ5V1a+EPizmEuPEm kM0nPeB/nfkfHmOmZQtIhmRTDjh8tLSzyW5uFTlsTwOZV7MV3F4PgYUdH7h6APBNt26z+nkNZQ4 6oQ5TWg0Ev0L0hv/KWLb6Gz7RVPuDEBWstQnegqDNt4/4JyY98WkRjm5qrwXc9RTFbylK5TXK/T Gjix7marZuSnOaYUv+pxBm2aHN1uNnrrZXD5ordIq X-Received: by 2002:a05:600c:4e55:b0:48a:761:5816 with SMTP id 5b1f17b1804b1-48fc99275d3mr8053895e9.8.1778620056397; Tue, 12 May 2026 14:07:36 -0700 (PDT) X-Received: by 2002:a05:600c:4e55:b0:48a:761:5816 with SMTP id 5b1f17b1804b1-48fc99275d3mr8053095e9.8.1778620055793; Tue, 12 May 2026 14:07:35 -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-48fc8d1986fsm19697375e9.3.2026.05.12.14.07.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:35 -0700 (PDT) Date: Tue, 12 May 2026 17:07:30 -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 v7 27/31] virtio_balloon: disable reporting zeroed optimization for confidential guests Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In confidential computing environments (TDX, SEV-SNP), the host is untrusted and may lie about zeroing reported pages. Clear DEVICE_INIT_REPORTED in validate() so the guest does not skip re-zeroing based on hints from an untrusted device. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- drivers/virtio/virtio_balloon.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index 6586699396b7..02d21147d4c6 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 /* * Balloon device works in 4K page units. So each page is pointed to by @@ -1190,6 +1191,8 @@ static int virtballoon_validate(struct virtio_device = *vdev) !want_init_on_free()) __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); =20 + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); __virtio_clear_bit(vdev, VIRTIO_F_ACCESS_PLATFORM); return 0; } --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 66D403CD8C1 for ; Tue, 12 May 2026 21:07:45 +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=1778620066; cv=none; b=E17r3rvdRK3o1CuTKP8UreQqrEqYNFXr3yt+M6IIe3iAUIHqyx+Bm0+S1+XtgCKvNVPCTCrAsGNYkuSLeyOveeBV3pQHON0B4NyIfy0jwk+nOKUa1R3Wv0Iy+UY42jSAWjG9YDD+1uyptVPScMKqfJPW9b04zb/VZqPTgPyuYw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620066; c=relaxed/simple; bh=wEvn415Fgtrq2ovu0Be2ECwe90TsK5RJeb5vnfFQo5w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QsaCj94lgrSHrHs4rj7uYoO/AsmWEFh9u62PkjynnCRxjwzu4GNm0H9kZ0P3a2RwT3O1Xe9fbeODa6TuqzUnBt09P4y/9fPsAIxM1E3BRqbQdDiUNRPBmYmhmGVSarjMsML6+rx4a8gSu6ayOpiFZkhDeXKUXZWYPwCTQ0NJf30= 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=EQBbSKYI; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Hu1QqZs/; 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="EQBbSKYI"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Hu1QqZs/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620064; 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=D/8VBBw0J+b0eTIG6c4Ba4jQebQb6vF38rsggt16jgI=; b=EQBbSKYIRlTYLLt0orvqFdxIiouldeEHTzspsOqicnJJuHkv8tGGwsPp9Q4FhwPb2wDBWe 5VgZGVKP3EQbqtVsGQTOx02L4mpsI8l5eal6Nj5dEvIHmEJAjN3u/g9P79M7nOWaXTA35C 7/OUZcUiHUd0CwpWPlpGdLoRmqSVQEA= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-152-Y5z566tKMrGsM8rvgrpGDg-1; Tue, 12 May 2026 17:07:43 -0400 X-MC-Unique: Y5z566tKMrGsM8rvgrpGDg-1 X-Mimecast-MFC-AGG-ID: Y5z566tKMrGsM8rvgrpGDg_1778620062 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-43ff19e54beso4180702f8f.2 for ; Tue, 12 May 2026 14:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620062; x=1779224862; 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=D/8VBBw0J+b0eTIG6c4Ba4jQebQb6vF38rsggt16jgI=; b=Hu1QqZs/9IAa7ZPfjqAZgBYfzc3fJ73RfdQOQu74X2BFPhfTKErJEDoPhhT8rUPEaE 2zhd85plF7mtve4aGk5/wxXhaab6JnBIFEoSPY6GUQvYNwXXFoo/8Eh44VseycVy3T5E vNL515F5wcdJ1d13ML/aITlWz2BCulMgrvQiOi9LNCoxOFzJ8VPdoTgQgu7g88n6tV8w D98osWp9VCxyBvFBm5SifOy+5LUNyFM46hLphYkCp3iUXmjCX6qxTWNr/qu96ccN4+Zr le5onf31nd7e33XiOQ8fLJsgdzz9mnHwV75tUzLs09U9FwbmpjlLdDH8SA7yIp3FNJaU ll6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620062; x=1779224862; 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=D/8VBBw0J+b0eTIG6c4Ba4jQebQb6vF38rsggt16jgI=; b=ey1jp1VCGy7RA2nX4sW3x8kkIC+LFlMzG1CnR0yfGyw1bfAKR/YOowyhIk/io3xytZ XtHddm2QBQrh1DIK2KuIbqnapnEjkqFdcYm1M8LeE6b9lsc1SjB3IWpHzwl+/bNJSJ2s 9kECL7/2UP4l/0LJGV41p9kxS6lQdja+bb5ktdOqJyE2O0uFyrV/yX+A+jF545lHJGf8 +sNpAR5fDbUi/gevS+UK6RrDyZ/33AFCEK/lb5qqt4pHD9aOIyMAjCgRaPkznJ6TH2Gb n5bQ07QyJkSKR8sm5Wr1QscbaIj9efK0hWKrKZZmqzdshLNzaMIOsPNcyqh6G+p5FWig pyrQ== X-Gm-Message-State: AOJu0Yw1tV1U2ZGIgo+jMT4KZXI0u9ulh8CsiVy4JgmoJ4edrs3O4WqB xcyLdedBRQp5jyjrpyMW6Cm6iPV35v3uL9EazT3zQ5ylZ03qD6Sy3gg2eziHAiqqQsKdehxvneY r5xHCFkhW3FW91B16JAvrzDGlPZbntcrMco7sC1AnZXhjvErCV7hHkzMqtaq4n0N0gFDcO7cmm5 HK4cIx5wiKY0V5Vj/bYGTFDvdnG0SSVz/e2SBkcx5QGQo= X-Gm-Gg: Acq92OERBjpULIRZ4Zh7Ljg2WlrdAQ6Mh/XfyYnfAHqQQJ7GVRig9gkVgr79ONp1beq bQexhyFT+/gkAILIHDyTnEXwVqxv+DWKnWrWUxZbMwSunpFox95Vmlu+tJNFfzAH0nznr8jPTMp z0KlxVYwRwhAQRtSt6XKAyn84EoQQnxqgNKtVNd9dW4AY7fYYGsyuhR7L3NIxoUgleozDZGSAJF YtUk2PKZDb4VpNatiBgfRxIyXoOXThziNrEhAhE+lP69vhJ7kd9ALfsghDiY9DWoHSog9hu85hG CGwsxFamiObzUwPAt8GnbpruSivoi+G5SQRNQ8oEXngogQW3AFBg77xb3Ds0WxP+GQ86BTDFKIe TvfQlQdkLhI23bXL5mQCdL1Y8pa2WUMxWJ0ilW6CV X-Received: by 2002:a05:6000:2384:b0:43d:71f4:7ed5 with SMTP id ffacd0b85a97d-45c58698080mr544151f8f.17.1778620061459; Tue, 12 May 2026 14:07:41 -0700 (PDT) X-Received: by 2002:a05:6000:2384:b0:43d:71f4:7ed5 with SMTP id ffacd0b85a97d-45c58698080mr544054f8f.17.1778620060883; Tue, 12 May 2026 14:07: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 ffacd0b85a97d-4548e6a66bfsm30848344f8f.4.2026.05.12.14.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:40 -0700 (PDT) Date: Tue, 12 May 2026 17:07:36 -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 v7 28/31] mm: add free_frozen_pages_zeroed Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add free_frozen_pages_zeroed(page, order) to free a frozen page while marking it as zeroed, so the next allocation can skip redundant zeroing. An FPI_ZEROED internal flag carries the hint through the free path. PageZeroed is set after __free_pages_prepare() clears all flags, so the hint survives on the free list. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- include/linux/gfp.h | 1 + mm/internal.h | 1 - mm/page_alloc.c | 21 ++++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index ee35c5367abc..e0d5743de68d 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -384,6 +384,7 @@ __meminit void *alloc_pages_exact_nid_noprof(int nid, s= ize_t size, gfp_t gfp_mas extern void __free_pages(struct page *page, unsigned int order); extern void free_pages_nolock(struct page *page, unsigned int order); extern void free_pages(unsigned long addr, unsigned int order); +void free_frozen_pages_zeroed(struct page *page, unsigned int order); =20 #define __free_page(page) __free_pages((page), 0) #define free_page(addr) free_pages((addr), 0) diff --git a/mm/internal.h b/mm/internal.h index fd910743ddc3..4af5e72742ba 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -938,7 +938,6 @@ struct page *__alloc_frozen_pages_noprof(gfp_t, unsigne= d int order, int nid, #define __alloc_frozen_pages(...) \ alloc_hooks(__alloc_frozen_pages_noprof(__VA_ARGS__)) void free_frozen_pages(struct page *page, unsigned int order); -void free_frozen_pages_zeroed(struct page *page, unsigned int order); void free_unref_folios(struct folio_batch *fbatch); =20 #ifdef CONFIG_NUMA diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ce43f5a3dbaa..8eebe01cda80 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -90,6 +90,13 @@ typedef int __bitwise fpi_t; /* Free the page without taking locks. Rely on trylock only. */ #define FPI_TRYLOCK ((__force fpi_t)BIT(2)) =20 +/* + * The page contents are known to be zero (e.g., the host zeroed them + * during balloon deflate). Set PageZeroed after free so the next + * allocation can skip redundant zeroing. + */ +#define FPI_ZEROED ((__force fpi_t)BIT(3)) + /* prevent >1 _updater_ of zone percpu pageset ->high and ->batch fields */ static DEFINE_MUTEX(pcp_batch_high_lock); #define MIN_PERCPU_PAGELIST_HIGH_FRACTION (8) @@ -1596,8 +1603,11 @@ static void __free_pages_ok(struct page *page, unsig= ned int order, unsigned long pfn =3D page_to_pfn(page); struct zone *zone =3D page_zone(page); =20 - if (__free_pages_prepare(page, order, fpi_flags)) + if (__free_pages_prepare(page, order, fpi_flags)) { + if (fpi_flags & FPI_ZEROED) + __SetPageZeroed(page); free_one_page(zone, page, pfn, order, fpi_flags); + } } =20 void __meminit __free_pages_core(struct page *page, unsigned int order, @@ -3000,6 +3010,9 @@ static void __free_frozen_pages(struct page *page, un= signed int order, if (!__free_pages_prepare(page, order, fpi_flags)) return; =20 + if (fpi_flags & FPI_ZEROED) + __SetPageZeroed(page); + /* * We only track unmovable, reclaimable and movable on pcp lists. * Place ISOLATE pages on the isolated list because they are being @@ -3038,6 +3051,12 @@ void free_frozen_pages(struct page *page, unsigned i= nt order) __free_frozen_pages(page, order, FPI_NONE); } =20 +void free_frozen_pages_zeroed(struct page *page, unsigned int order) +{ + __free_frozen_pages(page, order, FPI_ZEROED); +} +EXPORT_SYMBOL(free_frozen_pages_zeroed); + void free_frozen_pages_nolock(struct page *page, unsigned int order) { __free_frozen_pages(page, order, FPI_TRYLOCK); --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 A745C3CDBD1 for ; Tue, 12 May 2026 21:07:50 +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=1778620072; cv=none; b=aRpuQRSb40Pg5YMOR7kRg5/FVVoczWviRzqN7SRKJ0WWjyhNgvz5oAb+PXYF43c1FIiN377LnaRAsOfGAVV7cNDxtm3DjMEI8Tux1SNETIVAOYpkCPmtkgvrAuco75x0gosIQK/23mj2UJsTAdHZ8klmjCg1MgMZlc/xbsAAlrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620072; c=relaxed/simple; bh=FzG8+92oH2mwvb1TgGky3Bd7ojioTSewgWR4luIpYTY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eCLaqn9zr5s4wrL+MoUKjWIydB1KLtFqjLZG+dEyUUJoaWk+zpUd8e/uw5RDddDkJKsqngajDil9HtHmJ7amHXJL0HbvyCyOMztLqwGl8c9xRkuKbc22FHMVhv4NCwNzQ6K3byvaihpIenPtmBqMnDy3kujPY/cpT7XRuho4OTY= 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=jNp+Nj5D; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=PPh5RJFs; 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="jNp+Nj5D"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="PPh5RJFs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620069; 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=gBKqj2O9gjX/tz0GTabH1SzaDOD5jZb/zvIFduhmeuI=; b=jNp+Nj5DqYNVE0KyOUMbUdK8ujDlW6phBa8jHGJFHZYbHQDRbA3dKHoeWQurnILetOwMLc VQJrbPHMn8c/MKw/iwu2qGwAVK1isVpSzM0lwIViIgYdvc7+8GKEFXBdKzFDtzH9qPlWul gc0CAhGfZ1AVvqtREA3tD/Y+pno6RNM= 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-531-AAMj9BCZPEegoq6hF-5mjw-1; Tue, 12 May 2026 17:07:48 -0400 X-MC-Unique: AAMj9BCZPEegoq6hF-5mjw-1 X-Mimecast-MFC-AGG-ID: AAMj9BCZPEegoq6hF-5mjw_1778620067 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-486fa07f2bbso35898225e9.2 for ; Tue, 12 May 2026 14:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620067; x=1779224867; 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=gBKqj2O9gjX/tz0GTabH1SzaDOD5jZb/zvIFduhmeuI=; b=PPh5RJFsquHe/mrjjmJaUqpdxrS26eIvNl61qDXzyFRFOu5KhAgEFhykDUpHjuRSrv T5epSzHckG+fNtXHm7okHtfKV9D8UKS2NdX46Dews1/6oRSAQhtnO+uzWUAJWr5FLvom /JS2zK+gwxKCZKIr88Q8h/9QPqoVSmo3pBXLl4a93fFVy6DNfNJOj2uRi0J1+mchA/UU 0IiIWQ3eo8+lkdky/OtTpXrPE+7c86/sZeOoTdV1bjMc/fu3BzSuD4ZIdJuGzPwkuFAo Cd+cArTKqaLRcpLR93qnPMY3bgI8+9zXh3Ur1T8aa+3dpiqhXt4WOGovSxN20lerlqic KIsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620067; x=1779224867; 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=gBKqj2O9gjX/tz0GTabH1SzaDOD5jZb/zvIFduhmeuI=; b=p8TCcA8NkCXEuk5dw6G2a4PRp7JMzfc3d0RoKRwqlfv5kWzs8Iug8nbE0S/nwqGzGm h8ibwMjWFs5oWCIGW6uZUcDSsRx4NXYPZaPLY7BPiAou/NaB1PsbKQR+kQrDxW+a241F MqvQulJCgigJ2dPmfFmN7W0lH3a0VMrgxKbqge5KX/p2MXii30A8MCWmAWmIbJRI8vUm KTsYmrR1p+t03WGBj1k6CmsZ0ezTv3ZXt8u7aGKEYcubYX7QnZfoUAbepr3G4u/t9sOk UxkxTOcLBqg17vrYGw0QCmhs406445qaRvr9YLGBmRhjFPTQKUn/SrvSHVg4nPS6HNZ8 yMzA== X-Gm-Message-State: AOJu0YwDD9Rtv18Vr8M1TBw8wgi8zc3hmDsK8avAEdJ9NsIoHaF7EQT9 9TBmzyltHlvu7F3Uln0d9ETSFSIfOev6HdPrwt4+42OLsnz6pojhStpE51kQNu3qnDyVnHDS2n1 OufL5tP+D6ZLdmtCTW36wOVD1rNzpsSEuIJlPGRJ/97NZWjQSFlNdeBTaAFKELZQ5+P7HIwEs3u cq0cQNBUkmZvbcehP9lAJ1Gvwn5G8Byqu22qqhkNvg4xU= X-Gm-Gg: Acq92OGGUM1kU/CZgaVq6M2I0lLe07OCvH9T0lhPW7k+bhs/sU1TMlHw/a0YKeogV/w VOix8PnV04vzydkgr0B8rON7D2hjVg1J7D7PWuFS6IH2gpsifulXYllk2BIpRnOxLqCvvlBSWPU BYUJvHonBJk+WGYmm/HpKM9ArSNh7S7suSgqwBJT4b2I+/ltzA3tiCWray9Q5mZEckuUogexgbV qEoqaB1JqG2F4YbVRQcCjJ0SQrn0ovhrPNHCfqsacDWkVszUUG37veu603XBIj9JCcTh/29DfxX rDsrXDjrT8Al1X2G1trlj5urmZcaeP2rXutfOkZyrKLKQ5s8LXX1OwdLgVPQSmpIVNmM6cqvBDT jfGmTAG/FnwhtLgG8usUGel9fhZzQfWaGv0GNERDR X-Received: by 2002:a05:600c:19ce:b0:48e:7f1c:8778 with SMTP id 5b1f17b1804b1-48fc9a34577mr5610185e9.17.1778620067207; Tue, 12 May 2026 14:07:47 -0700 (PDT) X-Received: by 2002:a05:600c:19ce:b0:48e:7f1c:8778 with SMTP id 5b1f17b1804b1-48fc9a34577mr5609425e9.17.1778620066569; Tue, 12 May 2026 14:07:46 -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-48e8f63beb7sm30481905e9.35.2026.05.12.14.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:46 -0700 (PDT) Date: Tue, 12 May 2026 17:07:41 -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 , Qi Zheng , Shakeel Butt , Youngjun Park Subject: [PATCH v7 29/31] mm: add put_page_zeroed and folio_put_zeroed Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add put_page_zeroed() / folio_put_zeroed() for callers that hold a reference to a page known to be zeroed. If this drops the last reference, the page goes through __folio_put_zeroed() which calls free_frozen_pages_zeroed() so the zeroed hint is preserved. If someone else still holds a reference, the hint is simply lost - this is best-effort. This is useful for balloon drivers during deflation: the host has already zeroed the pages, and the balloon is typically the sole owner. But if the page happens to be shared, silently dropping the hint is safe and avoids the need for callers to check the refcount. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- include/linux/mm.h | 12 ++++++++++++ mm/swap.c | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 3b1ca90fd435..4c51b7bd7576 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1913,6 +1913,7 @@ static inline struct folio *virt_to_folio(const void = *x) } =20 void __folio_put(struct folio *folio); +void __folio_put_zeroed(struct folio *folio); =20 void split_page(struct page *page, unsigned int order); void folio_copy(struct folio *dst, struct folio *src); @@ -2090,6 +2091,17 @@ static inline void folio_put(struct folio *folio) __folio_put(folio); } =20 +static inline void folio_put_zeroed(struct folio *folio) +{ + if (folio_put_testzero(folio)) + __folio_put_zeroed(folio); +} + +static inline void put_page_zeroed(struct page *page) +{ + folio_put_zeroed(page_folio(page)); +} + /** * folio_put_refs - Reduce the reference count on a folio. * @folio: The folio. diff --git a/mm/swap.c b/mm/swap.c index 5cc44f0de987..8d57223dfe34 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -94,7 +94,7 @@ static void page_cache_release(struct folio *folio) lruvec_unlock_irqrestore(lruvec, flags); } =20 -void __folio_put(struct folio *folio) +static void ___folio_put(struct folio *folio, bool zeroed) { if (unlikely(folio_is_zone_device(folio))) { free_zone_device_folio(folio); @@ -109,10 +109,24 @@ void __folio_put(struct folio *folio) page_cache_release(folio); folio_unqueue_deferred_split(folio); mem_cgroup_uncharge(folio); - free_frozen_pages(&folio->page, folio_order(folio)); + if (zeroed) + free_frozen_pages_zeroed(&folio->page, folio_order(folio)); + else + free_frozen_pages(&folio->page, folio_order(folio)); +} + +void __folio_put(struct folio *folio) +{ + ___folio_put(folio, false); } EXPORT_SYMBOL(__folio_put); =20 +void __folio_put_zeroed(struct folio *folio) +{ + ___folio_put(folio, true); +} +EXPORT_SYMBOL(__folio_put_zeroed); + typedef void (*move_fn_t)(struct lruvec *lruvec, struct folio *folio); =20 static void lru_add(struct lruvec *lruvec, struct folio *folio) --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 B0E0E3CE483 for ; Tue, 12 May 2026 21:07:55 +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=1778620077; cv=none; b=VEAiMqpYCUouzRdhajSzEqcCTVHe3cRe7Fl17oekuSvFl5YWs9+n5wv+7ADMF4qxSgdOwi64ow6RdZQz8CYGbtKXiKBaY+G9024jHAZNmFKrWgKFLJTQ63OeLUP1ctOS/BAqxUsKqZnlfAL5YfdtBuNzkajbjYq5wSiPF2FpASY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620077; c=relaxed/simple; bh=gbHGWi857HvIZjWQ3R4rSMwRR/yXb/rr7xrLBv+uOjc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qpVbDwVWtdMbVL4IowQ3CbG13VdjcmyRgVePejhF1bcfwEsXP21Dn2H4vMARSdP8X9h81fNrGw5gaL3tsN6KGKw82IMl1BiCgtPGOM1OOik9GL3KUqm2VvtVSa8o8Ua5mdhQW1UBsr5F+pOTXXnpsSQ2R0kU/hNbJ4+by98fQtA= 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=YpXgWCgv; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=PKqVscKN; 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="YpXgWCgv"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="PKqVscKN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620075; 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=M5u/iM8du1/MGgA4/nGZcoKT5QLcOlAuJz0gbPaxdLE=; b=YpXgWCgvu9cMTIztS5MP46kUz9A/dv0HAcYfBRxGSbmR3xZhhnpe+H2Psb/Evgpct7MtAy KGzB+R1HYWASe+8psuUPoZ1ciHIgmzTl2vSqKlMTh0s9NuPDT4w4tK4nFoqSv+IWud/JfS kEc2Uyea1VNTYLvVpVZW7AANEevR2ck= 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-341-sz76S9e5PrWjYoDOlmxsag-1; Tue, 12 May 2026 17:07:53 -0400 X-MC-Unique: sz76S9e5PrWjYoDOlmxsag-1 X-Mimecast-MFC-AGG-ID: sz76S9e5PrWjYoDOlmxsag_1778620073 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-488d3eec9bcso43613555e9.3 for ; Tue, 12 May 2026 14:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620072; x=1779224872; 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=M5u/iM8du1/MGgA4/nGZcoKT5QLcOlAuJz0gbPaxdLE=; b=PKqVscKNycrk/AUB4vTXI70BiY/K7cRZS5IPlnmyrw59mf7c7QOvkGJdGs84x7sM8A wsQ5Ti7tzeoCi/9WRf8ocmX4O3ed7XJXbBOepGS/DRpoh/uXgHkjuKA9frzefs8WTIy9 58jZ/i6UrTXZvOYGDDsSXmNUhfVhgv0qPi7mUeHBTXTmHrT4otgP+J3FX4PEyREnAHIi if3P9V1QC56mj+mVlAR4hSaKkvwX54rOckYlxnYH9ttX6/pHPnq0ot4BNRh6v/4DJEUa igfJkMdc24fk6iJyTi7jBSOPm5ZH8xiqQZ8Ev1VrbjwmPWGTZ11VP5i6csGIdWdSvqIN fg6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620072; x=1779224872; 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=M5u/iM8du1/MGgA4/nGZcoKT5QLcOlAuJz0gbPaxdLE=; b=kcChTsNEIEw7kgg+9H65EbgfFoZ/OzKQykcl7uXV8dkvGKaCEX94isgsqIbR0zj/Iq RHX1dBTF1N5lgY1aGYuiP7fRvWFXWJ0bSu2IwKZs6Jq0QE9Gu22NbHCw3QNAYY8ut2P2 CrpI32cpCasRhOOwWz86vpHSdH9bVlBw1V0+TVIkoxjdMfM+0uxjTwQ9KvAEZyR48KMg WiQdeY3ZaYdoD+efxy+lCzVyXYUdHyd+O3MFMxr9zDRCXMaJrU/nLNYv9zc7+IthlSmo FLQ6AVVZ/PpOdVzhfI4g2N4E3j0Ntg3eOOWrHNOLGkqirJDTMmsiMJHCOY40hBMfTgor sjCA== X-Gm-Message-State: AOJu0YxTGMvygvkqR17SfNplBxeLDS9Uuv7aYO59bbztas1KBbiOMdgc U9f2GMZcnsgCtxcihWdwBRIy6SfKytUpP2icRfHwbarCdrZanApZjog1EfqWy/SBoh/f90JYwkC flOk/As20H3PgquzQckKZ+N6Ugq30VlGm1LtdXET0sGkYe1D5vjHrwCPgSqc0GdiyjGTwXIDSnj UWbEH039v8Ds8rlR8js7LB4tGJzrn+iHVZgEQMbRWz0RU= X-Gm-Gg: Acq92OE9H3h2722btjAZ/YtbBMSE0Rq+0nfWojiQk3VlsaTx1lGXDRtPOFbVN09RuE0 DtH2QO0MuVBEZ/lFGEL7z/wCjl4Ufw2xyAGFMD+rWxUapSrtn+9JGlmCLWUyHCUylP4/y3d/Cu9 jWuw4lx1OS6XVbLC77HQI3eM9rq1MW7RGXp59Sb2lUvDIxElQaH9gR8gMeIA0hmsDJbzo4mVmY2 K3ArMEDZTsTZr5kzc14R9OA6Et5oDyL+WzTBxuKpfL+Crv1+HaX+s+Gm5kD/g0A+iSpgqufun+t NMRCRJOyzqW+bX9AX/tgAW4y6musUDP1rsDFAOON2FC4OD5h9ai//8O2OWOIi6Lg7S/R1ndyEBa 2D2r9VRVoselCWRMPOxuFo/E2HNm7lYykN4/GYOOx X-Received: by 2002:a05:600c:c08e:b0:48a:5574:3a5b with SMTP id 5b1f17b1804b1-48fc9a5350bmr4617785e9.27.1778620072119; Tue, 12 May 2026 14:07:52 -0700 (PDT) X-Received: by 2002:a05:600c:c08e:b0:48a:5574:3a5b with SMTP id 5b1f17b1804b1-48fc9a5350bmr4617055e9.27.1778620071492; Tue, 12 May 2026 14:07:51 -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 ffacd0b85a97d-4548e4bbebdsm38944373f8f.5.2026.05.12.14.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:51 -0700 (PDT) Date: Tue, 12 May 2026 17:07:46 -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 v7 30/31] virtio_balloon: implement VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE Message-ID: <3b2729a80c19e634f9bc93ca2a8baed8cd760b45.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the device offers DEVICE_INIT_ON_INFLATE (bit 7), the device initializes inflated pages and returns a per-page bitmap indicating which pages were successfully initialized. The driver appends a device-writable bitmap buffer to each inflate descriptor chain via virtqueue_add_sgs. After the host acknowledges, the driver checks bitmap bits (bounded by used_len) and marks pages with SetPageZeroed. tell_host() returns used_len from virtqueue_get_buf(). Bitmap reads are bounded: fill_balloon() and virtballoon_migratepage() only trust bits within the used_len range. On deflate, release_pages_balloon checks PageZeroed per page and uses put_page_zeroed for pages the host initialized, propagating the zeroed hint to the buddy allocator. If inflate_vq has fewer than 2 descriptors, probe fails with -ENOSPC. If PAGE_POISON is negotiated with non-zero poison_val, the feature is cleared in validate(). See the virtio spec change: https://lore.kernel.org/all/9c69b992c3dd83dfef3db92cd86b2fd8a0730d48.177773= 1396.git.mst@redhat.com Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- drivers/virtio/virtio_balloon.c | 102 ++++++++++++++++++++++++---- include/uapi/linux/virtio_balloon.h | 1 + 2 files changed, 90 insertions(+), 13 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index 02d21147d4c6..f3929a238c8b 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -121,6 +121,9 @@ struct virtio_balloon { struct virtqueue *reporting_vq; struct page_reporting_dev_info pr_dev_info; =20 + /* Bitmap returned by host for DEVICE_INIT_ON_INFLATE */ + DECLARE_BITMAP(inflate_bitmap, VIRTIO_BALLOON_ARRAY_PFNS_MAX); + /* State for keeping the wakeup_source active while adjusting the balloon= */ spinlock_t wakeup_lock; bool processing_wakeup_event; @@ -181,20 +184,30 @@ static void balloon_ack(struct virtqueue *vq) wake_up(&vb->acked); } =20 -static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) +static unsigned int tell_host(struct virtio_balloon *vb, struct virtqueue = *vq) { - struct scatterlist sg; + struct scatterlist sg_out, sg_in; + struct scatterlist *sgs[] =3D { &sg_out, &sg_in }; unsigned int len; =20 - sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); + sg_init_one(&sg_out, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); =20 - /* We should always be able to add one buffer to an empty queue. */ - virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL); + if (vq =3D=3D vb->inflate_vq && + virtio_has_feature(vb->vdev, + VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE)) { + unsigned int bitmap_bytes; + + bitmap_bytes =3D DIV_ROUND_UP(vb->num_pfns, 8); + bitmap_zero(vb->inflate_bitmap, vb->num_pfns); + sg_init_one(&sg_in, vb->inflate_bitmap, bitmap_bytes); + virtqueue_add_sgs(vq, sgs, 1, 1, vb, GFP_KERNEL); + } else { + virtqueue_add_outbuf(vq, &sg_out, 1, vb, GFP_KERNEL); + } virtqueue_kick(vq); =20 - /* When host has read buffer, this completes via balloon_ack */ wait_event(vb->acked, virtqueue_get_buf(vq, &len)); - + return len; } =20 static int virtballoon_free_page_report(struct page_reporting_dev_info *pr= _dev_info, @@ -297,8 +310,37 @@ static unsigned int fill_balloon(struct virtio_balloon= *vb, size_t num) =20 num_allocated_pages =3D vb->num_pfns; /* Did we get any? */ - if (vb->num_pfns !=3D 0) - tell_host(vb, vb->inflate_vq); + if (vb->num_pfns !=3D 0) { + unsigned int used_len =3D tell_host(vb, vb->inflate_vq); + + if (virtio_has_feature(vb->vdev, + VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE)) { + unsigned int i; + unsigned int valid_bits =3D used_len * 8; + + for (i =3D 0; i < vb->num_pfns; + i +=3D VIRTIO_BALLOON_PAGES_PER_PAGE) { + unsigned int pfn, j; + bool zeroed =3D true; + + if (i + VIRTIO_BALLOON_PAGES_PER_PAGE > valid_bits) + break; + for (j =3D 0; j < VIRTIO_BALLOON_PAGES_PER_PAGE; j++) { + if (!test_bit(i + j, vb->inflate_bitmap)) { + zeroed =3D false; + break; + } + } + if (zeroed) { + pfn =3D virtio32_to_cpu(vb->vdev, + vb->pfns[i]); + __SetPageZeroed(pfn_to_page(pfn >> + (PAGE_SHIFT - + VIRTIO_BALLOON_PFN_SHIFT))); + } + } + } + } mutex_unlock(&vb->balloon_lock); =20 return num_allocated_pages; @@ -311,7 +353,12 @@ static void release_pages_balloon(struct virtio_balloo= n *vb, =20 list_for_each_entry_safe(page, next, pages, lru) { list_del(&page->lru); - put_page(page); /* balloon reference */ + if (PageZeroed(page)) { + __ClearPageZeroed(page); + put_page_zeroed(page); + } else { + put_page(page); + } } } =20 @@ -858,7 +905,25 @@ static int virtballoon_migratepage(struct balloon_dev_= info *vb_dev_info, /* balloon's page migration 1st step -- inflate "newpage" */ vb->num_pfns =3D VIRTIO_BALLOON_PAGES_PER_PAGE; set_page_pfns(vb, vb->pfns, newpage); - tell_host(vb, vb->inflate_vq); + { + unsigned int used_len =3D tell_host(vb, vb->inflate_vq); + + if (virtio_has_feature(vb->vdev, + VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE) && + used_len >=3D DIV_ROUND_UP(VIRTIO_BALLOON_PAGES_PER_PAGE, 8)) { + unsigned int j; + bool zeroed =3D true; + + for (j =3D 0; j < VIRTIO_BALLOON_PAGES_PER_PAGE; j++) { + if (!test_bit(j, vb->inflate_bitmap)) { + zeroed =3D false; + break; + } + } + if (zeroed) + __SetPageZeroed(newpage); + } + } =20 /* balloon's page migration 2nd step -- deflate "page" */ vb->num_pfns =3D VIRTIO_BALLOON_PAGES_PER_PAGE; @@ -963,6 +1028,12 @@ static int virtballoon_probe(struct virtio_device *vd= ev) if (err) goto out_free_vb; =20 + if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE) && + virtqueue_get_vring_size(vb->inflate_vq) < 2) { + err =3D -ENOSPC; + goto out_del_vqs; + } + if (!virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) vb->vb_dev_info.adjust_managed_page_count =3D true; #ifdef CONFIG_BALLOON_MIGRATION @@ -1188,11 +1259,15 @@ static int virtballoon_validate(struct virtio_devic= e *vdev) =20 /* Device fills with poison_val, not zeros; disable zeroed hint */ if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON) && - !want_init_on_free()) + !want_init_on_free()) { __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE); + } =20 - if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) { __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE); + } __virtio_clear_bit(vdev, VIRTIO_F_ACCESS_PLATFORM); return 0; } @@ -1205,6 +1280,7 @@ static unsigned int features[] =3D { VIRTIO_BALLOON_F_PAGE_POISON, VIRTIO_BALLOON_F_REPORTING, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED, + VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE, }; =20 static struct virtio_driver virtio_balloon_driver =3D { diff --git a/include/uapi/linux/virtio_balloon.h b/include/uapi/linux/virti= o_balloon.h index 13074631f300..cbaf18e0b17c 100644 --- a/include/uapi/linux/virtio_balloon.h +++ b/include/uapi/linux/virtio_balloon.h @@ -38,6 +38,7 @@ #define VIRTIO_BALLOON_F_PAGE_POISON 4 /* Guest is using page poisoning */ #define VIRTIO_BALLOON_F_REPORTING 5 /* Page reporting virtqueue */ #define VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED 6 /* Device initializes repo= rted pages */ +#define VIRTIO_BALLOON_F_DEVICE_INIT_ON_INFLATE 7 /* Device initializes pa= ges on inflate */ =20 /* Size of a PFN in the balloon interface. */ #define VIRTIO_BALLOON_PFN_SHIFT 12 --=20 MST From nobody Fri Jun 12 20:16:54 2026 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 E96583CE4B5 for ; Tue, 12 May 2026 21:08:01 +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=1778620083; cv=none; b=i6z49zDh0bwoVppL9+UAX63Adzdg/U3U2XRpZ7WY1XvwZDugspUj+gEKnyXNmx7oGLXdVFqsLB+M/T2tqbIq/q8bkVF1rwnDkuHR5Sq/MonBT2ZyzTRt5hZDwnRgE6JvuS/lYRu7KuW0U3iXkfOemDLdXYM5BqWCoHzB4RrdQ+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620083; c=relaxed/simple; bh=mQqx6N7f4HKujpbDEae/MRGG23U+Ado82zzAxmBrUmI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=txSvWfNZ/14r8itJ11Vlce7b2xPZOkvfPq30xmtPtr9gpfIIxocQU958IoErkQXid/RNDimv56bwIqmnCnCiReYirvNgp2kwSrynFK1KuhA5kkwXOHn3x/6dU078DeSXwyuOUS23Gl9HCVnCgba2k+4BXbnbvDLKA+IgE7HhGMA= 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=YFv3ZJ22; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=l3vWO/Rw; 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="YFv3ZJ22"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="l3vWO/Rw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620081; 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=MpBn8Jg+yemSfT/rKcYB8AJ8VmedmgkSc9fIviOsi3s=; b=YFv3ZJ22xEyteI8P4frS4mhqVBB4f7JcwCYAiX6Lnnp8SxAucYTyJoiCXififJwSs8GmNX ZCpb9/5m8r1EnIi/1PKQ5Zh18K6icSLepp3uLGKKQWgmTW1qfq7/GLzWFxVgy5LoLjKuJ0 pd3QtRvh15+D6RBAjKdzIRjNXaSZvvU= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-9jG7cJMSNrSvua84bN7nOQ-1; Tue, 12 May 2026 17:07:59 -0400 X-MC-Unique: 9jG7cJMSNrSvua84bN7nOQ-1 X-Mimecast-MFC-AGG-ID: 9jG7cJMSNrSvua84bN7nOQ_1778620078 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-488bd1ee9e7so65887625e9.1 for ; Tue, 12 May 2026 14:07:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620078; x=1779224878; 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=MpBn8Jg+yemSfT/rKcYB8AJ8VmedmgkSc9fIviOsi3s=; b=l3vWO/RwysywDDzORzLxl3NdapkJMTpbExBUlmaOpB2MxBnXqTF5tAbvS0PuohMHhg n3FVHPIvNZwopYKy9GjWgvgfxs6n+p6S0J4vNqnQ1kKNt2aQhdPp4bO17rL5catgZriG G4D7wJKMr8SG+h+s9XVgxfclYJkyy2IxrrLt6dCtxi1me3djq5sxTgIS04kzsQoQV6j2 rqUh/Of3ld2ZBoXee5jn7BXPdzzH1cWyAsKZ1lZREvM048yaGVcgjIXGZsaAJBTA6t46 cURJx+BCiHJCbSbxbIJSMuvqVgD1H2wcLtkEcbaM6Bj3mfs2DrZ9nB54TmOINv5zzPjm x8lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620078; x=1779224878; 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=MpBn8Jg+yemSfT/rKcYB8AJ8VmedmgkSc9fIviOsi3s=; b=ebiSFySpAPZoECOZog0iFYbvTrfxUsvdI6fSIvIXP0FizsugQXxzdgW/OMf3o4Dk3N SPDBURGVCK9v7FoW+rKava01kiD9MUE0GzsgvxCMZO1oYmSbF+G/mhmWMDoYOjsA58uF TwddTWT11VFqi5fJhTJoU3DkvReQfcRLxXzLVFKDl28F/IPdkS/+IAAnyNU3+skL8q/J SiFUcPOPAgQKI0uF04rp2fpqD+HDyanmWwVt1mGApNTezdfU6wIE93bKdpFyXOJ7xxqm P4Zd7vhxOMVZr2N5Y7QR6TW4O1rQn4tLeBs+N9klk7RwlDBNyy3yahznZrOR3VCa+g3m pcQA== X-Gm-Message-State: AOJu0Yyq9zSeCX54CNRMDKCo3z6t8v0wAthKUTotGzdtMgn+0hwObvAE xkOCCKxmd3WuNgm9QotVOsZLXpVymzxrSdedHg7WwgZzaoHd5yH6AXxgbwahk2xQmPahTEO27fl NUdZbGF8YlHbQevOpWfswWcfr64LXgvjaTzpVWVOxtA9xeAH2nL1H+T47eK27ZEGxfThAk5Qe8K sMdbLC+2xq4gntr3df8Hi+7VzdtYxi9XjjTcflI9ZwSKE= X-Gm-Gg: Acq92OHcnM0XnbIR4wbuyRbkOiwooQN94AeUU9zIMs7PMpgCFaE2NKLcUng+QPNCEVB hHw3LviGJjlo3SBbgukcB7k8zC+HHtScZrwnEPCuMJtyAX3khwpkDqRWBn5jE9NAgf18pRV/ZzO YHhFMgPBZ2C8fggP4kwWkehX31GK7wqCcuT5FS6GkCJNCOe0NjugwlB/2TtAFUcEs3fZNihpIrp TwsR0Sp4D3fbBfCubo8O/EnZtU2hR43ON2cx0hJqUPqwOERNRJYdX7FBaYhb+Y5Gs4133R5EavI XG0qURWYrw2+jjuJmIxm9LXM5QPorEXMWiL+Z0hTHD8IYIILcpsaJgry1qxEvkp69WSbDGMG7Ik P9Yn9BZzzrLX5wJl+mJv4U0B6T5A4GSEaJ9B7HB+g X-Received: by 2002:a05:600d:9:b0:489:1b0c:8b43 with SMTP id 5b1f17b1804b1-48fc9a03148mr4865555e9.1.1778620078014; Tue, 12 May 2026 14:07:58 -0700 (PDT) X-Received: by 2002:a05:600d:9:b0:489:1b0c:8b43 with SMTP id 5b1f17b1804b1-48fc9a03148mr4864945e9.1.1778620077400; Tue, 12 May 2026 14:07:57 -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-48fce066eeasm50325e9.7.2026.05.12.14.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:56 -0700 (PDT) Date: Tue, 12 May 2026 17:07:51 -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 v7 31/31] mm: balloon: use put_page_zeroed for zeroed balloon pages Message-ID: <13d76c12caad0008bee3d659cd986aeaf9a5fea2.1778616612.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-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a balloon page marked PageZeroed is freed during migration, use put_page_zeroed() to propagate the zeroed hint to the buddy allocator. Previously the hint was silently lost via plain put_page(). Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- mm/balloon.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/balloon.c b/mm/balloon.c index 96a8f1e20bc6..1bf7eb2642a9 100644 --- a/mm/balloon.c +++ b/mm/balloon.c @@ -324,7 +324,12 @@ static int balloon_page_migrate(struct page *newpage, = struct page *page, balloon_page_finalize(page); spin_unlock_irqrestore(&balloon_pages_lock, flags); =20 - put_page(page); + if (PageZeroed(page)) { + __ClearPageZeroed(page); + put_page_zeroed(page); + } else { + put_page(page); + } =20 return 0; } --=20 MST