Skip to content

Address some perf memory/data size issues

Ian Rogers linux-perf-users lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest16 patches 5 repliesIn review
  2. v116 patches 5 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/16perf header: Make nodes dynamic in write_mem_topologytools/perf/util/header.c+25 -160 replies
2/16perf test x86: insn-x86 test data is immutable so mark it consttools/perf/arch/x86/tests/insn-x86.c+5 -50 replies
3/16perf test x86: intel-pt-test data is immutable so mark it consttools/perf/arch/x86/tests/intel-pt-test.c+7 -70 replies
4/16perf trace: Make some large static arrays consttools/perf/builtin-trace.c+19 -140 replies
5/16perf trace beauty: Make MSR arrays consttools/perf/trace/beauty/beauty.h tools/perf/trace/beauty/tracepoints/x86_msr.sh+4 -40 replies
6/16tools api fs: Avoid large static PATH_MAX arraystools/lib/api/fs/fs.c+18 -70 replies
7/16tools lib api fs tracing_path: Remove two unused MAX_PATH pathstools/lib/api/fs/tracing_path.c+6 -110 replies
8/16perf daemon: Dynamically allocate path to perftools/perf/builtin-daemon.c+28 -160 replies
9/16perf lock: Dynamically allocate lockhash_tabletools/perf/builtin-lock.c+16 -40 replies
10/16perf timechart: Make large arrays dynamictools/perf/builtin-timechart.c+39 -90 replies
11/16perf probe: Dynamically allocate params memorytools/perf/builtin-probe.c+71 -621 reply
12/16perf path: Make mkpath thread safetools/perf/builtin-config.c tools/perf/builtin-help.c tools/perf/util/cache.h +2 more+14 -340 replies
13/16perf scripting-engines: Move static to local variabletools/perf/util/scripting-engines/trace-event-perl.c tools/perf/util/scripting-engines/trace-event-python.c+5 -40 replies
14/16tools api fs: Dynamically allocate cgroupfs mount point cachetools/lib/api/fs/cgroup.c+11 -60 replies
15/16perf test pmu: Avoid 2 static path arraystools/perf/tests/pmu.c+9 -80 replies
16/16libsubcmd: Avoid two path staticstools/lib/subcmd/exec-cmd.c+20 -150 replies

Reviews trailers per patch

1 of 16 patches has a Reviewed-by or Acked-by.

PatchMasami Hiramatsu (Google)
1/16
2/16
3/16
4/16
5/16
6/16
7/16
8/16
9/16
10/16
11/16A-b
12/16
13/16
14/16
15/16
16/16

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/16] Address some perf memory/data size issues

Try to reduce the data size of the perf command. Before these patches a stripped non-debug binary was:

$ size -A perf
perf  :
section                  size       addr
.interp                    28        848
.note.gnu.property         32        880
.note.gnu.build-id         36        912
.note.ABI-tag              32        948
.gnu.hash               24628        984
.dynsym                 88920      25616
.dynstr                 70193     114536
.gnu.version             7410     184730
.gnu.version_r            800     192144
.rela.dyn              460824     192944
.rela.plt               14784     653768
.init                      23     671744
.plt                     9872     671776
.plt.got                   24     681648
.text                 2279182     681680
.noinstr.text             476    2960864
.fini                       9    2961340
.rodata               7042922    2961408
.eh_frame_hdr           42844   10004332
.eh_frame              226496   10047176
.tbss                      48   10279720
.init_array                16   10279720
.fini_array                 8   10279736
.data.rel.ro            53376   10279744
.dynamic                  736   10333120
.got                      328   10333856
.got.plt                 4952   10334184
.data                  391088   10339136
.bss                   285776   10730240
.comment                   31          0
Total                11005894

And after:
perf :
section size addr

.interp                    28        848
.note.gnu.property         32        880
.note.gnu.build-id         36        912
.note.ABI-tag              32        948
.gnu.hash               24628        984
.dynsym                 88944      25616
.dynstr                 70217     114560
.gnu.version             7412     184778
.gnu.version_r            816     192192
.rela.dyn              460824     193008
.rela.plt               14808     653832
.init                      23     671744
.plt                     9888     671776
.plt.got                   24     681664
.text                 2280446     681696
.noinstr.text             476    2962144
.fini                       9    2962620
.rodata               7048746    2965504
.eh_frame_hdr           42852   10014252
.eh_frame              226568   10057104
.tbss                      48   10285640
.init_array                16   10285640
.fini_array                 8   10285656
.data.rel.ro           301408   10285664
.dynamic                  736   10587072
.got                      328   10587808
.got.plt                 4960   10588136
.data                  100464   10593152
.bss                    22512   10693632

.comment 31 0
Total 10707320

The binary has reduced in size by 298,574 bytes. The .bss, that doesn't count toward file size, is reduced by 263,254 bytes. At runtime this could reduce the footprint up to 561,828 bytes. This is still just a fraction of the .rodata section's size of 7,048,746 bytes, that mainly contains the converted json events. The .rodata section needn't all be mapped at the same time.

The changes are largely removing static variables and replacing them with local or dynamically allocated memory. A common issue was having paths in statics for the sake of returning a non-stack pointer to a buffer, so the APIs were changed to pass buffers in.

v2. Address review comments from Namhyung, thanks!

Ian Rogers (16):
perf header: Make nodes dynamic in write_mem_topology perf test x86: insn-x86 test data is immutable so mark it const perf test x86: intel-pt-test data is immutable so mark it const perf trace: Make some large static arrays const
perf trace beauty: Make MSR arrays const
tools api fs: Avoid large static PATH_MAX arrays tools lib api fs tracing_path: Remove two unused MAX_PATH paths perf daemon: Dynamically allocate path to perf
perf lock: Dynamically allocate lockhash_table
perf timechart: Make large arrays dynamic
perf probe: Dynamically allocate params memory
perf path: Make mkpath thread safe
perf scripting-engines: Move static to local variable tools api fs: Dynamically allocate cgroupfs mount point cache perf test pmu: Avoid 2 static path arrays
libsubcmd: Avoid two path statics

 tools/lib/api/fs/cgroup.c                     |  17 ++-
 tools/lib/api/fs/fs.c                         |  25 +++-
 tools/lib/api/fs/tracing_path.c               |  17 +--
 tools/lib/subcmd/exec-cmd.c                   |  35 +++--
 tools/perf/arch/x86/tests/insn-x86.c          |  10 +-
 tools/perf/arch/x86/tests/intel-pt-test.c     |  14 +-
 tools/perf/builtin-config.c                   |   4 +-
 tools/perf/builtin-daemon.c                   |  44 +++---
 tools/perf/builtin-help.c                     |   4 +-
 tools/perf/builtin-lock.c                     |  20 ++-
 tools/perf/builtin-probe.c                    | 133 ++++++++++--------
 tools/perf/builtin-timechart.c                |  48 +++++--
 tools/perf/builtin-trace.c                    |  33 +++--
 tools/perf/tests/pmu.c                        |  17 +--
 tools/perf/trace/beauty/beauty.h              |   2 +-
 .../perf/trace/beauty/tracepoints/x86_msr.sh  |   6 +-
 tools/perf/util/cache.h                       |   2 +-
 tools/perf/util/config.c                      |   3 +-
 tools/perf/util/header.c                      |  41 +++---
 tools/perf/util/path.c                        |  35 +----
 .../util/scripting-engines/trace-event-perl.c |   4 +-
 .../scripting-engines/trace-event-python.c    |   5 +-
 22 files changed, 297 insertions(+), 222 deletions(-)
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog