• yonghong-song's avatar
    implement free_bcc_memory() API (#2097) · 51480d05
    yonghong-song authored
    The main purpose of this API is to proactively release llvm/clang
    .text memory which is brought in during compilation.
    bcc .text memory for some other functions, e.g., attach_tracepoint,
    bpf_prog_load, etc. can also be freed after all these tasks are done.
    
    Note that such memory is reclaimable in kernel since it has
    file backup. But certain applicaiton may want to reduce this
    memory immediately to satisfy constraints imposed by sysadmin, etc.
    
    The implementation uses madvise with MADV_DONTNEED.
    For the case where bcc is static linked into the binary,
    we do not really know the start and the end of memory regions
    used by bcc, so the implementation here bluntly returned
    all .text memory back to kernel. This will incur some performance
    overhead as later on executed instructions will need to bring
    back to memory again.
    
    For static linked library, instrumented RandomRead example,
    without this patch, the RSS memory before load is:
      VmRSS:     63644 kB
      RssAnon:           23876 kB
      RssFile:           39768 kB
      RssShmem:              0 kB
    
    After this patch,
      VmRSS:     34264 kB
      RssAnon:           23880 kB
      RssFile:           10384 kB
      RssShmem:              0 kB
    
    For shared library, a python unit test, test_free_llvm_memory.py, is
    added, which shows for a do-nothing bpf program, we have
      Before freeing llvm memory: RssFile:  43000 kB
      After  freeing llvm memory: RssFile:  11992 kB
    
    The RssFile reduction on Facebook internal applications
    also ranges in 30-40MB.
    Signed-off-by: default avatarYonghong Song <yhs@fb.com>
    51480d05
BPF.cc 26.4 KB