pahole uses a lot of memory when doing DWARF->BTF encoding. While some of this is inevitable there are some cases where we can improve things. When doing BTF encoding, we sometimes need to keep CUs around to compare functions to spot optimized/inconsistent functions. Currently we decide this on a per-encoder basis (saved_func_cnt) where we count how many times we save a function, and if any functions are saved for the _encoder_, we keep all CUs. Instead we can have a per-CU count of saved functions, and if none are saved for the _CU_ it is safe to delete it. This leads to deleting ~90 CUs during parallel vmlinux BTF generation versus deleting just 1 prior to this change. Signed-off-by: Alan Maguire <alan.maguire@xxxxxxxxxx> --- btf_encoder.c | 5 ++--- dwarves.h | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index adc38c3..dfaab70 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -83,7 +83,6 @@ struct btf_encoder { const char *filename; struct elf_symtab *symtab; uint32_t type_id_off; - int saved_func_cnt; bool has_index_type, need_index_type, skip_encoding_vars, @@ -907,7 +906,7 @@ static int32_t btf_encoder__save_func(struct btf_encoder *encoder, struct functi } else { func->state.type_id_off = encoder->type_id_off; func->function = fn; - encoder->saved_func_cnt++; + encoder->cu->functions_saved++; } return 0; } @@ -2283,7 +2282,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, struct co * functions for later addition. */ if (!err) - err = encoder->saved_func_cnt > 0 ? LSK__KEEPIT : LSK__DELETE; + err = encoder->cu->functions_saved > 0 ? LSK__KEEPIT : LSK__DELETE; out: encoder->cu = NULL; return err; diff --git a/dwarves.h b/dwarves.h index d562e42..060e6a8 100644 --- a/dwarves.h +++ b/dwarves.h @@ -303,6 +303,7 @@ struct cu { uint8_t little_endian:1; uint8_t nr_register_params; int register_params[ARCH_MAX_REGISTER_PARAMS]; + int functions_saved; enum cu_state state; uint16_t language; unsigned long nr_inline_expansions; -- 2.43.5