perf maps: Add/use a sorted insert for fixup overlap and insert
authorIan Rogers <irogers@google.com>
Tue, 21 May 2024 16:51:09 +0000 (09:51 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 7 Jun 2024 06:31:30 +0000 (23:31 -0700)
commitd2307fd4f9895b44361d491f8bf474866b8351a2
tree391c3043835e5086dff26614b7d182f7ceee3943
parentaeefb04393f7525c0d5163f966f60d070b03ab99
perf maps: Add/use a sorted insert for fixup overlap and insert

Data may have lots of overlapping mmaps. The regular insert adds at
the end and relies on a later sort. For data with overlapping mappings
the sort will happen during a subsequent maps__find or
__maps__fixup_overlap_and_insert, there's never a period where the
inserted maps buffer up and a single sort happens. To avoid back to
back sorts, maintain the sort order when fixing up and
inserting. Previously the first_ending_after search was O(log n) where
n is the size of maps, and the insert was O(1) but because of the
continuous sorting was becoming O(n*log(n)). With maintaining sort
order, the insert now becomes O(n) for a memmove.

For a perf report on a perf.data file containing overlapping mappings
the time numbers are:

Before:
real    0m5.894s
user    0m5.650s
sys     0m0.231s

After:
real    0m0.675s
user    0m0.454s
sys     0m0.196s

Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: James Clark <james.clark@arm.com>
Cc: Steinar H . Gunderson <sesse@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240521165109.708593-4-irogers@google.com
tools/perf/util/maps.c