From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796365413; b=V5vZifENQTRvaJ3zaAp0+nTsL4KeQCEIkPKCUArQ29PEKxXx3LMSUXI+nGwPlfRO3nIx M6Df4z0hJ3yEM5AV+k4mYR9JOHZt4YgmuhAw64di3wyd9jeTxDr3ANqudUASHbFbgqrt3 MrzgE7G5TkbhLe6+/mIlFjdbNOcRIsrDpg90JRDUsQSvsk+fW59wP0uX8QQthu3zLdBDe MQq1sCZn86O8l60JnTt5PprqYEeJsLcMrwiAjJbIK8uZPXfvqN4Ykf5SxOBvKHT4cB689 yABmGedGMaIvxvacbDfG3Djg5qeq+F5tSu91ANbseyo5aa7U5lK7mS0BRyie3ABi5sQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796365413; 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=k9c7bg72OKyVZ3OhoXoOY3vbidMAwokU/eHErpCeRb0=; b=PtYV0AE8hd8f8D1wVZiRT8ml+qPtOcg7uz5Y1ZIm8PtmQAOLAZs9EvhMVToo26o9PHeC 0V1stmEkK+p5uSS0eJVg6W7/IFm0NUSMOzl1HNS5ZCAPymTz99ZMEbPqId5E5U0lIh29y dlEohY0IL4tec4k5g6FtvP6GbS1F4Fc3NSRg5yt3tjLvQ21uEq2rKEnwmjvO0kP+PD5RZ ugMZjHH7Edodbd1IzmFlCD42IqVe+Q7AFoE9Hz0pxxiLXnH1NoZ++CJ8rV1M1ynCkhJ0m bQ6N7IPnVFR9jhC/igfNI2XLKf2aioO0K+droAxamcPBVfEltbc05btd+JdSfINQ8Kg== 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="K7Q/wdxp"; arc=none smtp.remote-ip=74.125.82.69 Received: from mail-dl1-f69.google.com (mail-dl1-f69.google.com [74.125.82.69]) (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 99E2F606A32C for ; Fri, 4 Dec 2026 06:23:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 99E2F606A32C 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=K7Q/wdxp Received: by mail-dl1-f69.google.com with SMTP id a92af1059eb24-1b56c696405so1829214c88.1 for ; Thu, 03 Dec 2026 22:23:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796365412; x=1796970212; 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=k9c7bg72OKyVZ3OhoXoOY3vbidMAwokU/eHErpCeRb0=; b=K7Q/wdxp7DmLQJ1gHtl8K+xyiCFMGQnR5unHsz0gtLV6iuAHMamGn6eFb4PBMYjbs6 8LEgHtdtFdAWIRW176ZpXEhoIdNg9JRBjP5luPTVToNChBNL0suIZb6yUck5WFnbJ+aR +4bLSfeU2wi5MNFc+Zp/zGKPUbwRnCpLGhc8ui23UrEXDug9qisM8ivF7tZJLr1Mb6/X wyAQEcTVKlVqlSmAZG4vHDZoDN3q4U8C4091SoQQyxY772rEBefiPNRaaRdwqdyEbJIE XFrxocU+79NQFwrBxHjbgptInRh8o3OCvNYyhwNOoGgOWZksLiixTc5D6MyQ+Be1SxEW W3RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796365412; x=1796970212; 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=k9c7bg72OKyVZ3OhoXoOY3vbidMAwokU/eHErpCeRb0=; b=khICa7Ka6D/oG9UxJLHjV3vOIOh8KZ0YQ5MIBnr4eHMXQQzwSMladZuupF8rt4wH7U fuIBi5lJnVwHl/kEHHSBChynnGv7cYx0lwT12uySzPhGjbKIzNLKmk2YJSovkLEH2Cx6 3vVm2bHodaCU/6VUI2wdtt/ULuPy9R7uMYJW1zAJVQQws7rvQWCXCwqeQW1DzAROha7O TmB91S0vKHMmskGmX52VAbf0/V2THmfotfrgU9QYvVbMjiZsfuWeBDGmLv2zWyyRh8vP WlvN89eRpWe45gJHpiBXvXa0C0Q66LZpGKfQq2h3wgY4xbmf0iX4Bhfiriev5N0yIUN8 0GPw== X-Gm-Message-State: APuU4Z/0XRDUhGNLDYw5yhRe2J1B3OafWTDPEzlOB//KsMCglwuSVxJY 0szbh1gT98UhlN3EZjkg5miYtDTqmFBA2VrYdQR5M6+kvMI5+EBwWhDNhwsADsAvXJ6FOxNBf/N VT3Vn4/H5Yk+MUDSPL63Vv/v99wz5Cttw7ckU8db4UJ/2hL98eclb0FAofry5Yu3r4Vz9cuEW1a xeJ3qpDuiqYqHbvvy2cGA9bbLcysRdgYLis5jTdGHbN7JbfxW+v1vw06g= X-Received: from dlbur22-n1.prod.google.com ([2002:a05:7022:ea56:10b0:1a7:17d1:fc4a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:701a:cc85:20b0:1b5:86f9:69ea with SMTP id a92af1059eb24-1b5d6fc98a4mr1180085c88.0.1796365411321; Thu, 03 Dec 2026 22:23:31 -0800 (PST) Date: Thu, 3 Dec 2026 22:23:21 -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: <20261204062328.2508164-1-irogers@google.com> Subject: [PATCH v3 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+) 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. 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 6 adds a 'perf bench internals synthesize --[no-]procmap-query' option and a core.procmap-query config option to allow comparison. 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 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. 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/ 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 | 5 + tools/perf/bench/synthesize.c | 58 ++- tools/perf/check-headers.sh | 1 + 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 | 611 +++++++++++++++++++---- tools/perf/util/synthetic-events.h | 6 + 15 files changed, 1009 insertions(+), 139 deletions(-) create mode 100644 tools/perf/tests/synthesize-mmap.c base-commit: 22f7d78dc87e43ff4f7c03d23f46f49692c41ad0 -- 2.56.1.915.g69d5ec7298-goog