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.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 B424E25A2C6 for ; Wed, 22 Apr 2026 21:20:39 +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=1776892841; cv=none; b=aIafYqGk0H/hl96MLlLKUKLwtXlGWq1dQ04SBI3v0GJijrx/2uHV2zsHmKKQBQSbdQic98/3lJJLkZzXDP+zOqph3gvrYF8UZF8cyAliFg6XyiG8PurLjDAtcqQMRzbvglvXT4OdfESclv3DptmxEQTWYNgzOiWwV6cILnZerpM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776892841; c=relaxed/simple; bh=6SyZvBrbf+USjtmnc7xlaVRQIMYtEt4QvTpWJfC1Iso=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TzY6jXuy1th5gkhH5B6MKvHv3ZqHVyuXcY/dsODO5LGALx0jnzRob4vfAi/ih993G84z7SesgWgPxsnZD3RYZGgyDRzR4GzEmlISzDUC0RyThMrEq4eCvBGVaY/E1CIwLbEM6Ktovo+JEu2HYRlIsRlRwpK8M9RMDrnEAElaiwo= 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=Nl7i5d/w; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=H2bw9nzo; 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="Nl7i5d/w"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="H2bw9nzo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776892838; 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=0AuBD0WIXDzq4C1LKbO1zkVvixca9JBQuddXhofRNlk=; b=Nl7i5d/wImawKl47dD4N9QLsdnPu49CbJOsSz0BudkJ9QPur2L45jnb+E/jK0AllVh7CRY Gsf95hNvaK2HrBm/a5QBWBt0BFBNG7pMt+U6ejRuuqqzKYVsarhQBsra0z6vI3K0NbfH4c oXcRSHeGT86hl1ku8RYE5FE8kbFCqwU= 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-76-iP7bn0w1OTGvJpTIkcmOKQ-1; Wed, 22 Apr 2026 17:20:35 -0400 X-MC-Unique: iP7bn0w1OTGvJpTIkcmOKQ-1 X-Mimecast-MFC-AGG-ID: iP7bn0w1OTGvJpTIkcmOKQ_1776892834 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-4411a2ff53aso2097301f8f.0 for ; Wed, 22 Apr 2026 14:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776892834; x=1777497634; 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=0AuBD0WIXDzq4C1LKbO1zkVvixca9JBQuddXhofRNlk=; b=H2bw9nzopWSTl+KkC0ptpyJkyR6Q4yrxdSjWma5E7SETq0P8twd4uvVcEHc88A1zzr JWmZmQJdo1LT/V68j3b7k0Aj7QzNFMU4LDXqQz/9q8HyNVJwrGsICskp7iVDGjeGYaeD PBjKF8a7sjFUapjmW3dCzeCKJoGX1XwTFicdK2UgBsjxntJ+JeX9v2mUwo17luEjGWxD GccY90Y6yty+D+l4cuTckHKY1HkyBWJVaOD+83AmRl81mMla0AbKf4MiO+Ya5XURS/Sq IA45ALRAU0rC4mhGZ0/gSGYyD0UIN6T3OB2vvZCzsFzDFp4TqxhttLa8hLhlUo+lT4N7 hI3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776892834; x=1777497634; 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=0AuBD0WIXDzq4C1LKbO1zkVvixca9JBQuddXhofRNlk=; b=fny4DutYubwGo31eFv2L8b5KMmyeDejWKO/imLhzFTpGRqBfrikw+pCQkoHY5njOor YBkFXOrZnr776QMLRNAkSZA+CgnWoWfFaYIvHjXeD2fZICeIab2stproiOdJMS+VYljH YSh5x7isBBuVATpEIeuRfzuHkosAw2u0s5XW5JlnrIXpRAdORFpyBlYmFv0LCPKmZjqI 4FyCKQ1r2BacOehCfCug9ymUtQxHp334gtjruBGLLteBD9uKtEonkE9tMsSEGx32eReh noJ+4npXCDFIPbOOQqKB8wDf58S9a9OyuF+x5+35BhkXoRHW4DqS/9rcvmO3ltkjmvUB KF7w== X-Gm-Message-State: AOJu0YxhZuiBrJYCQS6Zpl4iJotwN/6TY9+2a0igNSdJRf9JVB86JE2I 6t1u4Jl8X2/Jq30/NZEdWfYA2gdjTK2/7ATgT/EtUse/GqsxHwbiYZAzVxvF2NqhHYYpL/DODex zfP8isGZhEFaJabFfYNs/5FU5hv35kB4GurdxWuODfVk1ao1PcT8bIw15cMjmo/5GfA== X-Gm-Gg: AeBDievEfZbjm/w1k7Pc4ut9oAf0/ir342E7xoQEMICQtuk8Wu1GKv1nVE/FTmRBmiU HqAbZPbRhwHOjftpg9eTgNoRV49Fd5ZYh76kKimq8yR/fnR5SQeEv7YPZi4RPwzLfo04J/csJAY 6ACDxohyYqE0wiQ0a5TOMpP7VgZYsWxBPucA8raS+dP7Reyojchtyr2TkJ7/dOayUGANTyWOo3P IVHWaRA4wMwDefui7RXZDpQmV1dFmiL+wNmDFo1NdP0BpomVzsvqgt5HhZaQlGexLMjw0Qh95qr HE+rNBPe+mDhHFYZWSKGEOcHa3QVnIdKvLGADIB+QfDGgrp9M+fCUm1eh3khTfBwPowseak5EHT mzal1HoynHofokqfr/JINmK4RdH5XC3HT4B3u5KvWtYlCAGeqfqjTqw== X-Received: by 2002:a05:600c:8115:b0:488:ac01:72b6 with SMTP id 5b1f17b1804b1-488fb77d7d3mr296536375e9.21.1776892834265; Wed, 22 Apr 2026 14:20:34 -0700 (PDT) X-Received: by 2002:a05:600c:8115:b0:488:ac01:72b6 with SMTP id 5b1f17b1804b1-488fb77d7d3mr296535725e9.21.1776892833712; Wed, 22 Apr 2026 14:20:33 -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-488fc10777csm537060875e9.8.2026.04.22.14.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2026 14:20:33 -0700 (PDT) Date: Wed, 22 Apr 2026 17:20:27 -0400 From: "Michael S. Tsirkin" To: Gregory Price Cc: linux-kernel@vger.kernel.org, Andrew Morton , David Hildenbrand , Vlastimil Babka , Brendan Jackman , Michal Hocko , Suren Baghdasaryan , Jason Wang , Andrea Arcangeli , linux-mm@kvack.org, virtualization@lists.linux.dev, Johannes Weiner , Zi Yan , Lorenzo Stoakes , "Liam R. Howlett" , Mike Rapoport , "Matthew Wilcox (Oracle)" , Muchun Song , Oscar Salvador , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Ying Huang , Alistair Popple , Hugh Dickins , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , linux-fsdevel@vger.kernel.org Subject: Re: [PATCH RFC v3 01/19] mm: thread user_addr through page allocator for cache-friendly zeroing Message-ID: <20260422171315-mutt-send-email-mst@kernel.org> References: <9dd9deabd42801f3c344326991d1431c3d8db39d.1776808210.git.mst@redhat.com> 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 Wed, Apr 22, 2026 at 03:47:07PM -0400, Gregory Price wrote: > On Tue, Apr 21, 2026 at 06:01:10PM -0400, Michael S. Tsirkin wrote: > > 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 > > > > Public APIs (__alloc_pages, __folio_alloc, folio_alloc_mpol) gain a > > user_addr parameter directly. Callers that do not need user_addr > > pass USER_ADDR_NONE ((unsigned long)-1), since > > address 0 is a valid user mapping. > > > > Question: rather than churning the entirety of the existing interfaces, > is there a possibility of adding an explicit interface for this > interaction that amounts to: > > __alloc_user_pages(..., gfp_t gfp, user_addr) > { > BUG_ON(!(gfp & __GFP_ZERO)); > > /* post_alloc_hook implements the already-zeroed skip */ > page = alloc_page(..., gfp, ...); /* existing interface */ > > /* Do the cacheline stuff here instead of in the core */ > cacheline_nonsense(page, user_addr); > > return page; /* user doesn't need to do explicit zeroing */ > } > > Then rather than leaking information out of the buddy, we just need to > get the zeroed information *into* the buddy. > > the users that want zeroing but need the explicit user_addr step just > defer the zeroing to outside post_alloc_hook(). > > That's just my immediate gut reaction to all this churn on the existing > interfaces. > > Existing users can continue using the buddy as-is, and enlightened users > can optimize for this specific kind of __GFP_ZERO interaction. > > ~Gregory Hmm. Maybe I misunderstand what you propose, but this seems pretty close to what v2 did - each callsite checked whether the page was pre-zeroed and called folio_zero_user() itself. The feedback (both you and David) was that threading it through the allocator is better. With a wrapper approach, looks like we'd need something like __GFP_SKIP_ZERO so post_alloc_hook doesn't zero sequentially, then the wrapper re-zeros with folio_zero_user(). But then the wrapper needs to know whether the page was pre-zeroed (PG_zeroed), which is cleared by post_alloc_hook before return. So the information doesn't survive to the wrapper. We could return the zeroed hint via an output parameter, but that's what v2's pghint_t was, and it was disliked. The user_addr threading through the allocator does add API churn, but it's all mechanical (adding one parameter, callers pass USER_ADDR_NONE), any mistaked are just build errors. And it makes the zeroing path closer to being correct by construction: every allocation either explicitly says no address or has a user_addr - and then gets cache-friendly zeroing or skip-if-prezeroed, with no possibility of a callsite forgetting to handle it. Fundamentally, David told me I need to move folio_zero_user into post_alloc_hook as a prerequisite to the optimization, so I did that - let's stick to it then, shall we? This approach also fixes a pre-existing double-zeroing on architectures with aliasing data caches + init_on_alloc, where current code zeros once via kernel_init_pages() then again via clear_user_highpage() at the callsite. I don't see how that would be possible with the wrapper. -- MST