From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dog.ash.relay.mailchannels.net (dog.ash.relay.mailchannels.net [23.83.222.48]) (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 3AD811A9FB0 for ; Tue, 7 Apr 2026 01:07:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=23.83.222.48 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775524061; cv=pass; b=Ttn8QY9RgWICK5c5GoPAPdqKMJWkwX5E1tYAAqzfjWgILnPhH2/Gk+H4EIILa7LMnQ6e3khY4/tTZ2co5rDmishuR7LorvyQJXzu2Ua1gI+trr1cOdSCkrNfYpnq/KgoJDARALK7b6ViuJBm8vKf2z0RDL2bw+l+/TGL7QZT3rg= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775524061; c=relaxed/simple; bh=eTW30qTPGzkW/22eJixcnXHrDMmesT4QFIv6IwZrzK4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jC4hHOwvLojD9na/QBHLzDTxMYKaEZInIM+Wk2WQRgTho6X8MnGJGXOmp+HMf49swk2ZwL3aNsUvD2WiVMxq8EP7E/pfVeooXrzhX+jQ3+dwYG5ICj5kCyMItM+/qP8v1K8JI+oIQLZUp1XWgUxGp1oADJCa96jvY+RP5JTxou8= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=stgolabs.net; spf=fail smtp.mailfrom=stgolabs.net; dkim=pass (2048-bit key) header.d=stgolabs.net header.i=@stgolabs.net header.b=mv1Cg4rr; arc=pass smtp.client-ip=23.83.222.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=stgolabs.net Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=stgolabs.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=stgolabs.net header.i=@stgolabs.net header.b="mv1Cg4rr" X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id C60C37E2FB9; Tue, 07 Apr 2026 00:50:30 +0000 (UTC) Received: from pdx1-sub0-mail-a247.dreamhost.com (trex-green-6.trex.outbound.svc.cluster.local [100.118.167.109]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 5656D7E2FE6; Tue, 07 Apr 2026 00:50:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; d=mailchannels.net; s=arc-2022; cv=none; t=1775523030; b=PQ8g6XBGhZ3w8GyAzZxmtZDDF8PRma6cYXOwYdQ1IXTE60d7reRM30s5WLPy+SyoWuoEA2 OXktNd2OKP0/azrdNfbZYnbijPeqA53TMuG/6XKtLSmWyyAuz4z97WE64KamvHOC0S0g/k Y+NzGdsHa/Tp8l85MzMIEOVuoL5xJhEBgJUCyC7K4aN2Q+3oCw4O95y2ILtL+Y6ETuMZl5 ETgMcOhLk+ebgdiQk9wxu8szouKShR7XegUHkmPMnKwazj+/zm1GuXfCyNqTabOI60zMxI lju02TVt2n0OGLAWeDqTavsgxa7t42KLuuDhjsO5X6V2Rn5nXstkw+wLSMRlfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1775523030; 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:dkim-signature; bh=cMwxCUdDzcCtqZxPCuLtLzFRvDztipo2RCcHqTcTHXY=; b=A7QBoKdFgJgD6nuljAjde7LQCjT6y/o4QFt+4Qo7FUmaUcjblJOBetMcWpO8lMJZfB7Wi+ ENkAYNmYhWozJfRMlftCEUG6SLH0lxljHws/KbGvlG0t8+xCWaz7VmWUDEhQ0pmYejZWiQ hTEoOTrmHFoDgpcchs4Vh6UaaLgycCPFOX5xSiC0DtGeK+c3HW43RloeCfJfIfbZoR7j4W +mqACVNEw2lkTzGDWUlH2JdxU35T7mPhbjWoQe6phJCwbmpsuVNJqOr3tjVeDPNZ4SHdzp FroUHCdnJ96iC8pvCOPbtf/W1b+O+ZB4rdhFEomffKssda8htW5HgcjEm3f8jw== ARC-Authentication-Results: i=1; rspamd-7d86dcc447-zkbxw; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Cooperative-Relation: 7a2bd04419e8d27e_1775523030651_2650626807 X-MC-Loop-Signature: 1775523030651:4205056266 X-MC-Ingress-Time: 1775523030651 Received: from pdx1-sub0-mail-a247.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.118.167.109 (trex/7.1.5); Tue, 07 Apr 2026 00:50:30 +0000 Received: from offworld (unknown [76.167.199.67]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a247.dreamhost.com (Postfix) with ESMTPSA id 4fqSKd484Wz106F; Mon, 6 Apr 2026 17:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1775523030; bh=cMwxCUdDzcCtqZxPCuLtLzFRvDztipo2RCcHqTcTHXY=; h=Date:From:To:Cc:Subject:Content-Type; b=mv1Cg4rr3UA6eaGve5YgvG77w4ObAXvFsTim2FNTd9d8Gbzgy4wB6+r6kLbfSXn8Y EcKmcQvmIANOGQl2dekmu76q4jfs3F9s+Ad99W/odWYAafHnaKGlULG65Lm5BEdGjw UHB0iLDE86uWB+iKmySfhCCHC6RyptXweYrd1MQ7x6NtnqsW1kRnbaAT3sVtBOLaWv XuTF53MdQZj5JigOcH4K4GAnKc5m3WaBhxvIy8zqG5AHZJzPhdsdpvLX0Zpe3MJ/YF 9PJUAhRo3ph6CNQv/vu1CtLqX4CAYiJAQYisog9w553GsEQdeHF0+CqQKP7bh897vH fQUVajMRWapAA== Date: Mon, 6 Apr 2026 17:50:26 -0700 From: Davidlohr Bueso To: Pedro Falcato Cc: Andrew Morton , "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , David Hildenbrand , Dev Jain , Luke Yang , jhladky@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/2] mm/mprotect: special-case small folios when applying write permissions Message-ID: <20260407005026.ytf7ed4bk2ljyflx@offworld> Mail-Followup-To: Pedro Falcato , Andrew Morton , "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , David Hildenbrand , Dev Jain , Luke Yang , jhladky@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260402141628.3367596-1-pfalcato@suse.de> <20260402141628.3367596-3-pfalcato@suse.de> 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; format=flowed Content-Disposition: inline In-Reply-To: <20260402141628.3367596-3-pfalcato@suse.de> User-Agent: NeoMutt/20220429 On Thu, 02 Apr 2026, Pedro Falcato wrote: >@@ -334,34 +371,20 @@ static long change_pte_range(struct mmu_gather *tlb, > > nr_ptes = mprotect_folio_pte_batch(folio, pte, oldpte, max_nr_ptes, flags); > >- oldpte = modify_prot_start_ptes(vma, addr, pte, nr_ptes); >- ptent = pte_modify(oldpte, newprot); >- >- if (uffd_wp) >- ptent = pte_mkuffd_wp(ptent); >- else if (uffd_wp_resolve) >- ptent = pte_clear_uffd_wp(ptent); >- > /* >- * In some writable, shared mappings, we might want >- * to catch actual write access -- see >- * vma_wants_writenotify(). >- * >- * In all writable, private mappings, we have to >- * properly handle COW. >- * >- * In both cases, we can sometimes still change PTEs >- * writable and avoid the write-fault handler, for >- * example, if a PTE is already dirty and no other >- * COW or special handling is required. >+ * Optimize for the small-folio common case by >+ * special-casing it here. Compiler constant propagation >+ * plus copious amounts of __always_inline does wonders. > */ >- if ((cp_flags & MM_CP_TRY_CHANGE_WRITABLE) && >- !pte_write(ptent)) >- set_write_prot_commit_flush_ptes(vma, folio, page, >- addr, pte, oldpte, ptent, nr_ptes, tlb); >- else >- prot_commit_flush_ptes(vma, addr, pte, oldpte, ptent, >- nr_ptes, /* idx = */ 0, /* set_write = */ false, tlb); >+ if (likely(nr_ptes == 1)) { Are there any numbers for this optimization? While I am all for optimizing the common case, it seems unfair to penalize the uncommon one here. Why is nr_ptes > 1 such an exotic use case (specially today)? ie: How does this change affect the program in b9bf6c2872c ("mm: refactor MM_CP_PROT_NUMA skipping case into new function"), which is a series for optimizing large folio cases. Thanks, Davidlohr >+ change_present_ptes(tlb, vma, addr, pte, 1, >+ end, newprot, folio, page, cp_flags); >+ } else { >+ change_present_ptes(tlb, vma, addr, pte, >+ nr_ptes, end, newprot, folio, page, >+ cp_flags); >+ } >+ > pages += nr_ptes; > } else if (pte_none(oldpte)) { > /* >-- >2.53.0 > >