From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796100256; b=XJzpLdqfJnQhHwhJVSRegNxo8JvLcwPzLSmnXZKCeS0bDnNeyDdYRnA8lUKuNNajnF6+ uo7Yn+bzvAC39c1syuMsWCLcmfYEo30axYwEOf8OAy+Hu7DUkrDxUKrF/RYXZl99mIGLm B+mOxsZfyYhxoi+WJjB3hrF5ovnPz8JwMi66oy3+8d8ljiUfRJxGnNVZK2hxFxhjSCFfh CkHqD/SZXIReq9xrM4I0kJsUZsjQORg4qXI4EzFsSz9n7/p6Rpjt7JID3OL8gwHzfCrsr VPUQzD3jkIciUdDdmgOl9TUCgDCWy0PRhevWcwK8FKbgXL8jYdyGukcz1qhzYOdL86w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796100256; h=DMARC-Filter:Received:Received:DKIM-Signature:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:Content-Language: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=EEY7GR97ijVjh66InHu6zGl/bD534D6M4kr3K4owlXc=; b=zu/hKWl+uBOhwT7tjndS2FnMHyBF49IBNlKpOe00BmFOXL4Zrr7FHJQ/TxtA5q4mIFRQ q0TcCePGSaLtUVnK0ssSNUS+slGGO9HrY191Vs8AGUOUZxP6t5vwgSX+AlcyjChAMuk17 uh0NZlET5GIWsOoCMf3J9tFvUmh9DIabZ3EBpg/BMv396fvNW6B6GDjnICl024qfEeZhv eMR7lFO5Lec6XVxVA0uzjDovCqFAwbsylyvR+zQSXEMBkzYsOruYuTNbsuXFHIFdDhSPX kRaxxdd2vZzWghXVAfcM2t7MF1o6OPv5tCX/KD7Jf2YBusXNetsYeqCjl5v1tZUj/Ew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=a5xrHR63; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 703DF606A31A for ; Tue, 1 Dec 2026 04:44:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 703DF606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=a5xrHR63 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9B70F1595; Mon, 30 Nov 2026 20:44:12 -0800 (PST) Received: from [10.164.148.53] (MacBook-Pro-3.blr.arm.com [10.164.148.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EDDD63F86F; Mon, 30 Nov 2026 20:44:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796100255; bh=DCCBi73ar7cz/+7OvmrHjpJj7bskLpWlQvTKT80REb8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=a5xrHR6336XwDsUa4sJyT0RZ/RmK4awjBEcj+jhZaYYi1bVt6KZ74DwigWHLXPaBt 7+TFkrW25/esyD+sl+4KXvTNN1fz/CKxf9vT0iiDkylgGm8qyMw7UBETJfSn2ci4n9 ta6yw6wgVi7FkIPaqdqIKnV3G6EPXT6GmSAzOdxA= Message-ID: <946b0aef-643a-4751-90d2-15763b84258a@arm.com> Date: Tue, 1 Dec 2026 10:14:09 +0530 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 User-Agent: Mozilla Thunderbird Subject: Re: mm/mprotect: testing a zero-offset fast path To: Chengfeng Lin Cc: Pedro Falcato , Andrew Morton , linux-mm@kvack.org, "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org References: Content-Language: en-US From: Dev Jain In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 30/11/26 2:51 pm, Chengfeng Lin wrote: > Hi Dev, Pedro and all, > > On bare-metal x86 (i7-12700KF), I tested mprotect() with the libMicro > benchmark used by MMTests. Before timing, it writes to a private > /dev/zero mapping to populate its pages. It then changes permissions > between PROT_NONE and PROT_READ | PROT_WRITE in 128 KiB requests. > In a direct-parent / cac1db8c3aad / direct-parent comparison, requests > took 8.1-8.3% longer on the commit than on either parent run. I saw this > both with and without reading each page before removing access. > > To isolate one cost, I kept batching enabled on v7.3 and skipped just the > two pte_advance_pfn() calls in prot_commit_flush_ptes() when idx is zero. > At offset zero the subrange starts at the first PTE, so neither the old > nor the new PTE needs its page frame number adjusted. Nonzero offsets, > protection commits and TLB flush decisions are unchanged. I really don't understand what your objective here is, you have sent two reports in the past as well: https://lore.kernel.org/all/662955ba.f499.19e3b2cf478.Coremail.23020251154299@stu.xmu.edu.cn/ https://lore.kernel.org/all/7c9eeb21.1c04f.19efaacbb2f.Coremail.chengfenglin@stu.xmu.edu.cn/ If there is something we are genuinely missing and is a *real* problem, please explain in brief. It is really difficult to read walls upon walls of text, even more so with all the LLM stuff we are getting, and that I am busy with off-list work so haven't had the time to look at the list as much as I would want to. > > Means of nine uninstrumented runs per arm: > > stock before guard only stock return > libMicro with read-touch, > us per 128 KiB request 2.462113 2.377241 2.456938 > Separate 16-PTE fixture, > ns per NONE + RW round trip 2669.41 2591.66 2676.70 > > The first row averages libMicro's default usecs/call medians from all > nine runs per arm. libMicro filters batches within each run. With -w, > the pages are written before timing. With -t, reading each page before > removing access is part of the timed work. The result is time per > 128 KiB benchmark request, not syscall-only latency. > > Request time fell by 3.45% / 3.24% (about 80-85 ns) versus the before/return > baselines. In separate observations, all 8,192 batch queries returned one > page and all 16,384 PTE advances had offset zero. > > The second row uses another private 128 KiB anonymous mapping, with > 64 KiB multi-size THPs, pinned to CPU 4 and with no page access between > the two calls. I separately verified 16-PTE batches in both directions. > Time per complete round trip fell by 2.91% / 3.18%. These reductions are > for the two tested workloads on v7.3. > > For the native workload I used gormanm/libMicro at > 976d502afaa2d9b919564d7fa8a08fec286dfc89. The single worker was allowed > to run on CPUs 0-19: > > taskset -c 0-19 ./mprotect -E -C 0 -D 30000 -B 10000 -L -S -W \ > -N mprot_tw128k -l 128k -w -t -f /dev/zero > > The v7.3 comparison used this diff: > > --- a/mm/mprotect.c > +++ b/mm/mprotect.c > @@ -127,8 +127,10 @@ static __always_inline void > prot_commit_flush_ptes(struct vm_area_struct *vma, > */ > addr += idx * PAGE_SIZE; > ptep += idx; > - oldpte = pte_advance_pfn(oldpte, idx); > - ptent = pte_advance_pfn(ptent, idx); > + if (idx) { > + oldpte = pte_advance_pfn(oldpte, idx); > + ptent = pte_advance_pfn(ptent, idx); > + } > > if (set_write) > ptent = pte_mkwrite(ptent, vma); > > I checked mainline v7.4-rc5 (fe6ff8d5d675): both advances are still > unconditional. I haven't measured that revision. I'd appreciate your > thoughts on whether this small change looks useful. > > Thanks, > Chengfeng