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 29291392802 for ; Mon, 13 Apr 2026 20:37:27 +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=1776112648; cv=none; b=fehb123WuATyPVvBBGMV9L4G2/xMqPjTkFVGZOMGNPV4y21p/Tr7QiT0znHSYN3Jhug2HgiZjfiu4epXNq8vK8WQ/DT979Pxo0k8fRQGMDWMFdvLXqltczYCDckn+ap8fdBGamYqX36v2g4MhLyZVgZ+zqYBKznspHUTpMf96+c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776112648; c=relaxed/simple; bh=3UOTDcLdkNpvNQuTboJmVRuKOVO/Ckh+7yVmvV9A5Zc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OXFE6S1Clgg6jJ/UAqKGZducghRFpIXoJ2RMiG9S1y/uN+zzxQbYwVHkiuBucoqanbloCITPEs1zgimLxGetu7MzPea7eN2/zFJp4MEkqKEt9gVhM5/aanEEWsSnw6N+6eacHads69aLpXA0htp2RJr3d4tlAKaPIxESUAGcYpA= 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=ALw5sTnQ; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=tNxGBWwe; 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="ALw5sTnQ"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="tNxGBWwe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776112646; 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=x+jn9tzh7nhmbt6+qjsG4Y4k6+ZRmcZ6RnPQ8R+vTBg=; b=ALw5sTnQdoqAdF/wpCLGxP9wlqfchag8mgrV8Ee5CALFvOxpRGc0o3lHhLWyvfr88Qh2wp 9jG60kaGr9izzjINuD0fFnwiI0kDaahVUbyLP9mqqZ1o/lToSaVyy1bUUyXtJwCUfx8z5n VvU6x71NYsy24qu6RUGynttKCIBJL3g= 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-449-xWuk8lJSP9uR0IFEQ53XHQ-1; Mon, 13 Apr 2026 16:37:25 -0400 X-MC-Unique: xWuk8lJSP9uR0IFEQ53XHQ-1 X-Mimecast-MFC-AGG-ID: xWuk8lJSP9uR0IFEQ53XHQ_1776112644 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-43d7757463eso703217f8f.0 for ; Mon, 13 Apr 2026 13:37:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776112644; x=1776717444; 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=x+jn9tzh7nhmbt6+qjsG4Y4k6+ZRmcZ6RnPQ8R+vTBg=; b=tNxGBWwec/RwYfnoq06a/Phde4gBkBzpkhwJGxPPh7ASaXFe3BnIV6ml1hXuBarQC/ k35ZXg4Drf69+fOIekelFchYUBOh4xFYPb2WSiHcb+S/eGk9dbL4eH3CGNDm6KJ/pyIx RYMqPaxKosdk4cjohA6xEcWyUGCRZ4NbckymGkndFEWWp+YYJHbSg7vOHWzIIXvrdkZ4 iuf5Pbw1APLGJY7oDYzHQs5SyG87ogXVT40vmWO6hJDN2odVoWqSH1m5Xjq7r4UVV2M6 fqyaxD3oaWlzYd4mAv5Rv/jOqJMiOsH+qDzWWVec17+h5s3391k5GTdeXBV2yDZM42GG 51mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776112644; x=1776717444; 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=x+jn9tzh7nhmbt6+qjsG4Y4k6+ZRmcZ6RnPQ8R+vTBg=; b=Jbm5v++8Y34F4ZfFHn/D4jh4QyrbdhZTevKkVdGiF2nGlAiSFC40/+TOyd9rhA4zMx 8Un2dhlNrGFukx0GPMBBmYlemVG2UXwx8bf7RF+ID3lJOb3TM97lf3TVdLqJFAPFse7t xPPA9tHn2CsQ/rnnpIJY59/TciTEtz4lykBB71Lk0hTgZdzZqNf/vpk6kpWxlgMe2Xjn DfEJqy50QTtCV6c83nN05l1tMFJb+WtbP3T7KsqtcaG8S5/f6XUMFH3XDgw834LlvQ9n 1cRn+igAxCjTB3LBwaQV2lRudzYJhxeDevc1wiDrpi0zoACH4ZWWBqXky97TsrGdNPmU Bq2Q== X-Gm-Message-State: AOJu0YyvqFdcPMeDBQVckW/FU/VMAPceT7Q8KXD6s1d0r0ktb+M7u3xZ M+TPT3V3UjzYX45EV/2blYftETm/WVWb/HkYGUQ1btU1xAlpN6zaeNkXKyH1E0e7c9egtwgKK6t 6oZEBekparJ0P1OCEEvZACWK/VicPTpNYOT1YLyF1548ftZfYbHCUXClhakNoXPG9cg== X-Gm-Gg: AeBDieuWCgrBfspM1rNOX5MUlNGTariPTigy9mP+nC4egExnV3xU6J0LZUMglt3c0UD 9pz0sQ2df/cAaR9kMpBPBqMRUCdlj8WfGqNIC3yWbl8wKjyuy0s1AKoh07mn4oQ7RCSfDZp+cax 2KMZW/jIjcCdgWvTgo2M4iQ1FkXh5mBDM1AyLVzwTWclgw2tWJ1ZTEY4ABhqNN7Ojdxu8OfhsZO rtiOV75D45A/VhBQnsStX0JEdQ7mPB5vnf5pi+N4P684P3O2VWU3ZJ1zCCZcIgR2c/uU7CtJ7ou WUVfz7sBpcBi2M+aQ2ZdPRZlJSeTLUQFqeeguHTj2obbWsd+WNr1YRctrrACxFhd75ODwHQlVk0 RZH2DvsopRb/dNlvtWP3b2v3SeFD8bxHifOtPkDwiPqw= X-Received: by 2002:a5d:5f44:0:b0:43c:f926:1fa with SMTP id ffacd0b85a97d-43d594ad27fmr26223984f8f.0.1776112643662; Mon, 13 Apr 2026 13:37:23 -0700 (PDT) X-Received: by 2002:a5d:5f44:0:b0:43c:f926:1fa with SMTP id ffacd0b85a97d-43d594ad27fmr26223952f8f.0.1776112643201; Mon, 13 Apr 2026 13:37:23 -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-43ea5f26274sm283900f8f.1.2026.04.13.13.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2026 13:37:22 -0700 (PDT) Date: Mon, 13 Apr 2026 16:37:19 -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 3/9] mm: add __GFP_PREZEROED flag and folio_test_clear_prezeroed() Message-ID: <20260413163644-mutt-send-email-mst@kernel.org> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Apr 13, 2026 at 11:05:40AM +0200, David Hildenbrand (Arm) wrote: > On 4/13/26 00:50, Michael S. Tsirkin wrote: > > The previous patch skips zeroing in post_alloc_hook() when > > __GFP_ZERO is used. However, several page allocation paths > > zero pages via folio_zero_user() or clear_user_highpage() after > > allocation, not via __GFP_ZERO. > > > > Add __GFP_PREZEROED gfp flag that tells post_alloc_hook() to > > preserve the MAGIC_PAGE_ZEROED sentinel in page->private so the > > caller can detect pre-zeroed pages and skip its own zeroing. > > Add folio_test_clear_prezeroed() helper to check and clear > > the sentinel. > > I really don't like __GFP_PREZEROED, and wonder how we can avoid it. > > > What you want is, allocate a folio (well, actually a page that becomes > a folio) and know whether zeroing for that folio (once we establish it > from a page) is still required. > > Or you just allocate a folio, specify GFP_ZERO, and let the folio > allocation code deal with that. > > > I think we have two options: > > (1) Use an indication that can be sticky for callers that do not care. > > Assuming we would use a page flag that is only ever used on folios, all > we'd have to do is make sure that we clear the flag once we convert > the to a folio. > > For example, PG_dropbehind is only ever set on folios in the pagecache. > > Paths that allocate folios would have to clear the flag. For non-hugetlb > folios that happens through page_rmappable_folio(). > > I'm not super-happy about that, but it would be doable. > > > (2) Use a dedicated allocation interface for user pages in the buddy. > > I hate the whole user_alloc_needs_zeroing()+folio_zero_user() handling. > > It shouldn't exist. We should just be passing GFP_ZERO and let the buddy handle > all that. > > > For example, vma_alloc_folio() already gets passed the address in. > > Pass the address from vma_alloc_folio_noprof()->folio_alloc_noprof(), and let > folio_alloc_noprof() use a buddy interface that can handle it. > > Imagine if we had a alloc_user_pages_noprof() that consumes an address. It could just > do what folio_zero_user() does, and only if really required. > > The whole user_alloc_needs_zeroing() could go away and you could just handle the > pre-zeroed optimization internally. > > -- > Cheers, > > David I admit I only vaguely understand the core mm refactoring you are suggesting. -- MST