From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0C16C340298 for ; Mon, 23 Mar 2026 12:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774270592; cv=none; b=e76osfkmauoSAs4XemAZukedkFWKvaqCG0dFs5ZWBAuMUQSb1wEB3T7f50fpOM0+++KibfuvtkQ7cC7SuPiy5uG/smoyGs29uA7haHap1kyBrGs69iur1+bcvSJgz5oQVfEXM03fCWv6B6mGY3WGpzQj6ShOY02NuqhPVu4W8go= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774270592; c=relaxed/simple; bh=56CvIhSJvJpbCTYN4/Ac/8swe6dujoF1iEBmLn1Suho=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=GyEWXs3dhfNZLSYRa74CVnYuwn4fgpDdnoj+YQtxC3qx06dwoB8eP95qKzb+5j/SH+eVY5wqq8WeVEQAQxXdC1mo90iiNfBXbz/v4r9fSD+vDoJam3AQGF5UKIff+pCFROAjJfS5xrqlGc3UQEdAxHGb/yUDxaTrsiWqsPK+0hA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tDXj1FN6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tDXj1FN6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D61EDC4CEF7; Mon, 23 Mar 2026 12:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774270591; bh=56CvIhSJvJpbCTYN4/Ac/8swe6dujoF1iEBmLn1Suho=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=tDXj1FN63tJSJrZckQn4KKWIfOSfqhJV5nlLOeyGyLaZyXXFMK9KcXhm8Ym2aYBE7 7JaqE0hzaqCqs30f52+MZiiBiwxSSejiUGMGLd59rDDbEIKFTn9xqMNx74L4iP5ksj 4+ZUcK4esFgzVBXGiI0ZarGayJpdIbHCAUTG4aYhu1edbEt190EUsX1JXpVx17Tyke i1X7Mg9U3pRsl/ftGkzPCB8CeCPJ9DqkZUMXse5HrTKjeXUfaQRlk0oeP4Z5qF3VIp dhUkRarIfTC8FBfUQ+BQtJbP/u0hLaWCP1gRzGLMh4POih+m8f2YVETHZuvyUC6rC5 DPE6D1Zmrhv+Q== Message-ID: Date: Mon, 23 Mar 2026 13:56:27 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/4] mm/mprotect: un-inline folio_pte_batch_flags() To: "Lorenzo Stoakes (Oracle)" Cc: Pedro Falcato , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Jann Horn , Dev Jain , Luke Yang , jhladky@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260319183108.1105090-1-pfalcato@suse.de> <20260319183108.1105090-4-pfalcato@suse.de> <2da1181c-165d-49cd-94cb-5ccbd3bb93b3@lucifer.local> <69382383-5f08-408f-8c13-d674e82c4dfd@kernel.org> <9b0aaa19-b839-4ebb-a312-097b869154c1@kernel.org> <11929205-d0dd-4e8f-8a99-2d0b02cfd5bd@lucifer.local> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOi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6x2rHyc8Sl86oK1tvAkwBNsfKou3v+jP/l14a7DGBvrmlYjO 59o3t6inu6H7pt7OL6u6BQj7DoMAEQEAAcLBfAQYAQgAJgIbDBYhBBvZyq1zXEw6Rg38yk3e EPcA/4NaBQJonNqrBQkmWAihAAoJEE3eEPcA/4NaKtMQALAJ8PzprBEXbXcEXwDKQu+P/vts IfUb1UNMfMV76BicGa5NCZnJNQASDP/+bFg6O3gx5NbhHHPeaWz/VxlOmYHokHodOvtL0WCC 8A5PEP8tOk6029Z+J+xUcMrJClNVFpzVvOpb1lCbhjwAV465Hy+NUSbbUiRxdzNQtLtgZzOV Zw7jxUCs4UUZLQTCuBpFgb15bBxYZ/BL9MbzxPxvfUQIPbnzQMcqtpUs21CMK2PdfCh5c4gS sDci6D5/ZIBw94UQWmGpM/O1ilGXde2ZzzGYl64glmccD8e87OnEgKnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: <11929205-d0dd-4e8f-8a99-2d0b02cfd5bd@lucifer.local> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit >>> I mean yeah that's a terrible name so obviously it'd have to be something >>> better. >>> >>> But again, this seems pretty stupid, now we're writing a bunch of duplicate >>> per-case code to force noinline because we made the central function inline >>> no? >>> >>> That's also super fragile, because an engineer might later decide that >>> pattern is horrible and fix it, and we regress this. >>> >>> But I mean overall, is the perf here really all that important? Are people >>> really that dependent on mprotect() et al. performing brilliantly fast? >> >> For basic primitives like mprotect/zap/fork I think yes. For other stuff >> like rmap.c, maybe not. > > Well on big ranges of mprotect() it could be, and I know often databases > like to do this kind of thing potentially, so yeah sure. > > But more so the microbenchmark stuff of *a million protect() invocations* > is not something to optimise for so much. > > Rather I'd say mprotect() over larger ranges is what we should look to. I tend to agree (and I think I made a similar point in previous discussions around mprotect() performance). There is the use case for userspace jits etc to call mprotect() on individual pages. I suspected that TLB flushing and syscall overhead would overshadow most micro-optimizations. :) [...] > > As I've said to Pedro elsewhere here, I guess my concern is nuanced: > > So if we introduce stuff like carefully chosen __always_inline or noinline > or other things that have characteristics like: > > - They're beneficial for the code AS-IS. > - They're based on compiler codegen that can easily be altered by other > changes. > - It is not obvious how other changes to the code might break them. > > We are asking for trouble - because people WILL change that code and WILL > break that, OR a possibly worse outcome - something like a noinline sticks > around when it makes sense, but everybody's scared to remove it + _doesn't > know why it's there_ - so it becomes a part of 'oh yeah we don't touch > that' lore that exists for a lot of 'weird' stuff in the kernel. > > Then it might end up actually _worsening_ the performance in future > accidentally because nobody dare touch it. > > Or another hellish future is one in which such things cause bot perf > regression reports for otherwise fine series, on microoptimisations we're > not even clear matter, and cause developers to have to spend hours figuring > out how to avoid them, meanwhile potentially making it even more difficult > to understand why the code is the way it is. > > So what is the solution? > > 1. Focus on the changes that are NOT brittle like this, e.g. special casing > order-0 is fine, adding profile/benchmark-proven likely()/unlikely(), > etc. - these are not things that have the above characteristics and are > just wins. Agreed. > > 2. For cases where things MIGHT have the characteristics listed above, > avoid the issue by abstracting it as much as possible, adding lengthily > comments and making it as hard as possible to screw it up/misunderstand > it. Agreed. > > 3. Often times perf issues coming up might be an indication that the > underlying mechanism is itself not well abstracted/already adding > unnecessary complexity that manifests in perf issues, so in that case - > rework first. Agreed. I think the usage of noinline for micro-performance optimization is really questionable and should be avoided at all costs. The folio_pte_patch() stuff likely really should just be a set of mm/util.c helpers that specialize on the flags only to make the inner loop as efficient as possible. -- Cheers, David