From: Peter Zijlstra <peterz@infradead.org>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Andrew Morton <akpm@linux-foundation.org>,
"David Hildenbrand (Arm)" <david@kernel.org>,
"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
bpf@vger.kernel.org, regressions@lists.linux.dev,
Sasha Levin <sashal@kernel.org>,
Alexander Motin <alexander.motin@truenas.com>,
Ameer Hamza <ameer.hamza@truenas.com>,
"Caleb St. John" <caleb.stjohn@truenas.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] perf/core: track the perf mlock gift separately
Date: Thu, 15 Oct 2026 09:58:17 +0200 [thread overview]
Message-ID: <20261015075817.GO2009045@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20261003-perf-locked-vm-fix-v1-1-d214dcaf0d76@kernel.org>
On Sat, Oct 03, 2026 at 05:29:07PM +0100, Lorenzo Stoakes (ARM) wrote:
> The locked_vm field in struct user_struct was originally introduced by
> commit 789f90fcf6b0 ("perf_counter: per user mlock gift") to provide an
> mlock-like budget for perf measured against mm->pinned_vm (since 2011).
>
> perf grants each user a 'gift' of perf_event_mlock_kb * online CPUs of
> buffer pages which is charged to user->locked_vm without any RLIMIT_MEMLOCK
> check.
>
> Only pages beyond the gift are checked against RLIMIT_MEMLOCK, per-mm, via
> mm->pinned_vm, which makes it different from the standard mlock() check,
> which is per-mm and made against RLIMIT_MEMLOCK.
>
> However, since this was introduced, a number of other components have
> utilised this field where a shared resource needed to be limited against
> RLIMIT_MEMLOCK.
>
> The other users are currently MSG_ZEROCOPY, io_uring, AF_XDP, iommufd,
> s390 KVM zPCI and most recently, secretmem in commit 97d34aa65c29
> ("mm/secretmem: properly account locked pages").
>
> This field is shared between all of these, but because the gift is not
> checked against RLIMIT_MEMLOCK, user->locked_vm alone can exceed it - 16
> CPUs * 516 KiB is already more than the default 8 MiB - after which every
> other user of the field fails unconditionally.
>
> This was reported by a user who saw secretmem failing while running a
> simultaneous perf record.
>
> Resolve the issue by simply giving perf its own field separate from the
> rest.
So I'm a little confused by all this -- perf introduced this field,
others jumped on and shit broke, so we fix perf instead of the others?
> BPF used user->locked_vm up until commit 80ee81e0403c ("bpf: Eliminate
> rlimit-based memory accounting infra for bpf maps") which landed in 5.11.
>
> Thus also eliminate the now-defunct ifdef for CONFIG_BPF_SYSCALL for
> user->locked_vm.
>
> This issue exists between all of the components which use user->locked_vm
> and perf, however secretmem is the first user who has caused a report over
> many years and has been backported, so target the fix at that.
>
> Fixes: 97d34aa65c29 ("mm/secretmem: properly account locked pages")
> Reported-by: Ameer Hamza <ameer.hamza@truenas.com>
> Closes: https://lore.kernel.org/20261002175651.811343-1-ameer.hamza@truenas.com
> Cc: stable@vger.kernel.org
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Anyway, patch seems straight forward enough; and you added comment to
the fields, which I suppose does clarify things some.
I'll take it. Thanks!
next prev parent reply other threads:[~2026-10-15 7:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-03 16:29 [PATCH] perf/core: track the perf mlock gift separately Lorenzo Stoakes (ARM)
2026-10-03 17:56 ` sashiko-bot
2026-10-15 7:58 ` Peter Zijlstra [this message]
2026-10-15 9:09 ` Lorenzo Stoakes (ARM)
2026-10-15 9:27 ` Thorsten Leemhuis
2026-10-15 10:40 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261015075817.GO2009045@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.motin@truenas.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=ameer.hamza@truenas.com \
--cc=bpf@vger.kernel.org \
--cc=caleb.stjohn@truenas.com \
--cc=david@kernel.org \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=regressions@lists.linux.dev \
--cc=rppt@kernel.org \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.