Skip to content

Commit 5cedb41

Browse files
olsajiriacmel
authored andcommitted
perf c2c: Use mem_info refcnt logic
Switch to refcnt logic instead of duplicating mem_info objects. No functional change, just saving some memory. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20180307155020.32613-7-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 9f87498 commit 5cedb41

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

‎tools/perf/builtin-c2c.c‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,20 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
237237
if (mi == NULL)
238238
return -ENOMEM;
239239

240-
mi_dup = memdup(mi, sizeof(*mi));
241-
if (!mi_dup)
242-
goto free_mi;
240+
/*
241+
* The mi object is released in hists__add_entry_ops,
242+
* if it gets sorted out into existing data, so we need
243+
* to take the copy now.
244+
*/
245+
mi_dup = mem_info__get(mi);
243246

244247
c2c_decode_stats(&stats, mi);
245248

246249
he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops,
247250
&al, NULL, NULL, mi,
248251
sample, true);
249252
if (he == NULL)
250-
goto free_mi_dup;
253+
goto free_mi;
251254

252255
c2c_he = container_of(he, struct c2c_hist_entry, he);
253256
c2c_add_stats(&c2c_he->stats, &stats);
@@ -272,19 +275,15 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
272275

273276
mi = mi_dup;
274277

275-
mi_dup = memdup(mi, sizeof(*mi));
276-
if (!mi_dup)
277-
goto free_mi;
278-
279278
c2c_hists = he__get_c2c_hists(he, c2c.cl_sort, 2);
280279
if (!c2c_hists)
281-
goto free_mi_dup;
280+
goto free_mi;
282281

283282
he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops,
284283
&al, NULL, NULL, mi,
285284
sample, true);
286285
if (he == NULL)
287-
goto free_mi_dup;
286+
goto free_mi;
288287

289288
c2c_he = container_of(he, struct c2c_hist_entry, he);
290289
c2c_add_stats(&c2c_he->stats, &stats);
@@ -303,10 +302,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
303302
addr_location__put(&al);
304303
return ret;
305304

306-
free_mi_dup:
307-
free(mi_dup);
308305
free_mi:
309-
free(mi);
306+
mem_info__put(mi_dup);
307+
mem_info__put(mi);
310308
ret = -ENOMEM;
311309
goto out;
312310
}

0 commit comments

Comments
 (0)