avoid large map memory allocation in userspace
authorYonghong Song <yhs@fb.com>
Wed, 16 Aug 2017 23:18:22 +0000 (16:18 -0700)
committerYonghong Song <yhs@fb.com>
Thu, 17 Aug 2017 00:26:11 +0000 (17:26 -0700)
commit067219b2b6ffc3ec250134420f2f7546335f93d3
treea0d90d337c7943827a39261a1ae42771b14e7c16
parent47305f479bd82957985b58a72292a0355c7d0d2b
avoid large map memory allocation in userspace

In bcc, internal BPF_F_TABLE defines a structure to
contain all the table information for later easy
extraction. A global structure will be defined
with this type. Note that this structure will be
allocated by LLVM during compilation.

In the table structure, one of field is:
   _leaf_type data[_max_entries]

If the _leaf_type and _max_entries are big,
significant memory will be consumed. A big
_leaf_type size example is for BPF_STACK_TRACE map
with 127*8=1016 bytes. If max_entries is bigger
as well, significant amount of memory will be
consumed by LLVM.

This patch replaces
  _leaf_type data[_max_entries]
to
  unsigned ing max_entries

The detail of a test example can be found in issue #1291.
For the example in #1291, without this patch, for a
BPF_STACK_TRACE map with 1M entries, the RSS is roughly
3GB (roughly 3KB per entry). With this patch, it is 5.8MB.

Signed-off-by: Yonghong Song <yhs@fb.com>
src/cc/export/helpers.h
src/cc/frontends/clang/b_frontend_action.cc