linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Mario <jmario@redhat.com>
To: Ian Rogers <irogers@google.com>, Michael Petlan <mpetlan@redhat.com>
Cc: linux-perf-users@vger.kernel.org, acme@redhat.com,
	namhyung@kernel.org, jolsa@kernel.org
Subject: Re: [PATCH 1/4] perf tools: Remove /SYSV from no_dso maps
Date: Mon, 6 Oct 2025 14:28:50 -0400	[thread overview]
Message-ID: <ec1dd178-890f-4eb7-b6e6-e027e7c2d7b3@redhat.com> (raw)
In-Reply-To: <CAP-5=fXo2+tKbTtNKN8oxiva+rKYB2AMpOCjA4+5xxNagC01UQ@mail.gmail.com>



On 10/6/25 2:01 PM, Ian Rogers wrote:
> On Mon, Oct 6, 2025 at 10:57 AM Michael Petlan <mpetlan@redhat.com> wrote:
>>
>> We will need it for upcoming commits. Also adjust the function
>> calls in perf-inject, in order not to break the logic.
>>
>> Suggested-by: Jiri Olsa <jolsa@kernel.org>
>>
>> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
>> ---
>>  tools/perf/builtin-inject.c | 4 ++--
>>  tools/perf/util/map.c       | 5 +++--
>>  tools/perf/util/map.h       | 6 +++++-
>>  3 files changed, 10 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
>> index a114b3fa1bea..cc090da5c445 100644
>> --- a/tools/perf/builtin-inject.c
>> +++ b/tools/perf/builtin-inject.c
>> @@ -773,7 +773,7 @@ static int tool__inject_build_id(const struct perf_tool *tool,
>>
>>         if (is_anon_memory(filename) || flags & MAP_HUGETLB)
>>                 return 0;
>> -       if (is_no_dso_memory(filename))
>> +       if (is_no_dso_memory(filename) || is_shared_memory(filename))
>>                 return 0;
>>
>>         if (inject->known_build_ids != NULL &&
>> @@ -813,7 +813,7 @@ static int tool__inject_mmap2_build_id(const struct perf_tool *tool,
>>         /* Return to repipe anonymous maps. */
>>         if (is_anon_memory(filename) || flags & MAP_HUGETLB)
>>                 return 1;
>> -       if (is_no_dso_memory(filename))
>> +       if (is_no_dso_memory(filename) || is_shared_memory(filename))
>>                 return 1;
>>
>>         if (dso__read_build_id(dso)) {
>> diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
>> index b46c68c24d1c..6d13b4602970 100644
>> --- a/tools/perf/util/map.c
>> +++ b/tools/perf/util/map.c
>> @@ -133,12 +133,13 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
>>         if (ADD_RC_CHK(result, map)) {
>>                 char newfilename[PATH_MAX];
>>                 struct dso *dso;
>> -               int anon, no_dso, vdso, android;
>> +               int anon, no_dso, vdso, android, shared;
>>
>>                 android = is_android_lib(filename);
>>                 anon = is_anon_memory(filename) || flags & MAP_HUGETLB;
>>                 vdso = is_vdso_map(filename);
>>                 no_dso = is_no_dso_memory(filename);
>> +               shared = is_shared_memory(filename);
>>                 nsi = nsinfo__get(thread__nsinfo(thread));
>>
>>                 if ((anon || no_dso) && nsi && (prot & PROT_EXEC)) {
>> @@ -174,7 +175,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
>>                 assert(!dso__kernel(dso));
>>                 map__init(result, start, start + len, pgoff, dso, prot, flags);
>>
>> -               if (anon || no_dso) {
>> +               if (anon || no_dso || shared) {
>>                         map->mapping_type = MAPPING_TYPE__IDENTITY;
>>
>>                         /*
>> diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
>> index 9cadf533a561..616f32504e46 100644
>> --- a/tools/perf/util/map.h
>> +++ b/tools/perf/util/map.h
>> @@ -258,10 +258,14 @@ static inline int is_anon_memory(const char *filename)
>>  static inline int is_no_dso_memory(const char *filename)
>>  {
>>         return !strncmp(filename, "[stack", 6) ||
>> -              !strncmp(filename, "/SYSV", 5)  ||
>>                !strcmp(filename, "[heap]");
>>  }
>>
>> +static inline int is_shared_memory(const char *filename)
>> +{
>> +       return !strncmp(filename, "/SYSV", 5);
>> +}
> 
> Shared memory could happen because of two mmaps having the same file
> and offset. Is the mapping shared within or across processes? Perhaps
> there is a clearer and more capable API hiding here.

Hi Ian:
We see it happening both within a process and across processes, where the code does something like this:

    shmid = shmget((key_t)0, 8192, IPC_CREAT|0777); 
    shmat_addr1 = shmat(shmid, (char *)0, 0);
    shmat_addr2 = shmat(shmid, (char *)0, 0);

The separate shmat() calls can either be in the same process or different processes.  As long as they use the same shmid and a NULL address, they end up with different virtual addresses pointing to the same location in shared memory.

Then if cacheline contention occurs from accesses to shmat_addr1 and shmat_addr2, perf c2c cannot detect it.

I hope this helps.
Thanks,
Joe

> 
> Thanks,
> Ian
> 
>> +
>>  static inline void map__set_start(struct map *map, u64 start)
>>  {
>>         RC_CHK_ACCESS(map)->start = start;
>> --
>> 2.47.3
>>
> 


  reply	other threads:[~2025-10-06 18:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-06 17:57 [PATCH 0/4] perf c2c: Detect shared memory cachelines Michael Petlan
2025-10-06 17:57 ` [PATCH 1/4] perf tools: Remove /SYSV from no_dso maps Michael Petlan
2025-10-06 18:01   ` Ian Rogers
2025-10-06 18:28     ` Joe Mario [this message]
2025-10-06 19:21       ` Ian Rogers
2025-10-06 17:57 ` [PATCH 2/4] perf c2c: Add shared mem flag Michael Petlan
2025-10-06 17:57 ` [PATCH 3/4] perf c2c: Add map name for cacheline Michael Petlan
2025-10-06 17:57 ` [PATCH 4/4] perf c2c report: Add --detect-shm option Michael Petlan
2025-10-07  8:16 ` [PATCH 0/4] perf c2c: Detect shared memory cachelines Namhyung Kim
2025-10-07 14:38   ` Arnaldo Carvalho de Melo

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=ec1dd178-890f-4eb7-b6e6-e027e7c2d7b3@redhat.com \
    --to=jmario@redhat.com \
    --cc=acme@redhat.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mpetlan@redhat.com \
    --cc=namhyung@kernel.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;
as well as URLs for NNTP newsgroup(s).