Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp16119rdb; Wed, 18 Oct 2023 16:21:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBtj70skupeST8jo8bfGplzuzSuHh09ceNJLhf7RUnt3YL3PGQMp7CIew2T2KdtTII2E8c X-Received: by 2002:a05:6a20:9155:b0:133:f0b9:856d with SMTP id x21-20020a056a20915500b00133f0b9856dmr673674pzc.17.1697671312497; Wed, 18 Oct 2023 16:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697671312; cv=none; d=google.com; s=arc-20160816; b=so4CWQ7xE4ZGas3xijnlJncBl6zffZXIS/qOVKT7I0tdeqWFuYNakjFybRgIAxXbx4 Rju2nWPRwIJN57W5qKBpgqOVNAvUs8cGmRqlNilZ4V9vn5wGxqEwFLu8KDXSYcRNM4Gl YVB/dl7kSvWN2gtuUv3GMrqwjSxu+VHVDN3yZhf3elQ8n3Ft5Nd9t2VjD46ubIwRyusZ IfTC8/AcUnxBOBAua3I1N6+RsFM/XV5yWXl0evr8ElYEpnvPpZn48LvkzmSUIxIZzJLt AqIQyuMaURUKN9NGPzwT8PCCpRlRPYpC8inwJ/px6E3BiZ1ugwjG0/jtGFLzk7TJ1t7/ EGqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=+96JSHq590yHwa9ziIp059RfnAiYFpeifQHUKTUkZIA=; fh=E10VZPe6Co8ezsBgErBfA67AzM7mDmfOH0ZUqd+UkZw=; b=ox/EWRzBHwN/ctypDGiIT4htW+kj8eV7wkgJAT88UiMURWflpebZPuOC9PpmxiK42b UzEVssFJqxhtu0YGg8JFaWNBE1vPBFh4LcWjJMjArvFMGOr0GkH4HvxwOUnhmXEv7Mwz kQnzhVQWa8kAA2+koxznRPxA00/rvKMgXdVIsj5kuyBYOurKRu8cGnMC7e+U4WwJ13nx M6oQ+u4tCBqEs0szJIjiz/857gdOHMYX4NAJ3guJ4jSaBz6LBII6SXGD6U2R2uHrrK1R cvcKzxSqxInRjaAJ8kpWbvVbJ6OeEoc7tRVzGZMQ8kP05g9/WSfw8vnaP+sv4fxZjonx I7ww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id y2-20020a633202000000b005895c80c902si3022279pgy.438.2023.10.18.16.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:21:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3C87C8212AA2; Wed, 18 Oct 2023 16:21:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232124AbjJRXV0 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 18 Oct 2023 19:21:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232586AbjJRXVB (ORCPT ); Wed, 18 Oct 2023 19:21:01 -0400 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8B03D51; Wed, 18 Oct 2023 16:20:42 -0700 (PDT) Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-27d23f1e3b8so5619406a91.1; Wed, 18 Oct 2023 16:20:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671242; x=1698276042; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UufSU0DJZN7WnStqbSdFLZOGonoM+uqnsYlL8bCP5z8=; b=FogSghdWNbnqLh0STBS4o+Tc5LukwGDkIxTKzAAfcLjWXc7K/jghnRCKlEWXAsmxHn 0zr0VwbGjw7BgZmiK8GJI85JB7IRoprUimdiN5/4LduZ/TTdkIbJxj4+TEysqqw0JzVS AC1kKsGx6HIuAx4JN033ok89NyaswmhggyLnQci0ve4c09GkkKsQIGy4ENWtvUg8m+Ms IKHf6Ml0nPLyOZb2aCgxxWX6i6LYeW3jvOB/fOk/2YDGDeEibUVxqtu0vmvpuNkTl1b6 K9icgTwcdwucRHjE/eNcM/cPi/K4yVk0nLQ30YUdcV0ELFupV5l/Vb3lO1k6tkTYWCp7 Ut8A== X-Gm-Message-State: AOJu0Yzfzl4l/sN67MDXdaym6T+PEZpEinfXyw5kyawrzmUpalPwmCPg ZfjkQEE9oabNIsUYr8piK6Hzt5kBx8jRu4ZNfL8= X-Received: by 2002:a17:90b:4b49:b0:27d:8d0:713e with SMTP id mi9-20020a17090b4b4900b0027d08d0713emr655906pjb.10.1697671241931; Wed, 18 Oct 2023 16:20:41 -0700 (PDT) MIME-Version: 1.0 References: <20231012062359.1616786-1-irogers@google.com> <20231012062359.1616786-10-irogers@google.com> In-Reply-To: <20231012062359.1616786-10-irogers@google.com> From: Namhyung Kim Date: Wed, 18 Oct 2023 16:20:30 -0700 Message-ID: Subject: Re: [PATCH v2 09/13] perf mem_info: Add and use map_symbol__exit and addr_map_symbol__exit To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Nick Terrell , Kan Liang , Song Liu , Sandipan Das , Anshuman Khandual , James Clark , Liam Howlett , Miguel Ojeda , Leo Yan , German Gomez , Ravi Bangoria , Artem Savkov , Athira Rajeev , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_SPF_HELO, HTML_MESSAGE,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 18 Oct 2023 16:21:51 -0700 (PDT) On Wed, Oct 11, 2023 at 11:24 PM Ian Rogers 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 > --- > 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 >