mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: linux-perf-users@vger.kernel.org, acme@kernel.org, namhyung@kernel.org
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
	mingo@redhat.com,  jolsa@kernel.org, adrian.hunter@intel.com,
	james.clark@linaro.org,  dsahern@gmail.com, andrii@kernel.org,
	Ian Rogers <irogers@google.com>
Subject: [PATCH 0/6] perf synthetic-events: Use PROCMAP_QUERY for mmap synthesis
Date: Thu,  3 Dec 2026 17:04:45 -0800	[thread overview]
Message-ID: <20261204010452.1937224-1-irogers@google.com> (raw)

Today perf parses the text of /proc/<pid>/task/<pid>/maps and, for
each file backed mapping missing from the DSO cache, opens and parses
the ELF file, within the process' mount namespace, for its build ID.
PROCMAP_QUERY (Linux 6.11+) returns each VMA in binary form, can
filter VMAs by permission in the kernel, and returns the build ID read
by the kernel from the mapped file. This works for deleted binaries
and binaries in other mount namespaces, where perf currently gets no
build ID.

While PROCMAP_QUERY was being developed, Andrii Nakryiko prototyped
using it for perf's mmap synthesis and measured it with 'perf bench
internals synthesize', finding it slightly faster than parsing the
text, but the perf change wasn't posted for inclusion [1][2]. This
series differs in letting the kernel filter VMAs, in getting build IDs
from the kernel, as build IDs in synthesized MMAP2 events have since
become the default, and in fixing the benchmark, which was failing to
read build IDs (patch 3).

[1] https://lore.kernel.org/all/CAEf4BzbdGJzMuRgGJE72VFquXL37rS9Ti__wx4f_+kt3yetkEg@mail.gmail.com/
[2] https://github.com/anakryiko/linux/commit/0841fe675ed30f5605c5b228e18f5612ea253b35

The series is based on perf-tools-next.

Patches 1 and 2 fix pre-existing bugs found by the Sashiko AI review
tool when reviewing an earlier version of this series. Patch 1 fixes a
leak in __machine__new_host() when creating the kernel maps fails.
Patch 2 fixes a data race on DSO build IDs when several threads
synthesize events, by reading and setting the build ID with the dsos
lock held, as lookups that compare DSO ids already do. ThreadSanitizer
reported 8 races on the build ID in 'perf bench internals synthesize
-t -m 8 -M 8' before the fix and none after it.

Patch 3 fixes 'perf bench internals synthesize', which never called
symbol__init() so every build ID read failed and the DSO cache never
worked, making the benchmark ~15x slower than real synthesis.

Patch 4 adds the PROCMAP_QUERY path. Without data mmaps the kernel
returns only executable VMAs. With data mmaps (readable or executable
VMAs are wanted) a first pass gets readable VMAs, skipping guard pages,
and a second pass gets executable VMAs that aren't readable, such as
execute-only memory. The DSO cache is consulted first (keyed by
device/inode as before), and only on a miss is the VMA queried again
for the kernel to read the build ID, so each file's build ID is read
once. If the kernel can't give a build ID, the file is read as before,
with the existing nsinfo handling; no nsinfo or mount namespace work
is done when the kernel or DSO cache provides the build ID. The text
parser remains as a fallback when the ioctl isn't supported (probed
once with pthread_once()) or the first query fails. Shared code is in
a helper so both paths emit identical events.

Patch 5 adds a 'perf bench internals synthesize --[no-]procmap-query'
option and a core.procmap-query config option to allow comparison.

Patch 6 adds a perf test that synthesizes the test process' mmaps both
ways and checks the MMAP2 events are byte for byte identical, with and
without build IDs and data mmaps, including an execute-only mapping.

Results on an Intel Core i7-14700, 7.1 kernel (usec, lower is better).

 Single threaded, perf process, warm DSO cache, pinned to a CPU,
 min / median of 10 interleaved runs:
                        text              PROCMAP_QUERY
   exec mmaps only    249.2 /  258.8      172.2 /  177.2   (-32%)
   with data mmaps   1458.3 / 1621.8     1631.5 / 1726.2   (+6%)

 System wide ('-t -m 1 -M 4', ~32,000 events, unprivileged), cold
 DSO cache as at the start of 'perf record -a', min / median of 3
 runs:
   threads              text              PROCMAP_QUERY
     1               301943 / 302766     161624 / 164009   (-46%)
     2               184631 / 187061     112002 / 115959   (-38%)
     3               240013 / 240291     136163 / 215740
     4               133571 / 139586      92270 /  95234   (-32%)

