From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796417940; b=NBVuKkGDK2OQYg1KMBhettBvC+0872xVog3jzglF4FeN2iOASNE4il7IdZrGY1T2GBKm T2CcqOGy4LRJEpj6FEDXeLtxCFc8VYsRcwmwdkUILjeI77IhvoBZ5IGV8TpDGbjPLeJVb hsZY/9B2Z+edIIvbLcHMuuEtIVA98i+8bAqDP3UTzxUFVg9wP7xsW+bGsKX2VVt9b2fda vR5dDmFLWMCHCGha0+katqejrpSiDL7VqSGVzc2bqFQoornJD1KVxGCBfAyyHy5HhM68H sx7dMx7i5X6ZoGcnQC+BmjVqzhpdoG4k3D4nT4k+BxZlcxLTnjX8nKHztE3wAAwodJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796417940; 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=zCB2Kz3hfK8kZjITkKACoL5P1yIX1lEIBRfJ9IzBcKg=; b=WIFNkK+0E4wHAOFZVwwXb4V8zt5uBcJ1pWjJOjXaHm/GcliZJkuNI6rWciCjGcdl9cVq vo3VAKR168KHrm3f7FNXjfAcLWkmHJHQAsE79BCMffnCLC+bRZ1juDmCGfZnclGyH/xhm TBJ1/RNl8jwbdT56ORJ03hMbl4Ik895s2oBxUrEa/hzV2XPJgdCVgEbcXdMwGIitQegCx 7Aix9wiSFuKyDvsVTyZCaY/Lh/+ZHGtpmBbYI5UG7IYPVUmb1nnZRwDsTMezkKygCNQK5 5sTandjPenmzpFuPk6i2F8OhLj0vRU90Rxi1WFIK/142tfiF/b/vVcng0tI0KvMx+uA== 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="AB+XP/+7"; arc=none smtp.remote-ip=74.125.82.199 Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) (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 8C201606A322 for ; Fri, 4 Dec 2026 20:58:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8C201606A322 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=AB+XP/+7 Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-3869865a304so4189005eec.0 for ; Fri, 04 Dec 2026 12:58:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796417939; x=1797022739; 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=zCB2Kz3hfK8kZjITkKACoL5P1yIX1lEIBRfJ9IzBcKg=; b=AB+XP/+7kB3dLlqZ0t5CpEVAJqJWKwzqq59ckk8Q2cVo27hlBZu2N/iGTRUiL7a3n7 TkkV/x+ha0Bkwwgo5mR+2dkshcw/AIBXoHsdjNd2+1QffTWl7ngPeFyShBSLlZUp6xkY swG8Jx3gBT5Lmml44jHqjq3CfqdBjyfr9lQpJPHJK56AaG8Xo2AipRvyI7MY/3N74UKb OxyNVQeQRcQmvHeNBs8AVNTTMtSXfdpKw8HNYmFI7Tvx5TotUlRGJCdOMV87R3lfvUFS dxvAkyWprQ3a7XfAnNwqmplNAny/9e4JmBf9ipAvnBL8EY4AifbiuA790fPb9aElJk0Y mFDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796417939; x=1797022739; 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=zCB2Kz3hfK8kZjITkKACoL5P1yIX1lEIBRfJ9IzBcKg=; b=X8pUl1KACA/T6K9wl7xwh7pQ2v73fgR8X4fQL20hJyymFCPgDNzaV5s/Egb5rT6UCf hprfzNXy6jABBob3/6OGKL7gr4eczZN9t3TjtR5ZQ5+ChpP9TqCyw0KiDfFRlyvYgIOI p4bUFpibYR695zSg4PbW0HEGc6dVruu+8JVC5+6vpghP9dJSOqQ2dTvpG254fk+3Ki0m A5D++t175/KQwUOD8/w2nINaQ00uNDXqWsqF4O9whUo9pCVt9KV2Zq9pyb3aRvgz+hcB 9OvoGRotbsYjek21mQP02adVbsA3QRasZxnurBgrA3h4YmW+woGdvOj+/jxI0OmURlzU 73Bw== X-Gm-Message-State: AB4q+uF8AwBH9bUxVRaQQEyXk1LhvKWMmn6am2JTW6eNwEMUoynlMbOy Oixj0jHVlWZ/ORpYlG10E+R06+p+6LMpY995fnbBJvFBhmaU05DEaKRgLCTB9gnn6f8yCdGEJ2W mJy5W7QuVZ4TxWu+Jg8evZvfbgiy7XsUdygRmZDBc6lv6IgFMKOx526wecr/COSB5xLQxspzk9D RdUDldNUj+txmIfrtco/2+XlWcwduT2n+eEg71G0TeZFtpUioEODBoVgw= X-Received: from dyu28.prod.google.com ([2002:a05:693c:811c:b0:386:9d73:d06d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:41d8:b0:387:4d80:eebf with SMTP id 5a478bee46e88-38751fc92a7mr3057837eec.5.1796417938275; Fri, 04 Dec 2026 12:58:58 -0800 (PST) Date: Fri, 4 Dec 2026 12:58:46 -0800 X-Mailing-List: linux-perf-users@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: <20261204205854.3973609-1-irogers@google.com> Subject: [PATCH v4 0/7] perf synthetic-events: Use PROCMAP_QUERY for mmap synthesis From: Ian Rogers To: linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, 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+, used here on Linux 6.19+) 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 synchronizes tools/include/uapi/linux/fs.h with include/uapi/linux/fs.h and tracks it in tools/perf/check-headers.sh. Patch 5 adds the PROCMAP_QUERY path, gated on Linux 6.19+ so both per-VMA locks (6.18) and safe __kernel_read() build ID reads (6.19) are present. 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 on kernels older than 6.19, when the ioctl isn't supported (probed once with pthread_once()), or when the first query fails. Shared code is in a helper so both paths emit identical events. Patch 6 adds a 'perf bench internals synthesize --[no-]procmap-query' option, a core.procmap-query config option to allow comparison, and exports perf_event__procmap_query_supported(). Patch 7 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 P-core CPU, min / median of 10 interleaved runs: text PROCMAP_QUERY exec mmaps only 254.1 / 256.9 171.1 / 173.5 (-32%) with data mmaps 1513.4 / 1618.1 1667.8 / 1749.1 (+8%) System wide ('-t -m 1 -M 4', ~24,000 events, unprivileged), cold DSO cache as at the start of 'perf record -a', min / median of 5 interleaved runs: threads text PROCMAP_QUERY 1 243754 / 246155 124929 / 126336 (-49%) 2 139272 / 143913 79233 / 80165 (-44%) 3 207429 / 209567 93290 / 94799 (-55%) 4 123863 / 123989 59701 / 62360 (-50%) 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 Antigravity) 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. v4: - Address Sashiko AI review feedback on v3 [5]: - Gate all PROCMAP_QUERY synthesis (not just build ID queries) on Linux 6.19+ in procmap_query__probe(), avoiding both the data-mmap regression without kernel build IDs on 6.11-6.18 and the mmap_lock contention regression on 6.17 (where text maps had per-VMA locks via commit 5631da56c9a8 before PROCMAP_QUERY gained them in 6.18 via commit d9d1c2d81797). - Export perf_event__procmap_query_supported() in patch 6 so 'perf bench internals synthesize' prints the actual mode and patch 7's test reuses the same probe rather than duplicating it. v3: - Address Sashiko AI review feedback on v2 [4]: - Add patch 4 synchronizing tools/include/uapi/linux/fs.h with include/uapi/linux/fs.h and tracking it in tools/perf/check-headers.sh; fix the include comment and commit message in patch 5. - Gate kernel PROCMAP_QUERY build ID queries on Linux 6.19+ (checked via uname() in procmap_query__probe()) so perf never triggers a kernel NULL pointer dereference in filemap_read_folio() on 6.11-6.18 kernels lacking commit 777a8560fd29 for mappings without ->read_folio (such as tmpfs, shmem, hugetlbfs, dma-buf, or devices). - Tighten procmap_query__skip_build_id() to also skip /dev/shm/, /memfd:, /dmabuf:, /anon_hugepage, /SYSV, and /[ pseudo-paths on 6.19+ kernels. v2: - Address Sashiko AI review feedback on patch 4 [3]: - Skip device nodes (except /dev/shm), pseudo-filesystems (/sys, /proc), and other visible non-regular files before asking the kernel for a build ID, avoiding __kernel_read() warnings on device files and a kernel NULL pointer dereference on 6.11-6.18 kernels lacking commit 777a8560fd29. - Keep addr non-decreasing when retrying Pass 2 queries for VMA names (and guard against non-advancing vma_end) to prevent an infinite loop if a target concurrently mprotect()s a VMA prefix. - Check --proc-map-timeout while skipping readable VMAs in Pass 2 so timeout warnings and PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT are still emitted. [3] https://lore.kernel.org/linux-perf-users/20261204010452.1937224-1-irogers@google.com/ [4] https://lore.kernel.org/linux-perf-users/20261204045948.2254888-1-irogers@google.com/ [5] https://lore.kernel.org/linux-perf-users/20261204062328.2508164-1-irogers@google.com/ Ian Rogers (7): 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 tools headers UAPI: Synchronize linux/fs.h with the kernel sources 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/include/uapi/linux/fs.h | 137 ++++- tools/perf/Documentation/perf-bench.txt | 4 +- tools/perf/Documentation/perf-config.txt | 6 + tools/perf/bench/synthesize.c | 59 ++- tools/perf/check-headers.sh | 1 + tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/synthesize-mmap.c | 257 ++++++++++ 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 | 610 +++++++++++++++++++---- tools/perf/util/synthetic-events.h | 7 + 15 files changed, 993 insertions(+), 139 deletions(-) create mode 100644 tools/perf/tests/synthesize-mmap.c base-commit: 22f7d78dc87e43ff4f7c03d23f46f49692c41ad0 -- 2.56.1.915.g69d5ec7298-goog