Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
5cedb413 9f87498f

+11 -13
+11 -13
tools/perf/builtin-c2c.c
··· 237 237 if (mi == NULL) 238 238 return -ENOMEM; 239 239 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); 243 246 244 247 c2c_decode_stats(&stats, mi); 245 248 ··· 250 247 &al, NULL, NULL, mi, 251 248 sample, true); 252 249 if (he == NULL) 253 - goto free_mi_dup; 250 + goto free_mi; 254 251 255 252 c2c_he = container_of(he, struct c2c_hist_entry, he); 256 253 c2c_add_stats(&c2c_he->stats, &stats); ··· 275 272 276 273 mi = mi_dup; 277 274 278 - mi_dup = memdup(mi, sizeof(*mi)); 279 - if (!mi_dup) 280 - goto free_mi; 281 - 282 275 c2c_hists = he__get_c2c_hists(he, c2c.cl_sort, 2); 283 276 if (!c2c_hists) 284 - goto free_mi_dup; 277 + goto free_mi; 285 278 286 279 he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, 287 280 &al, NULL, NULL, mi, 288 281 sample, true); 289 282 if (he == NULL) 290 - goto free_mi_dup; 283 + goto free_mi; 291 284 292 285 c2c_he = container_of(he, struct c2c_hist_entry, he); 293 286 c2c_add_stats(&c2c_he->stats, &stats); ··· 302 303 addr_location__put(&al); 303 304 return ret; 304 305 305 - free_mi_dup: 306 - free(mi_dup); 307 306 free_mi: 308 - free(mi); 307 + mem_info__put(mi_dup); 308 + mem_info__put(mi); 309 309 ret = -ENOMEM; 310 310 goto out; 311 311 }