Skip to content

Add BTF types deduplication algorithm

Andrii Nakryiko netdev 2 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 1 replyApplied
  2. v13 patches 3 repliesSuperseded

Changes in v2 from the cover letter

- rebase on latest bpf-next
- err_log/elog -> pr_debug
- btf__dedup, btf__get_strings, btf__get_nr_types listed under 0.0.2 version

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/3btf: extract BTF type size calculationtools/lib/bpf/btf.c+46 -520 replies
2/3btf: add BTF types deduplication algorithmtools/lib/bpf/btf.c tools/lib/bpf/btf.h tools/lib/bpf/libbpf.map+1749 -00 replies
3/3selftests/btf: add initial BTF dedup teststools/lib/bpf/btf.c tools/lib/bpf/btf.h tools/lib/bpf/libbpf.map +1 more+537 -150 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH btf v2 0/3] Add BTF types deduplication algorithm

This patch series adds BTF deduplication algorithm to libbpf. This algorithm allows to take BTF type information containing duplicate per-compilation unit information and reduce it to equivalent set of BTF types with no duplication without loss of information. It also deduplicates strings and removes those strings that are not referenced from any BTF type (and line information in .BTF.ext section, if any).

Algorithm also resolves struct/union forward declarations into concrete BTF types across multiple compilation units to facilitate better deduplication ratio. If undesired, this resolution can be disabled through specifying corresponding options.

When applied to BTF data emitted by pahole's DWARF->BTF converter, it reduces the overall size of .BTF section by about 65x, from about 112MB to 1.75MB, leaving only 29247 out of initial 3073497 BTF type descriptors.

Algorithm with minor differences and preliminary results before FUNC/FUNC_PROTO support is also described more verbosely at:
https://facebookmicrosites.github.io/bpf/blog/2018/11/14/btf-enhancement.html

v1->v2:
- rebase on latest bpf-next
- err_log/elog -> pr_debug
- btf__dedup, btf__get_strings, btf__get_nr_types listed under 0.0.2 version

Andrii Nakryiko (3):
btf: extract BTF type size calculation
btf: add BTF types deduplication algorithm
selftests/btf: add initial BTF dedup tests

 tools/lib/bpf/btf.c                    | 1851 +++++++++++++++++++++++-
 tools/lib/bpf/btf.h                    |   10 +
 tools/lib/bpf/libbpf.map               |    3 +
 tools/testing/selftests/bpf/test_btf.c |  535 ++++++-
 4 files changed, 2332 insertions(+), 67 deletions(-)
Signature · 1 line
2.17.1