bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	 Adrian Hunter <adrian.hunter@intel.com>,
	Nick Terrell <terrelln@fb.com>,
	 Kan Liang <kan.liang@linux.intel.com>,
	Song Liu <song@kernel.org>,  Sandipan Das <sandipan.das@amd.com>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	 James Clark <james.clark@arm.com>,
	Liam Howlett <liam.howlett@oracle.com>,
	 Miguel Ojeda <ojeda@kernel.org>, Leo Yan <leo.yan@linaro.org>,
	 German Gomez <german.gomez@arm.com>,
	Ravi Bangoria <ravi.bangoria@amd.com>,
	 Artem Savkov <asavkov@redhat.com>,
	Athira Rajeev <atrajeev@linux.vnet.ibm.com>,
	 Andi Kleen <ak@linux.intel.com>,
	linux-kernel@vger.kernel.org,  linux-perf-users@vger.kernel.org,
	bpf@vger.kernel.org
Subject: Re: [PATCH v2 09/13] perf mem_info: Add and use map_symbol__exit and addr_map_symbol__exit
Date: Wed, 18 Oct 2023 16:20:30 -0700	[thread overview]
Message-ID: <CAM9d7cih9+DCKzVXBFTMUfjjY6ZX-yrj3CEM+Q3tjTNRYmQ=Yw@mail.gmail.com> (raw)
In-Reply-To: <20231012062359.1616786-10-irogers@google.com>

