From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4828606A32A for ; Mon, 30 Nov 2026 16:08:57 +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=FXEohg8n Received: by kanga.kvack.org (Postfix) id 82AE76B05B4; Mon, 30 Nov 2026 11:08:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B3AA6B05B5; Mon, 30 Nov 2026 11:08:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A1BF6B05BC; Mon, 30 Nov 2026 11:08:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3B52C6B05B4 for ; Mon, 30 Nov 2026 11:08:56 -0500 (EST) Received: from smtpin07.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2BBC01A0A5C for ; Mon, 30 Nov 2026 16:08:55 +0000 (UTC) X-FDA: 85492269030.07.83C8335 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf28.hostedemail.com (Postfix) with ESMTP id 65C7DC001A for ; Mon, 30 Nov 2026 16:08:53 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=FXEohg8n; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of ljs@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=ljs@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796054933; b=mgzd19vQSrPwCiTHtPgCp3CuMabyyxZFx6wxO2Gj66OMA3/dX+UwZ6+DfxiNO+anjtLy/7 RVkPlPe27rL2wF4JdqVgtHoyx7SWfZ1nRvc5ctZ+6YeYnnBJFkAkpdrtT68L8z07OGVZsf KpFq1BZTyTg9zLr8SCsZrvsTYC6TUuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796054933; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=H1t0GagVsJlXR3dOtoBWZ9OlqRpixauiZCPGOv5c0/E=; b=7B6EQ5aIPk+yfsD4SrkRGpXgRHXoMwyUSeINIdc/ewKjpEF3Vh6b2VX+uqj/A144PYFoKP bngDWi1FMHAtrigQo/3dygygbyB1YaWKRDhAWwV2f6KLIW8p1I0qF/ITqA08IKFvdy9Dc5 FaTRTXCvEp8i4MxvLGK9sBka/GF70X4= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=FXEohg8n; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of ljs@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=ljs@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id D815061ECC; Mon, 30 Nov 2026 16:08:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A92981F00896; Mon, 30 Nov 2026 16:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796054932; bh=H1t0GagVsJlXR3dOtoBWZ9OlqRpixauiZCPGOv5c0/E=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=FXEohg8n+6cEHiiOrNK3DXrNXqwoShBPU/UbgDjqMKi4iksy88rWbAIlWviMc+KOc 1s5veZ+zmnpmLz/E7uBe/rrCP/0NadAQddtTIrwJpTekE91fg60x7pbOrJjGtpDQQr ySyArWioeU8e+eTID9r1NqPWTcIKTgSSX3MTZIEs5j/9Gm0//yxHAZC/J6nEdWlmel L/8h9rN7Idgs5Y+JhB1Hu3WV+iVNdvyA1zqFagYC+AH59/PyA77Uqcj3i3vsRwVJjR 3iBcSfVPJi53wyVMToAQzW84xMnJrfLiLuzQlRvRtnSaWVPDJcQJ7jF8S5DEJiAckQ yl3vMX3pOOnlg== Date: Mon, 30 Nov 2026 16:08:46 +0000 From: "Lorenzo Stoakes (ARM)" To: Chengfeng Lin Cc: Dev Jain , Pedro Falcato , Andrew Morton , linux-mm@kvack.org, "Liam R. Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org Subject: Re: mm/mprotect: testing a zero-offset fast path Message-ID: References: X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 65C7DC001A X-Rspam-User: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Stat-Signature: buye4quxdizxowopdigtpe6nqzp4xw5n X-HE-Tag: 1796054933-842358 X-HE-Meta: U2FsdGVkX197XCck4fJNqHwBgyEqRhnXfwFx2NoMZsPFY0k5l7dRsionSR9q3ZkgN/y/7prrbUV54pw+Sp0XDd6CcvkcfbAp1md0jcXCTKeNDYSe/g3lKXnStL0yyxVa0O4AZO43Hy9W5mUCy72z+aWUH9NXpGSYRNDqY1cd+VQSSTt/POCaLNkjr3/UPDqoGFM1TIBGIeCuoK91qHYyHG3QWU48qV0/sGsSxeehD8tI7+cnwKMveH1RiWu5k7RD9yWyZFN+z/JMnK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n4Wxw1EjMptOPddE7CBuas5U39aknH9YaN573kSB+nwbagxOONz585FolrMbKI9x1FxZIw4eB1wHAxrx7C0KInmSM0NhAqjp0teWrMjms/z1i8MeVzh Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Mon, Nov 30, 2026 at 05:21:47PM +0800, 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. > > 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. Is this an RFC or a proposed patch or what is it? I'm a little confused as to what real-world this impacts, and why we would want it? It seems like a microbenchmark-based thing that just adds complexity no? > > Thanks, > Chengfeng -- Cheers, Lorenzo