From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795112574; b=bc9sQTlxpxj4NDmV4sMREK54jqV0WSxMvXt1WZxJ3BSBpV71XJizM8+TeV/WFSjyVmHX KGx7MyJUgf6DqaGRX8TSqII+3mODGErioXXrPjYwInaYfR9vVPrpkRH7xHvERBfOD79DL kzYp5//e/m29kUpZ6UY46yzouCVxHCQUXremnGMonRPZBoSZ7lFXYwqDY7kScWJUm4Chd /CFfXI0XkFSeVlmh/Gt1EkORqt+EF8B1+qxCFqqjhj2XmeLLT9gMYC9efWT5iYZ4antYb wdk98V2yn4L8Bu0aAR34SlyDS2FdFQZaRPzWgoGXOfhWz8G0rt6/zgmUZS/qSHyF2AA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795112574; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=ZfsfFEJM82krByuOVGPOZZKv9Osma7QbzsdrPPTac/s=; b=ks/qHNea/0n2TNFLxkKrFQGGFzQQ1ymw9Z5Rus4iTbt+IV6nGq3fDlJg9SZiK+z3x9wy YKR2LuUFckUuUdSvTxCV2HqlkU3iTgIT7Cmuq9LZf14NyQgWGvOszKmWdkTCWvaMnC/9a HytqnhUVEnpfywvVfWSg1O3Iel/xK+3Dp7eJjVy2baIW1znDEG7qJCRwmeR2gJQr2g2dC ZObA8AfxE/NbnTp31UrMUxEHAWpzFCdVo6M804eDoZ2tLvLByhsY2MhI7Rnn26ZB6hesT id15jA7TaNKq4iBEt2E9PsEeNDjhAEvhNB2B2/UzHHBKZIWoDVhH3mUdOavY5Mk28/w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SXMU8n0n; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEE40606A320 for ; Thu, 19 Nov 2026 18:22:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SXMU8n0n Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BA991F000C5; Thu, 19 Nov 2026 18:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795112574; bh=ZfsfFEJM82krByuOVGPOZZKv9Osma7QbzsdrPPTac/s=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=SXMU8n0n7HXvIZMBaIH/Sj2ALikU/NZyraGWrOKCkESGWY7SJKRbHud/A4KvFVB4Q SbIrRDc/P6vWCjfXMaopS3UWETKT4B6yGuhi+pwrAK8SNQHvCfylkkG1NBFmw6gvIu H3bN2qXd0b/JXtif/5WkqT0iz3DHkOvjB2r7E99qPBiDguG886zzvpVAVt5VbyxTVj mvOAFdaP+g0/FxNTAcjBBPTeOdxC2LqscC2wf1QFaL1OyJoBzvlXAfw305Xvet0ALF Z4+TZF+DOH1qNJmzg77iUGY0b74R0BV3AqdQ7EEpvR+VrwctmUyYm024rgLCT4LAsn V5LIXAAUjSKNw== Date: Thu, 19 Nov 2026 18:22:49 +0000 From: "Lorenzo Stoakes (ARM)" To: Avi Weiss Cc: david@kernel.org, akpm@linux-foundation.org, rppt@kernel.org, peterx@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, liam@infradead.org, mhocko@suse.com, surenb@google.com, vbabka@kernel.org Subject: Re: [PATCH] mm: skip temporary folio allocation for anonymous UFFD missing faults Message-ID: References: <20261119180015.933433-1-thnkslprpt@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261119180015.933433-1-thnkslprpt@gmail.com> +cc missing. Please just stop. You sent 7 series across 6 different subsystems over 11 hours. You(r AI) even failed to cc the right people (added). On Thu, Nov 19, 2026 at 08:00:15PM +0200, Avi Weiss wrote: > An anonymous write fault on a VMA registered for missing userfaultfd > faults currently allocates, zeroes and memcg-charges a folio before > checking the PTE and handing the fault to userspace. The folio is then > immediately discarded without ever being mapped. > > Check the PTE and address-space stability under the PTE lock before > allocating a folio when missing faults are registered. Deliver the fault > to userfaultfd without allocating and discarding a temporary folio. > > In a four-boot native B/P/B/P comparison, the mean UFFD fault median > fell from 13,997.75 ns to 13,093.55 ns (-904.2 ns, -6.46%). A guest > allocation trace saw 256 fewer allocations in the faulting task for > 256 registered missing faults. A .9us delta on a _uffd_ fault (nobody in their right mind puts it on a hot path) with no standard deviation? Seriously? > > Note: this changes OOM ordering. In a fixed 18 MiB memcg test, the > baseline OOM-killed only the faulting client before delivering a UFFD > event. With this change, the event reached an unprotected shared handler, > and its UFFDIO_COPY allocation could trigger an additional OOM kill of the > handler. A separate surviving client consequently lost its handler and > failed a page-content check after the UFFD registration was released. > The same handler-death mechanism was reproducible on the unmodified > (mainline) kernel when memory pressure was imposed after event delivery > but before UFFDIO_COPY, although the fixed-limit outcomes differed. This is both unreadable word salad and alludes to you causing possibly breaking changes for a barely-distinguishable-from-noise fault time improvement. > > Signed-off-by: Avi Weiss Please stop submitting patches, thanks. "You are expected to understand and to be able to defend everything you submit. If you are unable to do so, then do not submit the resulting changes." https://docs.kernel.org/process/generated-content.html > --- > mm/memory.c | 22 ++++++++++++++++------ > 1 file changed, 16 insertions(+), 6 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 0fb676d..63b39fa 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -5547,6 +5547,22 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > ret = vmf_anon_prepare(vmf); > if (ret) > return ret; > + > + if (unlikely(userfaultfd_missing(vma))) { > + vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, > + vmf->address, &vmf->ptl); > + if (!vmf->pte) > + goto unlock; > + if (vmf_pte_changed(vmf)) { > + update_mmu_tlb(vma, vmf->address, vmf->pte); > + goto unlock; > + } > + ret = check_stable_address_space(vma->vm_mm); > + if (ret) > + goto unlock; > + pte_unmap_unlock(vmf->pte, vmf->ptl); > + return handle_userfault(vmf, VM_UFFD_MISSING); > + } > /* Returns NULL on OOM or ERR_PTR(-EAGAIN) if we must retry the fault */ > folio = alloc_anon_folio(vmf); > if (IS_ERR(folio)) > @@ -5579,12 +5595,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > if (ret) > goto release; > > - /* Deliver the page fault to userland, check inside PT lock */ > - if (userfaultfd_missing(vma)) { > - pte_unmap_unlock(vmf->pte, vmf->ptl); > - folio_put(folio); > - return handle_userfault(vmf, VM_UFFD_MISSING); > - } > map_anon_folio_pte_pf(folio, vmf->pte, vma, addr, > vmf_orig_pte_uffd_wp(vmf)); > unlock: > -- > 2.43.0 > -- Cheers, Lorenzo