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=1796054933; b=qB6ungQbjghyr3dGiMCDF1uvd3Q79kNQKIkphIVmIM/1c5tq1j+UicTnnEg4zR7FuM4K dLUMoV8vUnb7zUqdYGqA09yw96oAdvzB5TsDBr/W5YKyfpIim77X6v5WNeZqjGbp47I8i xEQjbiI6s7oOOqzyStoW9jpBBJx/a6PgszQp8W1jczjjE/LgHLHwB19tdSYNh3sXtVuEc OQrAQPUbZvEIJvvkkPIpgAafKg9nxkFRqT3H/fjPXAs/PGWWT9Cu10KZFWIaerHeqdopG AgpkM2jREZTNdfIaRsodcPPV8f8r3G1fp5p42hcGi85sXdneKupwOrKlapBlTRcYg7w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796054933; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=H1t0GagVsJlXR3dOtoBWZ9OlqRpixauiZCPGOv5c0/E=; b=zGZJQcZyAjPgeJPaxB9z2NszlUpjoaAQnpyePRaqv9brK5Rc15ngM+8e3NOJVtWjZzoN 10zWB2IqFrWguM+ouepUtCYGNKdFfRAsqjrA/5QcQgqUHiLrfF00wf+CBRxwimBCOExVy pOoN/809xqAn5Of2/KIZGsam6PUoLTh7LmgfuAnlTWhlxApH1ZeoJKDBKW8FNwFgK4L1M 0IThBV5X9wgFk+oLe44eplxzIrt6Pqw+Aib8BIQk9j2LIr6PgsKFrjhbZj1iKm8chtYqG IqEF4D3sSv5ax6LpnS1q/tOklMfephu8SOnsUzS0+QCONaxGnrIHWWNWTN5ybEwoxjA== 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=FXEohg8n; 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 E7955606A31C for ; Mon, 30 Nov 2026 16:08:52 +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 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-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: 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