Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753360AbbLICXv (ORCPT ); Tue, 8 Dec 2015 21:23:51 -0500 Received: from mail4.hitachi.co.jp ([133.145.228.5]:53373 "EHLO mail4.hitachi.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753126AbbLICS4 (ORCPT ); Tue, 8 Dec 2015 21:18:56 -0500 X-AuditID: 85900ec0-9afc5b9000001a57-b2-56678f8d93ca Subject: [PATCH perf/core 07/22] perf: Make map_groups to use refcnt From: Masami Hiramatsu To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Adrian Hunter , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Ingo Molnar , Namhyung Kim , Jiri Olsa Date: Wed, 09 Dec 2015 11:11:03 +0900 Message-ID: <20151209021103.10245.95658.stgit@localhost.localdomain> In-Reply-To: <20151209021047.10245.8918.stgit@localhost.localdomain> References: <20151209021047.10245.8918.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2056 Lines: 69 Make 'map_groups' object to use refcnt interface for debug. This can find refcnt related memory leaks. E.g. ---- # ./perf top --stdio ^q REFCNT: BUG: Unreclaimed objects found. REFCNT: Total 3615 objects are not reclaimed. "map" leaks 3373 objects "dso" leaks 232 objects "map_groups" leaks 10 objects To see all backtraces, rerun with -v option ---- Signed-off-by: Masami Hiramatsu --- tools/perf/util/map.c | 5 +++-- tools/perf/util/map.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 72fcc54..7859216 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -471,7 +471,7 @@ void map_groups__init(struct map_groups *mg, struct machine *machine) maps__init(&mg->maps[i]); } mg->machine = machine; - atomic_set(&mg->refcnt, 1); + refcnt__init_as(mg, refcnt, 1, "map_groups"); } static void __maps__purge(struct maps *maps) @@ -501,6 +501,7 @@ void map_groups__exit(struct map_groups *mg) for (i = 0; i < MAP__NR_TYPES; ++i) maps__exit(&mg->maps[i]); + refcnt__exit(mg, refcnt); } bool map_groups__empty(struct map_groups *mg) @@ -533,7 +534,7 @@ void map_groups__delete(struct map_groups *mg) void map_groups__put(struct map_groups *mg) { - if (mg && atomic_dec_and_test(&mg->refcnt)) + if (mg && refcnt__put(mg, refcnt)) map_groups__delete(mg); } diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index fcdc7d6..4667d67 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -78,7 +78,7 @@ bool map_groups__empty(struct map_groups *mg); static inline struct map_groups *map_groups__get(struct map_groups *mg) { if (mg) - atomic_inc(&mg->refcnt); + refcnt__get(mg, refcnt); return mg; } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/