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 3E5B33D4112 for ; Tue, 14 Apr 2026 10:22:12 +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=1776162139; cv=none; b=QfQzEtMuM/HoxBbQsSI3gn6891Ce3VtG1LgDAU8S1+2vyNMz8gWPSBmOiHLdK9kLI+uAo3thSI9L7LcjqP1BaI8imUzy9fTbd17ymnZDPuxEBwzqZOIAxTJXKfVzr8Xp5E/R8/3NPYIv7y/MXXDlheDUAAH2CtKSsok4BAYONoE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776162139; c=relaxed/simple; bh=xILvyVtg9LF65+dVUQ70weH6IfOdBLvSQOgd6Pwdrvo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QtvIA1fVxyamxCvByBzAOxGsikh8Q1zdNd75EXSHdRTgfmYsVddudzqIvDgj3iUK4iJDw1sfKIJ8/lS1SArcyc4ybl+u7x5NrrQKg9G3z2xlZruwGIp0shr1WqSj7fMUFCiGe5wG39PxDW8Tf8sFqLzsPQg3/Azi2mZ+F8IsNUA= 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=TTc9XV9u; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=tyvWTawV; 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="TTc9XV9u"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="tyvWTawV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776162129; 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=BckpnXSCVQvxxavP5rvqgYmN6kasGEX6+ue3Zi6tRyM=; b=TTc9XV9u/mjd7Ckij7YmmggErysPO4ECfQ5iMlUrAgfcN4qJjyp8w/Aft3fC7zM4UxzELH fvkLh/BUb8tWsUeaaP40oPMY0t3qDTdGzUtO68Qy4Vx28xe1IdMzCbxamvnVAqq1h+hX5y V33RgYH7sWFZKGYYrTrwFEQnefd9aUk= 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-539-pA5pUau0NmWZ01LGJhQa9A-1; Tue, 14 Apr 2026 06:22:08 -0400 X-MC-Unique: pA5pUau0NmWZ01LGJhQa9A-1 X-Mimecast-MFC-AGG-ID: pA5pUau0NmWZ01LGJhQa9A_1776162127 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-486fa07f2bbso27233055e9.2 for ; Tue, 14 Apr 2026 03:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776162127; x=1776766927; 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=BckpnXSCVQvxxavP5rvqgYmN6kasGEX6+ue3Zi6tRyM=; b=tyvWTawV/bQHtRB1AiS0qmokoWzk3ra9A76fd/2uRx6Nxwex68BFuwxKxuFlv1Dweu zgPvcM73FP0Ef9eXPxEzUjwMMEtuZKCCMZfk2kigVLClUxjNdjG41Olya/md6MhRM6U6 HqZYp/KDJhMgQ3+/jxNzJpLHW31P7nyMJkHCZyjbH3E0CKJwl3Ud7YKFB2nKZhoSg/26 ZW7ri7DlN3d2jvFvOmxhH7I0df8tA4vi1OorLwMjSIC82d55samJLiRFfQITaULlRljm YUFXaRJqyQVZap9l1MhlyaruBeyT7ewreOr6tiTG8hxadqZzSAcqXc0BLrFU2s5Agnnu HpZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776162127; x=1776766927; 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=BckpnXSCVQvxxavP5rvqgYmN6kasGEX6+ue3Zi6tRyM=; b=FoPzVcEoGv0oZWK7fWShk1v3YrkBPSHP3oqudv+u0tBzENbxbNagTCixcUyQ69UAm4 iR2kvLQzSqCc9HVz9mUKSl0DFXxGIkpfyV9fUQ9u2RemRcnXe8JAOa9KDEKeTXdtDd8I 88QoBnmrG0o4V3d99Auwt5qWlarvSzMJ+cvv/GMyaMl5bRbMFDAwUxPzIwunsH9HTqvX dcNTJ/ClPXMMBmccczJIoY2b4EntR6JyubN2sk7mU1webQUIt76WGzC2f6FXcQ3FViCP 1G9UgU2HViZGi8FG3XNbMiBjmXI49LvdHF5I/97VjaUt9KhkKTx9IwTbUV013bjD18Mf rTDg== X-Gm-Message-State: AOJu0Yz+vucJH2Fa1o50GF4/A0E63Rsmkb9XaU2/abhbAeClMZgvugwD 5Q7UOi196t+VVlDCOOu5ZzYVhOeYwgoVzOOCjDU3Xc2kL0sw/anCjHqPLDEs5aaVmqhbMB3kZWh 454Gu9N/aGedBk1KxvVu1TqdnPz0wsslTe0h4Mr8R4kLz+ORaP9X8ySC52lPLRO+lrA== X-Gm-Gg: AeBDieuLFd9zWZD49sm6MbtSP5ujZkgWuhhlQN+1kf8WNC3YlfZvjVqWU6BBevXyeYe QWdsHcEmkYKFXVDWivvrssPBnQE2xoNE6UQ3GT11ZU0PQqwsELPPGEimgnKdo6wRDQ9h7Db5YP8 SejAdBg/XpSdALT71e70i/t4cW0miwo9vQCA/gt/EPWKVXdfa2MrSKmLGcalIC00NQmHuj6LYy2 vBtkM8XMJotSQfQ2v+rquDZUAySkcu2arEmGL1v/VYZ5GsxmQ2TniHEqBtVWrhaAx15FMeYkQoL AQrBRee/6LC/4IHl9YyFL/1gI+aFVy0WO5rwYpu9Gj91xNg8HfCU4SJBim/5AXVxjMzldbELyyv Fir0ro4d5dElIRXWPSQltse+aibFADetX91xhcXQ/yG0= X-Received: by 2002:a05:600c:c094:b0:488:cc72:5497 with SMTP id 5b1f17b1804b1-488d6ad5ed3mr156716875e9.31.1776162126946; Tue, 14 Apr 2026 03:22:06 -0700 (PDT) X-Received: by 2002:a05:600c:c094:b0:488:cc72:5497 with SMTP id 5b1f17b1804b1-488d6ad5ed3mr156716545e9.31.1776162126454; Tue, 14 Apr 2026 03:22:06 -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 5b1f17b1804b1-488d67b128dsm194935355e9.2.2026.04.14.03.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2026 03:22:05 -0700 (PDT) Date: Tue, 14 Apr 2026 06:22:01 -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: <20260414062015-mutt-send-email-mst@kernel.org> References: <2155527a-e077-4b71-80ee-d735f9984f60@kernel.org> <20260413163233-mutt-send-email-mst@kernel.org> <244c9779-b4a5-4d0f-9eb9-ef0ec873e0f6@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: <244c9779-b4a5-4d0f-9eb9-ef0ec873e0f6@kernel.org> On Tue, Apr 14, 2026 at 11:18:02AM +0200, David Hildenbrand (Arm) wrote: > On 4/13/26 22:35, 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? > >> > >> 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. > > > > > > So here's an only alternative I see: a page flag for when page is in > > buddy and a new "prezero" bool that we have to propagate everywhere > > else. This is a patch on top. More elegant? Please tell me if you prefer that. > > If yes I will squash it into the appropriate patches. > > I'd be interesting to know how this would look without the GFP flag, > when we don't have to leak any of this out of the buddy. > > -- > Cheers, > > David But the zeroing takes place outside of the buddy now, it's more "reporting" than "leaking". You mean, moving the zeroing into buddy? See https://lore.kernel.org/all/20260413184022-mutt-send-email-mst@kernel.org/ -- MST