From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC1223932FF for ; Mon, 13 Apr 2026 08:29:19 +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=1776068961; cv=none; b=f2L9THzpZkmeSJtunuwyhcuUMpM3oOS0vuFymfjD19uHzRz3lV2+qTNE5cgkr9S9OUpP+MjnXoNbqQdJgAEj35zVAiqHZ97/T7AhfwPcllpyPdAb4SDeZVwyVp5pHUQf0DlPJLLNaD01QVmoS3RIPD6v/9yMHtyr0oSVqwHRIm0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776068961; c=relaxed/simple; bh=IynBP1xNxhC0gDIWmoXTYME2eIumM1yWHA/A/mJzrOA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BS/usS/ETbQgiCKjEyfM4CDQ3Yk8vi6qVHYbw6wjd6/Me9uhXzZcm5q4+5JL6f+PpOw1EydknL6TvBNsZ4N6jHh0cYJg+qAH/0BbN0739fU6jPclpYP6XkRUwKKI6gFPkOlj6uWpPzwT1GBoEyZvlFzhNCYkuiicb0dB5JbLOHQ= 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=AN+FIDzr; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=O84LnF34; 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="AN+FIDzr"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="O84LnF34" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776068958; 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=d7T2EfZlOhL6EGzqfce/4yeDNVNuR7hO+mhzu7kbbMs=; b=AN+FIDzrmyfWJ3RvNXWH4ooH7mDvNzMykzzsHOnK4LZEqEUZH0eJghfRuyWGUTj9ysN5cZ wdJZt+jNjwaquAAs3puOmvlHnQoIsvxiKJthlhIjArin7jrCrGusGSHi45nkzKm0EWRZlC jNNqqFyPwZXSoXiFc0Wi2OVzV/sH6/c= 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-357-ZgoJxHVmPM6MMQPXpZg4kg-1; Mon, 13 Apr 2026 04:29:17 -0400 X-MC-Unique: ZgoJxHVmPM6MMQPXpZg4kg-1 X-Mimecast-MFC-AGG-ID: ZgoJxHVmPM6MMQPXpZg4kg_1776068956 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-43d1ceb2ddfso3776632f8f.2 for ; Mon, 13 Apr 2026 01:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776068956; x=1776673756; 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=d7T2EfZlOhL6EGzqfce/4yeDNVNuR7hO+mhzu7kbbMs=; b=O84LnF34vQR6OcVvZ3rGaI+mdLL0Ozp47msIF76q8roHuHuBlRcGpx8cU1gbLQ30fg I6XhSVby7hY5u61jMHtew3D4STlkYmNpu2s2mUgTcXVOqA1Zb5GWMp72VnhPlLq42LS5 Gj8JU6HgDUJMzUMpvn4FH101mAhXusrKU91I/qZPMYu0vJGfBzGNjB6fJkOGa4MECBkx zxYF5E3olLUtbmi+DaN3wQVKZ1k5ccj/qzvccLsSiQFCd5D9SJj1poZu9QblgjbIK42Y 2g7GW0tg0QQXLJIh2NnVarDJL8S+ygkoMDZIOTE60Oxd83En0yRZysdwsUPrhDEMzWfz VMZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776068956; x=1776673756; 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=d7T2EfZlOhL6EGzqfce/4yeDNVNuR7hO+mhzu7kbbMs=; b=RmeMipiPEuHX+fi9Zp//NCcOzHWb9ShBIz3WsEAGK5AF+qYVJKCqs+mZSjUB7r1FdU K5gU8gO7bLoNAhb94OrZ4L7uTYNIQtNVmPD9rT0HeYtlj4teJhy7VRS4fhk/f1j7t6W8 kd5F5RTctU3C3zNi6N3F2GoiFe+2gXxzHzdLwtsZ6D/YBadupGXHaO2aFxqp36env6WU MFSQEvfyzbXGZ1YVrtezKq2WJhiylzdH2fLwS5+TIgN1WclpvnXyYS5whnntYAjUQ0i9 mObwSqTjRoHmQmftIcHBI7MpizN8YywTwwIhdzhFhe/WYU7ybdI9SxQ5MzzRjF6ZXEA6 i36g== X-Gm-Message-State: AOJu0Yyrk4qUOR7BCRKA5PW1c/zz62mOKNbWFTYXQhJvSxoMZ2ZuA7Ok 7RF1cXfGD5oVpxndlpusXJbxuOhROaiAjUPyiRmDSW6LFogmCfHC0vYB4FVNeFxLL0+jvfQZX1h s7Iv3UQk1fsgI30EndfEWpHeRBwxmXNGPPDcvEZpJoK9DsH/WNkL9qWVum8hNdTsAtQ== X-Gm-Gg: AeBDiev61R5qyBHS2oQNuk3OsSy+OH0TzAWD1xAyahJ70aBZXy61SbLpZR0f7tvciJr ncu0EusZAvDjzhRm7i5AT6vKuWjSKGglEA1hYvkyu6OKss5riX3f2G1h4YjhpDpvXgRH3ReA+/1 iPZCaNtT7MBrdYAFL+xU7EWolM9iE/PGIy7tWpKs/spHWbhF7h76MQa0EA6tF+0esmfqSLAyojK XMz1MgpQ9aCleCjwZSj2ir20dCZVxzzK3175evDHAvOwrRE9Du59YtUPouKyjRwjTyP4yMkfKT/ 3DHp+WxG9fvzHpqiQr1zn55yuUBmRaVFelZiRCJOBf0UIIkQvwvSv/SXDU2ZZoqbSoz+8BE5vQ1 NO+SEIrJ3aXlSyKeaB+QgggwaQ4/m5PVIMZB0qpH3jtk= X-Received: by 2002:a5d:5f86:0:b0:43d:2be:e54 with SMTP id ffacd0b85a97d-43d642b5035mr18655089f8f.39.1776068955994; Mon, 13 Apr 2026 01:29:15 -0700 (PDT) X-Received: by 2002:a5d:5f86:0:b0:43d:2be:e54 with SMTP id ffacd0b85a97d-43d642b5035mr18654999f8f.39.1776068955408; Mon, 13 Apr 2026 01:29:15 -0700 (PDT) Received: from redhat.com (IGLD-80-230-25-21.inter.net.il. [80.230.25.21]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d7bd2f237sm3321886f8f.23.2026.04.13.01.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2026 01:29:14 -0700 (PDT) Date: Mon, 13 Apr 2026 04:29:10 -0400 From: "Michael S. Tsirkin" To: "David Hildenbrand (Arm)" Cc: linux-kernel@vger.kernel.org, Andrew Morton , Vlastimil Babka , Brendan Jackman , Michal Hocko , Suren Baghdasaryan , Jason Wang , Andrea Arcangeli , linux-mm@kvack.org, virtualization@lists.linux.dev, Lorenzo Stoakes , "Liam R. Howlett" , Mike Rapoport , Johannes Weiner , Zi Yan Subject: Re: [PATCH RFC 2/9] mm: page_reporting: skip redundant zeroing of host-zeroed reported pages Message-ID: <20260413042505-mutt-send-email-mst@kernel.org> References: <2155527a-e077-4b71-80ee-d735f9984f60@kernel.org> <20260413040143-mutt-send-email-mst@kernel.org> <4e1b349b-d0df-4ad5-8050-9a2b3b3831ac@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4e1b349b-d0df-4ad5-8050-9a2b3b3831ac@kernel.org> On Mon, Apr 13, 2026 at 10:15:08AM +0200, David Hildenbrand (Arm) wrote: > On 4/13/26 10:10, Michael S. Tsirkin wrote: > > On Mon, Apr 13, 2026 at 10:00:58AM +0200, David Hildenbrand (Arm) wrote: > >> On 4/13/26 00:50, Michael S. Tsirkin wrote: > >>> 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 by propagating the "host already zeroed this" > >>> information through the allocation path: > >>> > >>> 1. 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. > >>> > >>> 2. In page_del_and_expand(), when the page was reported and the > >>> static key is enabled, stash a sentinel value (MAGIC_PAGE_ZEROED) > >>> in page->private. > >>> > >>> 3. In post_alloc_hook(), check page->private for the sentinel. If > >>> present and zeroing was requested (but not tag zeroing), skip > >>> kernel_init_pages(). > >>> > >>> In particular, __GFP_ZERO is used by the x86 arch override of > >>> vma_alloc_zeroed_movable_folio. > >>> > >>> 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 > >>> --- > >>> include/linux/mm.h | 6 ++++++ > >>> include/linux/page_reporting.h | 3 +++ > >>> mm/page_alloc.c | 21 +++++++++++++++++++++ > >>> mm/page_reporting.c | 9 +++++++++ > >>> mm/page_reporting.h | 2 ++ > >>> 5 files changed, 41 insertions(+) > >>> > >>> diff --git a/include/linux/mm.h b/include/linux/mm.h > >>> index 5be3d8a8f806..59fc77c4c90e 100644 > >>> --- a/include/linux/mm.h > >>> +++ b/include/linux/mm.h > >>> @@ -4814,6 +4814,12 @@ static inline bool user_alloc_needs_zeroing(void) > >>> &init_on_alloc); > >>> } > >>> > >>> +/* > >>> + * Sentinel stored in page->private to indicate the page was pre-zeroed > >>> + * by the hypervisor (via free page reporting). > >>> + */ > >>> +#define MAGIC_PAGE_ZEROED 0x5A45524FU /* ZERO */ > >> > >> Why are we not using another page flag that is yet unused for buddy pages? > > > > Because we need to report the status *after* it left buddy. > > And all flags are in use at that point. > > I'll comment on that on the other patch, where __GFP_PREZEROED, which I > really hate, is added. > > > > > > >> Using page->private for that, and exposing it to buddy users with the > >> __GFP_PREZEROED flag (I hope we can avoid that) does not sound > >> particularly elegant. > > > > But propagating this all over mm does not sound too palatable, right? > > There's precedent with MAGIC_HWPOISON already. > > Better ideas? Thanks! > > I'll comment on the __GFP_PREZEROED patch. > > > > >> Also, if we're going to remember that some pages in the buddy are > >> pre-zeroed, it should better not be free-page-reporting specific. > >> I'd assume ordinary inflating+deflating of the balloon would also end up > >> with pre-zeroed pages. We'd just need a (mm/balloon.c -specific) > >> interface to tell the buddy that the pages are zeroed. > >> > > > > Indeed, it's also easily possible - it's a separate optimization, though. > > Another simple enhancement is including hugetlbfs freelists in page > > reporting. > > Doesn't need to block this patchset though, right? > > Not blocking, but I don't want something that is too coupled to > free-page reporting optimizations in the buddy. I can add that in the next version if you like, sure. The main issue is that it means we need a flag that survives free. And the benefit is much smaller - unlike page reports, deflates are rare. > The comment above > MAGIC_PAGE_ZEROED triggered my reaction. yea, that's more confusing than helpful. > -- > Cheers, > > David