On Wed, Oct 11, 2023 at 11:24 PM Ian Rogers <irogers@google.com> wrote:
>
> Fix leak where mem_info__put wouldn't release the maps/map as used by
> perf mem. Add exit functions and use elsewhere that the maps and map
> are released.
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/Build        |  1 +
>  tools/perf/util/callchain.c  | 15 +++++----------
>  tools/perf/util/hist.c       |  6 ++----
>  tools/perf/util/machine.c    |  6 ++----
>  tools/perf/util/map_symbol.c | 15 +++++++++++++++
>  tools/perf/util/map_symbol.h |  4 ++++
>  tools/perf/util/symbol.c     |  5 ++++-
>  7 files changed, 33 insertions(+), 19 deletions(-)
>  create mode 100644 tools/perf/util/map_symbol.c
>
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index 0ea5a9d368d4..96058f949ec9 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -49,6 +49,7 @@ perf-y += dso.o
>  perf-y += dsos.o
>  perf-y += symbol.o
>  perf-y += symbol_fprintf.o
> +perf-y += map_symbol.o
>  perf-y += color.o
>  perf-y += color_config.o
>  perf-y += metricgroup.o
> diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
> index 0a7919c2af91..02881d5b822c 100644
> --- a/tools/perf/util/callchain.c
> +++ b/tools/perf/util/callchain.c
> @@ -1496,16 +1496,14 @@ static void free_callchain_node(struct callchain_node *node)
>
>         list_for_each_entry_safe(list, tmp, &node->parent_val, list) {
>                 list_del_init(&list->list);
> -               map__zput(list->ms.map);
> -               maps__zput(list->ms.maps);
> +               map_symbol__exit(&list->ms);
>                 zfree(&list->brtype_stat);
>                 free(list);
>         }
>
>         list_for_each_entry_safe(list, tmp, &node->val, list) {
>                 list_del_init(&list->list);
> -               map__zput(list->ms.map);
> -               maps__zput(list->ms.maps);
> +               map_symbol__exit(&list->ms);
>                 zfree(&list->brtype_stat);
>                 free(list);
>         }
> @@ -1591,8 +1589,7 @@ int callchain_node__make_parent_list(struct callchain_node *node)
>  out:
>         list_for_each_entry_safe(chain, new, &head, list) {
>                 list_del_init(&chain->list);
> -               map__zput(chain->ms.map);
> -               maps__zput(chain->ms.maps);
> +               map_symbol__exit(&chain->ms);
>                 zfree(&chain->brtype_stat);
>                 free(chain);
>         }
> @@ -1676,10 +1673,8 @@ void callchain_cursor_reset(struct callchain_cursor *cursor)
>         cursor->nr = 0;
>         cursor->last = &cursor->first;
>
> -       for (node = cursor->first; node != NULL; node = node->next) {
> -               map__zput(node->ms.map);
> -               maps__zput(node->ms.maps);
> -       }
> +       for (node = cursor->first; node != NULL; node = node->next)
> +               map_symbol__exit(&node->ms);
>  }
>
>  void callchain_param_setup(u64 sample_type, const char *arch)
> diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
> index ac8c0ef48a7f..d62693b8fad8 100644
> --- a/tools/perf/util/hist.c
> +++ b/tools/perf/util/hist.c
> @@ -524,8 +524,7 @@ static int hist_entry__init(struct hist_entry *he,
>                 map__put(he->mem_info->daddr.ms.map);
>         }
>  err:
> -       maps__zput(he->ms.maps);
> -       map__zput(he->ms.map);
> +       map_symbol__exit(&he->ms);
>         zfree(&he->stat_acc);
>         return -ENOMEM;
>  }
> @@ -1317,8 +1316,7 @@ void hist_entry__delete(struct hist_entry *he)
>         struct hist_entry_ops *ops = he->ops;
>
>         thread__zput(he->thread);
> -       maps__zput(he->ms.maps);
> -       map__zput(he->ms.map);
> +       map_symbol__exit(&he->ms);
>
>         if (he->branch_info) {
>                 map__zput(he->branch_info->from.ms.map);

What about he->branch_info and he->mem_info ?

Also I think we can use it in hists__account_cycles() too.

Thanks,
Namhyung


> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index 8e5085b77c7b..6ca7500e2cf4 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -2389,8 +2389,7 @@ static int add_callchain_ip(struct thread *thread,
>                                       iter_cycles, branch_from, srcline);
>  out:
>         addr_location__exit(&al);
> -       maps__put(ms.maps);
> -       map__put(ms.map);
> +       map_symbol__exit(&ms);
>         return err;
>  }
>
> @@ -3116,8 +3115,7 @@ static int append_inlines(struct callchain_cursor *cursor, struct map_symbol *ms
>                 if (ret != 0)
>                         return ret;
>         }
> -       map__put(ilist_ms.map);
> -       maps__put(ilist_ms.maps);
> +       map_symbol__exit(&ilist_ms);
>
>         return ret;
>  }
> diff --git a/tools/perf/util/map_symbol.c b/tools/perf/util/map_symbol.c
> new file mode 100644
> index 000000000000..bef5079f2403
> --- /dev/null
> +++ b/tools/perf/util/map_symbol.c
> @@ -0,0 +1,15 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include "map_symbol.h"
> +#include "maps.h"
> +#include "map.h"
> +
> +void map_symbol__exit(struct map_symbol *ms)
> +{
> +       maps__zput(ms->maps);
> +       map__zput(ms->map);
> +}
> +
> +void addr_map_symbol__exit(struct addr_map_symbol *ams)
> +{
> +       map_symbol__exit(&ams->ms);
> +}
> diff --git a/tools/perf/util/map_symbol.h b/tools/perf/util/map_symbol.h
> index e08817b0c30f..72d5ed938ed6 100644
> --- a/tools/perf/util/map_symbol.h
> +++ b/tools/perf/util/map_symbol.h
> @@ -22,4 +22,8 @@ struct addr_map_symbol {
>         u64           phys_addr;
>         u64           data_page_size;
>  };
> +
> +void map_symbol__exit(struct map_symbol *ms);
> +void addr_map_symbol__exit(struct addr_map_symbol *ams);
> +
>  #endif // __PERF_MAP_SYMBOL
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index 2740d4457c13..d67a87072eec 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -2790,8 +2790,11 @@ struct mem_info *mem_info__get(struct mem_info *mi)
>
>  void mem_info__put(struct mem_info *mi)
>  {
> -       if (mi && refcount_dec_and_test(&mi->refcnt))
> +       if (mi && refcount_dec_and_test(&mi->refcnt)) {
> +               addr_map_symbol__exit(&mi->iaddr);
> +               addr_map_symbol__exit(&mi->daddr);
>                 free(mi);
> +       }
>  }
>
>  struct mem_info *mem_info__new(void)
> --
> 2.42.0.609.gbb76f46606-goog
>

  reply	other threads:[~2023-10-18 23:20 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-12  6:23 [PATCH v2 00/13] Improvements to memory use Ian Rogers
2023-10-12  6:23 ` [PATCH v2 01/13] perf machine: Avoid out of bounds LBR memory read Ian Rogers
2023-10-12  6:23 ` [PATCH v2 02/13] libperf rc_check: Make implicit enabling work for GCC Ian Rogers
2023-10-12  6:23 ` [PATCH v2 03/13] perf hist: Add missing puts to hist__account_cycles Ian Rogers
2023-10-18 23:16   ` Namhyung Kim
2023-10-24 16:12     ` Ian Rogers
2023-10-12  6:23 ` [PATCH v2 04/13] perf threads: Remove unused dead thread list Ian Rogers
2023-10-12  6:23 ` [PATCH v2 05/13] perf offcpu: Add missed btf_free Ian Rogers
2023-10-12  6:23 ` [PATCH v2 06/13] perf callchain: Make display use of branch_type_stat const Ian Rogers
2023-10-12  6:23 ` [PATCH v2 07/13] perf callchain: Make brtype_stat in callchain_list optional Ian Rogers
2023-10-12  6:23 ` [PATCH v2 08/13] perf callchain: Minor layout changes to callchain_list Ian Rogers
2023-10-12  6:23 ` [PATCH v2 09/13] perf mem_info: Add and use map_symbol__exit and addr_map_symbol__exit Ian Rogers
2023-10-18 23:20   ` Namhyung Kim [this message]
2023-10-24 20:52     ` Ian Rogers
2023-10-12  6:23 ` [PATCH v2 10/13] perf record: Lazy load kernel symbols Ian Rogers
2023-10-19 11:02   ` Adrian Hunter
2023-10-24 18:42     ` Ian Rogers
2023-10-12  6:23 ` [PATCH v2 11/13] libperf: Lazily allocate mmap event copy Ian Rogers
2023-10-12  6:23 ` [PATCH v2 12/13] perf mmap: Lazily initialize zstd streams Ian Rogers
2023-10-18 23:21   ` Namhyung Kim
2023-10-24 19:21     ` Ian Rogers
2023-10-12  6:23 ` [PATCH v2 13/13] perf machine thread: Remove exited threads by default Ian Rogers
2023-10-18 23:30   ` Namhyung Kim
2023-10-19  0:39     ` Ian Rogers
2023-10-20 21:08       ` Namhyung Kim
2023-10-23 14:24   ` Adrian Hunter
2023-10-23 18:49     ` Ian Rogers
2023-10-24  5:19       ` Adrian Hunter

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='CAM9d7cih9+DCKzVXBFTMUfjjY6ZX-yrj3CEM+Q3tjTNRYmQ=Yw@mail.gmail.com' \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=anshuman.khandual@arm.com \
    --cc=asavkov@redhat.com \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=german.gomez@arm.com \
    --cc=irogers@google.com \
    --cc=james.clark@arm.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=leo.yan@linaro.org \
    --cc=liam.howlett@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=sandipan.das@amd.com \
    --cc=song@kernel.org \
    --cc=terrelln@fb.com \
    /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).