From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796346307; b=zZaEYshG/qVS3O09C21OOX5kF7VMX5j+5Vwk86BNn4SKqgHzll7W+Ho5iJcwX/D09QRu O1arkwdg7DJWIexlTioeYprPscVNREyFQaemOolEQLs8Hep/0Vhysq5d0mc+WGLB/g6UF QUrvTBvwD8x8+t5bs5IHWotxmVwJiPlx23ZPuPJVAPrDlhyzKyZ8kU2BIqC4tsUilRCqU UResHhb3n4XEjHW5gLuJj2OUKZ+YAu4/BBI1mwPcv5DD1E4cdgnoW0BTggF+1QqL4z0HE 84pSdmZUPMCu2JrpLbFlcnesSTR5gFQUdBwYPWByCA5r8mLwtpbHTSVecjWAHieJvag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796346307; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:Mime-Version:X-Mailer:Message-ID: Subject:From:To:Cc:Content-Type; bh=QDs/OdbheIdE2QKMogprXu0/4ZxmMzb1dUwe2Pzo/II=; b=Xp4GOPlTN1H/aIeuB2b+W7SH8OEHyyN16YtsxtAo0GgeAqL30UU2BXYr/i1iybrlTzOo Ph1yd5fzypPw7lOdwL6wpqp4uK43cGA02NhXHTQ6Efrsy1Xgi7OKEEc+ZBDOMOJt3GP/R i20RWqd/UsrQjVfK8Gv/wRPoDTd+6gAv3VX3k9a+HmkgY6EqEW3tiu4Qyl8WBfoCduCpS tQW1nKwn+rtwAQmA/IH50KDPvDCFkD0NPYLLao9L8fH8tz2TtuDswNFSaPvFofyd9vBve hyDPH0VJYECiMCWCvVWjrUzMcUaiwcNXRXKLcXQuF4giL1dOMMTQ8GiYf8nDE3n+sdg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=GN1J2zjQ; arc=none smtp.remote-ip=74.125.82.71 Received: from mail-dl1-f71.google.com (mail-dl1-f71.google.com [74.125.82.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23728606A332 for ; Fri, 4 Dec 2026 01:05:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 23728606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=GN1J2zjQ Received: by mail-dl1-f71.google.com with SMTP id a92af1059eb24-1b5d5f48795so1742149c88.0 for ; Thu, 03 Dec 2026 17:05:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796346306; x=1796951106; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QDs/OdbheIdE2QKMogprXu0/4ZxmMzb1dUwe2Pzo/II=; b=GN1J2zjQ4GGIDm83lFAGaT+bOQuZmLFAVFAYHfcT1bsyAUy6ZI2sjHA7ZO6JMDWenr ZFvJfh3gBaylJJg7hg0chmsfaCK1U5DpUEfLfFrpKs9Qe8HkpUBy39HI8MBoKk+YBF6T zSPRbvvo3pbK6jR2v2oHj2qkVFiEp3dZMNicuF7VLqySwOk0kPnvwxSkJ/8LHD4B62Zx FQR3dUt0sGLCE7SIXYllP1NWuOzoEkJ65ilSUrtyssLaF2MiXYobTzP8gD07PV3MX246 +AcnDmAENAJmEfct6W4pRbHtmIv/NddxZFBuQNegpNM1RtVRcL66XZYytj9z6z4x9Vgc ErcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796346306; x=1796951106; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QDs/OdbheIdE2QKMogprXu0/4ZxmMzb1dUwe2Pzo/II=; b=vNJFWCbkhQzr8XI1Zg5ZVafQfE/TLAZil/F+RhvDwhb5NqKqovX05mtMberqj6c6kh SeBD2BomU7nroldRVYuhTAAhrbttfEi0W/dQQwtBDudsF2sS33Xzqx7hfeHeheNoA3g8 A9VkbZQRlDFOYuY2kfFPOlr6d6PcfYE8OFf4DanLGtgAA6MnRMKdb0fkCQYmoiXJY0BF 3j8SsZorOBKFvQVTtwRdJ+xtwM57dJ8B+fGmf62aTDGjzDV3r3MDOQFzxyB0QKK34hNQ Rkbkb4a0pxFVKCuMjZLZhf28FlmmFrt+gtX3Bli8Omj+6LuVuBYm8ZgMLRvrnnTT6mam 7zyg== X-Gm-Message-State: APuU4Z/y5/AzJh+Y7nFOXCEsapd5Gt4r3Mt122rRadVME3BWFYZETs0Y eMqA+VbwAt/8H9onXLALfQkhLey8AqwEVomhgYsremFN3WqH8YK37KS9ctJXYTvCETGULFPSQMj WSKIW/E1eiw== X-Received: from dlag3.prod.google.com ([2002:a05:701b:2503:b0:1b5:3561:2fe9]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:281:10b0:1b5:888a:a1a7 with SMTP id a92af1059eb24-1b5d7104e7bmr540008c88.19.1796346305940; Thu, 03 Dec 2026 17:05:05 -0800 (PST) Date: Thu, 3 Dec 2026 17:04:45 -0800 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 X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204010452.1937224-1-irogers@google.com> Subject: [PATCH 0/6] perf synthetic-events: Use PROCMAP_QUERY for mmap synthesis From: Ian Rogers 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 Content-Type: text/plain; charset="UTF-8" Today perf parses the text of /proc//task//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