The 3 thread PROCMAP_QUERY median is skewed by two noisy runs; by the
minimum it is 43% faster.

PROCMAP_QUERY is not a win everywhere: with data mmaps and a warm DSO
cache, one ioctl per readable VMA is slightly slower than formatting
and parsing the text. Splitting data mmap synthesis into the readable
and execute-only passes avoids querying the ~22% of VMAs that are
inaccessible guards, cutting the ioctls when walking every process on
the test machine by 13%, but the time only improved by about 1% as
those VMAs have no name and are cheap to query. The benefit for
executable mmaps, the default for 'perf record', comes from the kernel
filtering VMAs and from not opening ELF files.

Recording with and without core.procmap-query on 'sleep' and a
python3 process with many libraries, with and without -d, gave
identical mmap events in 'perf script --show-mmap-events'. For a
process running a deleted binary, PROCMAP_QUERY gave the build ID
where the text path only had the device/inode.

Known difference: the gate VMA ([vsyscall] on x86-64, [vectors] on
32-bit ARM) isn't in the VMA tree, so no map is synthesized for it.
No symbols were ever resolved for it, as it has no backing file, and
samples there are now shown as [unknown] rather than [vsyscall] or
[vectors]. The kernel never emits an MMAP2 event for the gate VMA, so
processes started during recording already lacked it; PROCMAP_QUERY
makes pre-existing processes consistent with them.

Tools used: the code, tests and changelogs in this series were
initially written by an AI coding assistant (Gemini in Jetski)
from prompts describing the goal above, and were then reviewed,
built (GCC and clang), tested ('perf test', the new equivalence
test, 'perf record'/'perf script' comparisons) and benchmarked by
me.

Ian Rogers (6):
  perf machine: Fix leak when creating host kernel maps fails
  perf synthetic-events: Fix race on DSO build IDs when synthesizing
  perf bench synthesize: Initialize symbols so build IDs can be read
  perf synthetic-events: Use PROCMAP_QUERY to synthesize mmap events
  perf bench synthesize: Add --procmap-query option
  perf test: Add test comparing PROCMAP_QUERY and /proc/pid/maps
    synthesis

 tools/perf/Documentation/perf-bench.txt  |   4 +-
 tools/perf/Documentation/perf-config.txt |   5 +
 tools/perf/bench/synthesize.c            |  58 ++-
 tools/perf/tests/Build                   |   1 +
 tools/perf/tests/builtin-test.c          |   1 +
 tools/perf/tests/synthesize-mmap.c       | 275 ++++++++++++
 tools/perf/tests/tests.h                 |   1 +
 tools/perf/util/config.c                 |   4 +
 tools/perf/util/dsos.c                   |  38 +-
 tools/perf/util/dsos.h                   |   4 +
 tools/perf/util/machine.c                |   2 +-
 tools/perf/util/synthetic-events.c       | 539 ++++++++++++++++++-----
 tools/perf/util/synthetic-events.h       |   6 +
 13 files changed, 808 insertions(+), 130 deletions(-)
 create mode 100644 tools/perf/tests/synthesize-mmap.c


base-commit: 22f7d78dc87e43ff4f7c03d23f46f49692c41ad0
-- 
2.56.1.915.g69d5ec7298-goog


             reply	other threads:[~2026-12-04  1:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  1:04 Ian Rogers [this message]
2026-12-04  1:04 ` [PATCH 1/6] perf machine: Fix leak when creating host kernel maps fails Ian Rogers
2026-12-04  1:04 ` [PATCH 2/6] perf synthetic-events: Fix race on DSO build IDs when synthesizing Ian Rogers
2026-12-04  1:04 ` [PATCH 3/6] perf bench synthesize: Initialize symbols so build IDs can be read Ian Rogers
2026-12-04  1:04 ` [PATCH 4/6] perf synthetic-events: Use PROCMAP_QUERY to synthesize mmap events Ian Rogers
2026-12-04  1:04 ` [PATCH 5/6] perf bench synthesize: Add --procmap-query option Ian Rogers
2026-12-04  1:04 ` [PATCH 6/6] perf test: Add test comparing PROCMAP_QUERY and /proc/pid/maps synthesis Ian Rogers

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=20261204010452.1937224-1-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=andrii@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®