Skip to content

Commit 0a1eae3

Browse files
committed
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>
1 parent 70597f2 commit 0a1eae3

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

‎tools/perf/util/hist.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template)
9393
if (self != NULL) {
9494
*self = *template;
9595
self->nr_events = 1;
96+
if (self->ms.map)
97+
self->ms.map->referenced = true;
9698
if (symbol_conf.use_callchain)
9799
callchain_init(self->callchain);
98100
}

‎tools/perf/util/map.c‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void map__init(struct map *self, enum map_type type,
2929
self->unmap_ip = map__unmap_ip;
3030
RB_CLEAR_NODE(&self->rb_node);
3131
self->groups = NULL;
32+
self->referenced = false;
3233
}
3334

3435
struct 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,
387388
{
388389
struct rb_root *root = &self->maps[map->type];
389390
struct rb_node *next = rb_first(root);
391+
int err = 0;
390392

391393
while (next) {
392394
struct map *pos = rb_entry(next, struct map, rb_node);
@@ -402,21 +404,17 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
402404
}
403405

404406
rb_erase(&pos->rb_node, root);
405-
/*
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]);
411407
/*
412408
* Now check if we need to create new maps for areas not
413409
* overlapped by the new map:
414410
*/
415411
if (map->start > pos->start) {
416412
struct map *before = map__clone(pos);
417413

418-
if (before == NULL)
419-
return -ENOMEM;
414+
if (before == NULL) {
415+
err = -ENOMEM;
416+
goto move_map;
417+
}
420418

421419
before->end = map->start - 1;
422420
map_groups__insert(self, before);
@@ -427,14 +425,27 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
427425
if (map->end < pos->end) {
428426
struct map *after = map__clone(pos);
429427

430-
if (after == NULL)
431-
return -ENOMEM;
428+
if (after == NULL) {
429+
err = -ENOMEM;
430+
goto move_map;
431+
}
432432

433433
after->start = map->end + 1;
434434
map_groups__insert(self, after);
435435
if (verbose >= 2)
436436
map__fprintf(after, fp);
437437
}
438+
move_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;
438449
}
439450

440451
return 0;

‎tools/perf/util/map.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ struct map {
2929
};
3030
u64 start;
3131
u64 end;
32-
enum map_type type;
32+
u8 /* enum map_type */ type;
33+
bool referenced;
3334
u32 priv;
3435
u64 pgoff;
3536

0 commit comments

Comments
 (0)