aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-08-02 18:45:23 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-08-02 18:45:23 -0400
commit0a1eae391d0d92b60cff9f55cdaf3861b4e33922 (patch)
tree1482c70150e51f37849304385833d233475da192
parent70597f21f128b7dd6a2490078bea99d704b6f8c3 (diff)
perf tools: Don't keep unreferenced maps when unmaps are detected
For a file with: [root@emilia linux-2.6-tip]# perf report -D -fi allmodconfig-j32.perf.data | grep events: TOTAL events: 36933 MMAP events: 9056 LOST events: 0 COMM events: 1702 EXIT events: 1887 THROTTLE events: 8 UNTHROTTLE events: 8 FORK events: 1894 READ events: 0 SAMPLE events: 22378 ATTR events: 0 EVENT_TYPE events: 0 TRACING_DATA events: 0 BUILD_ID events: 0 [root@emilia linux-2.6-tip]# Testing with valgrind and making perf_session__delete() a nop, so that we can notice how many maps were actually deleted due to not having any samples on it: ==== HEAP SUMMARY: Before: ==10339== in use at exit: 8,909,997 bytes in 68,690 blocks ==10339== total heap usage: 78,696 allocs, 10,007 frees, 11,925,853 bytes allocated After: ==10506== in use at exit: 8,902,605 bytes in 68,606 blocks ==10506== total heap usage: 78,696 allocs, 10,091 frees, 11,925,853 bytes allocated I.e. just 84 detected unmaps with no hits out of 9056 for this workload, not much, but in some other long running workload this may save more bytes. Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/hist.c2
-rw-r--r--tools/perf/util/map.c31
-rw-r--r--tools/perf/util/map.h3
3 files changed, 25 insertions, 11 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index a6cea2894d12..e7263d49bcf0 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -93,6 +93,8 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template)
93 if (self != NULL) { 93 if (self != NULL) {
94 *self = *template; 94 *self = *template;
95 self->nr_events = 1; 95 self->nr_events = 1;
96 if (self->ms.map)
97 self->ms.map->referenced = true;
96 if (symbol_conf.use_callchain) 98 if (symbol_conf.use_callchain)
97 callchain_init(self->callchain); 99 callchain_init(self->callchain);
98 } 100 }
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 801e6962b0a6..3a7eb6ec0eec 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -29,6 +29,7 @@ void map__init(struct map *self, enum map_type type,
29 self->unmap_ip = map__unmap_ip; 29 self->unmap_ip = map__unmap_ip;
30 RB_CLEAR_NODE(&self->rb_node); 30 RB_CLEAR_NODE(&self->rb_node);
31 self->groups = NULL; 31 self->groups = NULL;
32 self->referenced = false;
32} 33}
33 34
34struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, 35struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
@@ -387,6 +388,7 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
387{ 388{
388 struct rb_root *root = &self->maps[map->type]; 389 struct rb_root *root = &self->maps[map->type];
389 struct rb_node *next = rb_first(root); 390 struct rb_node *next = rb_first(root);
391 int err = 0;
390 392
391 while (next) { 393 while (next) {
392 struct map *pos = rb_entry(next, struct map, rb_node); 394 struct map *pos = rb_entry(next, struct map, rb_node);
@@ -403,20 +405,16 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
403 405
404 rb_erase(&pos->rb_node, root); 406 rb_erase(&pos->rb_node, root);
405 /* 407 /*
406 * We may have references to this map, for instance in some
407 * hist_entry instances, so just move them to a separate
408 * list.
409 */
410 list_add_tail(&pos->node, &self->removed_maps[map->type]);
411 /*
412 * Now check if we need to create new maps for areas not 408 * Now check if we need to create new maps for areas not
413 * overlapped by the new map: 409 * overlapped by the new map:
414 */ 410 */
415 if (map->start > pos->start) { 411 if (map->start > pos->start) {
416 struct map *before = map__clone(pos); 412 struct map *before = map__clone(pos);
417 413
418 if (before == NULL) 414 if (before == NULL) {
419 return -ENOMEM; 415 err = -ENOMEM;
416 goto move_map;
417 }
420 418
421 before->end = map->start - 1; 419 before->end = map->start - 1;
422 map_groups__insert(self, before); 420 map_groups__insert(self, before);
@@ -427,14 +425,27 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
427 if (map->end < pos->end) { 425 if (map->end < pos->end) {
428 struct map *after = map__clone(pos); 426 struct map *after = map__clone(pos);
429 427
430 if (after == NULL) 428 if (after == NULL) {
431 return -ENOMEM; 429 err = -ENOMEM;
430 goto move_map;
431 }
432 432
433 after->start = map->end + 1; 433 after->start = map->end + 1;
434 map_groups__insert(self, after); 434 map_groups__insert(self, after);
435 if (verbose >= 2) 435 if (verbose >= 2)
436 map__fprintf(after, fp); 436 map__fprintf(after, fp);
437 } 437 }
438move_map:
439 /*
440 * If we have references, just move them to a separate list.
441 */
442 if (pos->referenced)
443 list_add_tail(&pos->node, &self->removed_maps[map->type]);
444 else
445 map__delete(pos);
446
447 if (err)
448 return err;
438 } 449 }
439 450
440 return 0; 451 return 0;
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 5b51bbd2f734..78575796d5f3 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -29,7 +29,8 @@ struct map {
29 }; 29 };
30 u64 start; 30 u64 start;
31 u64 end; 31 u64 end;
32 enum map_type type; 32 u8 /* enum map_type */ type;
33 bool referenced;
33 u32 priv; 34 u32 priv;
34 u64 pgoff; 35 u64 pgoff;
35 36