From nobody Thu Sep 24 15:11:49 2026 Received: from mail-pz2-f43.google.com (mail-pz2-f43.google.com [74.125.228.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE9B655293C for ; Tue, 22 Sep 2026 13:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790083202; cv=none; b=QjtFf6GxT0aAhfjG3yGFtygYVA5sqUEj+di3Xm5i4WZUeUgYiK+hFMia8s0FG3uvHk9oB1DYMKEHomKgfydbqPOoF/fS74qXbeXpWDaVqDdmMtoIA2R55n48UMw2CirIPxYzHXWxmWawr0yXKuZMFKJf1DG0YHw8Wzt6DYN02ak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790083202; c=relaxed/simple; bh=hNqYfoxEta6yayuVGifvUciuQ8J6upVwEpfzs/v+b2Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=eJo5dgf+rCa+KQqvA5EJOiHyy9akeI8FivqHTNkNfkpjaPFb+r0WqWZ/XgagZbdUIU8a/ynii6tXvuOLjIHnCGOEOSjEKQFQdidDv/sNNLI2aCBe4GnvKfe29KSFyMlB1uvm1z2m64g5bfYuok7InkvTshX+gaI20tHizM7RShk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VSVZW5gw; arc=none smtp.client-ip=74.125.228.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VSVZW5gw" Received: by mail-pz2-f43.google.com with SMTP id 41be03b00d2f7-cc4c08393dfso3384523a12.3 for ; Tue, 22 Sep 2026 06:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790083200; x=1790688000; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=0HuHouIXMmXXF1mGK08VBIvb7z6Q3KyojyCZuU1PWGs=; b=VSVZW5gw8UeGrn1fekDe69hEQNVFjHMriRUM9bQIzO+Oh6/rYYKTSwACduUVyHZmlu gZ/IoJyIVvaCIbQ0bsMdUMkjE2RvdbcuyCnqNhnJzg6TzQxUCsm0o3wCW13Zp0Kg94Db 2pTTLRZezTc1UzxjlwZ3Sf3V6ETuFBDnJmiASKEEUi2mTHVBnm63hvd2nRNEkHBGfmZW 0NQv5xn0nrPiR8GaHEP4eYoV+Jnwkqku8NvlcIp9jXMpVfwQGaJMU2+iPWnL2fqDbjzR Ru75p+0sfLv8zGUqyiVi3sO2YDSk9eJD1/yn4p8PwfasWY5AMOymEE3s+u96tpJT1F22 meNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790083200; x=1790688000; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0HuHouIXMmXXF1mGK08VBIvb7z6Q3KyojyCZuU1PWGs=; b=sz+rZk3OD6ZC09CbKvuI7HPRKIzxwjSF2j5hPBpdVxEFo42eH3/ZBxXEQmMTLPZ2rH kU6GLk+Tcp6aUy8hcHnLynQa5EKf60/oDKrvQ+MClDTNV7k/S/d88rkyUM9wFE1lPfi8 VKLeneXPX76Acw2oCtkKG/wHvkfMbKSjfiFa4fYNfxMNx1hhFXz6fpewu/N1tCsf1R43 020hY7l8eP6ldKxIY3ygbUHS6bzy0VKhqIeVYqdSeIGtwV7QhP5FCQOdQZBcVNkLUv0b bieq2tuvLc8G+6zAY0sMgnlataBUxMay97BFqN+P+5r0llWuNCX+J+IJaKn7a+4Q+IKN JbOA== X-Forwarded-Encrypted: i=1; AKwUvByB1iqyl1cvSmZpwQmnYB2gvcP3Ua60rx2RRvQGE8sDlXk4cJvQSzAhnURna/EDbp7+GBUu64Zmr8y9Ilk=@vger.kernel.org X-Gm-Message-State: AFuF++lZ8zuzsyOdTyuHN4orTMUcRrPsaizYkOgGB0+lw1kPdtkqwIAp DhfGqfLxRd7s6TVj3fv5IbZSz/a4uyTu/juWr605Zf9fkFrOuD8I4gAv X-Gm-Gg: AYBFou3SFmr8u+LdopjYhgxy68b3xkd7Hd2eL+8p45dvJlvvaxkzeP2lPGFlxx7mHu4 vPhJnd9R27o+XfHsaGkuNA8Cx66k622A9Ywbu7WZPUtEwQY/HKYfZSD5AgacDTq1vV6UQVP5k0y LpnA0SXA/a/P7DJgxcmE6CygHDfovH47Id96IE7TGL2kCzlMZ6HX1wiGXraQJsZ9yNTLSbSkSnk lFgY6klv7bNzDyyZD+j6ht8I/gENu5rt2bhUfE7XKALAk0O/JQDciFFoCXzmsx2WmkBowOSmddV v0D/J0yW8XWsyt+hhVP1Utzsy9MCAkIZp8oCLnAaitEorKW9Bgy5nfo6JH5yaTVyOv3Ikmn25zq 9zCYRNbTCR1jZYH406mMcRUfU0qGUo/QwK7RsGiq9DAUnLwGF3kxwTpIJue3OsbNgP5D9v1rzM9 xZWHNsjJZCHH/KchNZCL8Nw/1WN6ujIXVBX60OoAS29rSmd8aogLIoEz+1lZn+ixVkPs1xupdXi dDQr2vvpc4= X-Received: by 2002:a17:90b:4b0a:b0:39e:4c80:44b7 with SMTP id 98e67ed59e1d1-3a0730fa737mr1299033a91.26.1790083199680; Tue, 22 Sep 2026 06:19:59 -0700 (PDT) Received: from osman.mioffice.cn ([43.224.245.178]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a06741d485sm4946783a91.8.2026.09.22.06.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 06:19:59 -0700 (PDT) From: Zhan Xusheng X-Google-Original-From: Zhan Xusheng To: namhyung@kernel.org Cc: irogers@google.com, acme@kernel.org, changbin.du@huawei.com, adrian.hunter@intel.com, jolsa@kernel.org, mingo@redhat.com, peterz@infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, zhanxusheng@xiaomi.com Subject: [PATCH v3] perf symbols: Apply the symfs flat layout to the composed filename Date: Tue, 22 Sep 2026 21:19:52 +0800 Message-ID: <20260922131952.2922816-1-zhanxusheng@xiaomi.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" --symfs=3D,flat documents itself as matching only the base name, so a debuginfo lookup for /usr/lib/x86_64-linux-gnu/libc.so.6 should land on /libc.so.6.debug. It lands on /debug/usr/lib/x86_64-linux-gnu/libc.so.6.debug instead, because the layout is applied to a fixed prefix and the file name arrives afterwards: len =3D __symbol__join_symfs(filename, size, "/usr/lib/debug"); snprintf(filename + len, size - len, "%s.debug", dso__long_name(dso)); perf_basename() only ever sees "/usr/lib/debug", so neither layout comes out of it. Compose the path as it would appear on the profiled system and join it once, which puts the layout on the whole name. That covers FEDORA_DEBUGINFO, UBUNTU_DEBUGINFO, MIXEDUP_UBUNTU_DEBUGINFO, OPENEMBEDDED_DEBUGINFO and BUILDID_DEBUGINFO, plus the same composition in build_id_cache__find_debug(). BUILDID_DEBUGINFO needs one more step: the build id cache splits the first two characters of the build id off into a directory name, so the basename of the hierarchy path is only part of the build id. Name the flat file after the whole build id. dso__disassemble_filename() passes a path from perf's own build id cache rather than one on the profiled system, and every entry there is named "elf" or "debug". Use path__join() so the layout does not apply. With --symfs /s,flat the lookups are now /s/libc.so.6, /s/libc.so.6.debug, /s/sleep and /s/.debug. hierarchy is unchanged. Signed-off-by: Zhan Xusheng --- v2->v3: different approach. v1 and v2 took the four sites out of the layout; Namhyung asked for the layout to be made to work instead, so v3 composes the filename first and joins once. v2: https://lore.kernel.org/r/20260819094621.844115-1-zhanxusheng@xiaomi.com Traced openat()/newfstatat() under --symfs /s,flat and /s,hierarchy with perf record -- sleep 0.3 before and after: flat goes from 21 paths to 15, hierarchy is identical at 21. tools/perf/util/build-id.c | 12 +++++++---- tools/perf/util/disasm.c | 8 ++++++- tools/perf/util/dso.c | 43 +++++++++++++++++++++++++------------- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index eb95ab90f974..02233ef0eaff 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -586,9 +586,9 @@ static char *build_id_cache__find_debug(const char *sbu= ild_id, const char *dirname =3D "/usr/lib/debug/.build-id/"; char *realname =3D NULL; char dirbuf[PATH_MAX]; + char pathbuf[PATH_MAX]; char *debugfile; struct nscookie nsc; - size_t len =3D 0; =20 debugfile =3D calloc(1, PATH_MAX); if (!debugfile) @@ -599,9 +599,13 @@ static char *build_id_cache__find_debug(const char *sb= uild_id, dirname =3D dirbuf; } =20 - len =3D __symbol__join_symfs(debugfile, PATH_MAX, dirname); - snprintf(debugfile + len, PATH_MAX - len, "%.2s/%s.debug", sbuild_id, - sbuild_id + 2); + /* See the build id note in dso__read_binary_type_filename(). */ + if (symbol_conf.symfs_layout_flat) + scnprintf(pathbuf, PATH_MAX, "/%s.debug", sbuild_id); + else + scnprintf(pathbuf, PATH_MAX, "%s%.2s/%s.debug", dirname, + sbuild_id, sbuild_id + 2); + __symbol__join_symfs(debugfile, PATH_MAX, pathbuf); =20 nsinfo__mountns_enter(nsi, &nsc); realname =3D realpath(debugfile, NULL); diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 6cfdbabbb8c7..1148dde6c975 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -31,6 +31,7 @@ #include "map.h" #include "maps.h" #include "namespaces.h" +#include "path.h" #include "srcline.h" #include "symbol.h" #include "thread.h" @@ -1173,7 +1174,12 @@ static int dso__disassemble_filename(struct dso *dso= , char *filename, size_t fil =20 build_id_filename =3D dso__build_id_filename(dso, NULL, 0, false); if (build_id_filename) { - __symbol__join_symfs(filename, filename_size, build_id_filename); + /* + * This is a path in perf's own build id cache, not a path on + * the profiled system, so the symfs layout does not apply. + */ + path__join(filename, filename_size, symbol_conf.symfs, + build_id_filename); free(build_id_filename); } else { if (dso__has_build_id(dso)) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 42bfe30a3b51..e52de7cc1bc6 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -115,6 +115,7 @@ int dso__read_binary_type_filename(const struct dso *ds= o, const char *root_dir, char *filename, size_t size) { char build_id_hex[SBUILD_ID_SIZE]; + char relative[PATH_MAX]; int ret =3D 0; size_t len; =20 @@ -167,13 +168,15 @@ int dso__read_binary_type_filename(const struct dso *= dso, break; =20 case DSO_BINARY_TYPE__FEDORA_DEBUGINFO: - len =3D __symbol__join_symfs(filename, size, "/usr/lib/debug"); - snprintf(filename + len, size - len, "%s.debug", dso__long_name(dso)); + snprintf(relative, sizeof(relative), "/usr/lib/debug%s.debug", + dso__long_name(dso)); + __symbol__join_symfs(filename, size, relative); break; =20 case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: - len =3D __symbol__join_symfs(filename, size, "/usr/lib/debug"); - snprintf(filename + len, size - len, "%s", dso__long_name(dso)); + snprintf(relative, sizeof(relative), "/usr/lib/debug%s", + dso__long_name(dso)); + __symbol__join_symfs(filename, size, relative); break; =20 case DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO: @@ -187,8 +190,9 @@ int dso__read_binary_type_filename(const struct dso *ds= o, ret =3D -1; break; } - len =3D __symbol__join_symfs(filename, size, "/usr/lib/debug"); - snprintf(filename + len, size - len, "%s", dso__long_name(dso) + 4); + snprintf(relative, sizeof(relative), "/usr/lib/debug%s", + dso__long_name(dso) + 4); + __symbol__join_symfs(filename, size, relative); break; =20 case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO: @@ -200,15 +204,15 @@ int dso__read_binary_type_filename(const struct dso *= dso, while (last_slash !=3D dso__long_name(dso) && *last_slash !=3D '/') last_slash--; =20 - len =3D __symbol__join_symfs(filename, size, ""); dir_size =3D last_slash - dso__long_name(dso) + 2; - if (dir_size > (size - len)) { + if (dir_size > sizeof(relative)) { ret =3D -1; break; } - len +=3D scnprintf(filename + len, dir_size, "%s", dso__long_name(dso)); - len +=3D scnprintf(filename + len , size - len, ".debug%s", - last_slash); + len =3D scnprintf(relative, dir_size, "%s", dso__long_name(dso)); + scnprintf(relative + len, sizeof(relative) - len, ".debug%s", + last_slash); + __symbol__join_symfs(filename, size, relative); break; } =20 @@ -219,9 +223,20 @@ int dso__read_binary_type_filename(const struct dso *d= so, } =20 build_id__snprintf(dso__bid(dso), build_id_hex, sizeof(build_id_hex)); - len =3D __symbol__join_symfs(filename, size, "/usr/lib/debug/.build-id/"= ); - snprintf(filename + len, size - len, "%.2s/%s.debug", - build_id_hex, build_id_hex + 2); + /* + * The build id cache layout splits the first two characters off + * into a directory name, so the basename of the hierarchy path + * is only part of the build id. Name the flat file after the + * whole build id instead. + */ + if (symbol_conf.symfs_layout_flat) + snprintf(relative, sizeof(relative), "/%s.debug", + build_id_hex); + else + snprintf(relative, sizeof(relative), + "/usr/lib/debug/.build-id/%.2s/%s.debug", + build_id_hex, build_id_hex + 2); + __symbol__join_symfs(filename, size, relative); break; =20 case DSO_BINARY_TYPE__VMLINUX: base-commit: f0100363d8c374bd8e9ea7c9ba02744f0b802ca4 --=20 2.43.0