• Yonghong Song's avatar
    free llvm engine/context memory when rw_engine is not used · af96bba7
    Yonghong Song authored
    bcc utilizes MCJIT to generate final code and the code
    is actually runnable in the process. This, however,
    may have negative memory consumption impact.
    All data will be actually allocated in memory.
    
    For example, the following large array,
      #define TCP6_RXMIT_BUCKET_BITS 18
      struct tcp6_rxmit_tbl {
        __u64 buckets[1 << TCP6_RXMIT_BUCKET_BITS];
      };
      BPF_ARRAY(rxmit_marking_map, struct tcp6_rxmit_tbl, 1);
    is added to examples/cpp/HelloWorld.cpp.
    Internally, bcc will define a structure type rxmit_marking_map_table
    with members `struct tcp6_rxmit_tbl leaf` and a variable
    with this structure type. (see src/cc/export/helpers.h),
    so that rw_engine can traverse the type to generate
    proper sscanf/snprintf functions.
    
    Even with rw_engine is disabled, the RSS still increased
    from 6MB to 12MB. The array size is roughly 2MB.
    The additional 4MB overhead is due to some llvm internal overhead
    which I did not root cause it.
    
    If rw_engine is disabled, we can actually free llvm
    engine and context memory after copying the section data.
    We do not need to copy map section data since it is not
    used later on. Only map size is needed.
    
    We cannot free llvm context memory if rw_engine is enabled since context
    is shared between regular llvm module and sscanf module.
    
    For the above HelloWorld example, if rw_engine is disabled,
    this patch is able to reduce the RSS memory from 12MB to 6MB.
    Signed-off-by: default avatarYonghong Song <yhs@fb.com>
    af96bba7
bpf_module.cc 31.8 KB