[PATCH] D150816: [llvm-mca][RISCV] Fix llvm-mca RISCVInstrument memory leak

Michael Maitland via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 18 15:18:15 PDT 2023


michaelmaitland added a comment.

In D150816#4354479 <https://reviews.llvm.org/D150816#4354479>, @michaelmaitland wrote:

> Valgrind reports `1711 errors from 1711 contexts` before my fix and `1710 errors from 1710 contexts` after my fix. It looks like using valgrind has problems related to python code. This is the command I ran:
>
>   valgrind --leak-check=yes bin/llvm-lit -v ../llvm/test/tools/llvm-mca/RISCV/different-instruments.s ../llvm/test/tools/llvm-mca/RISCV/disable-im.s ../llvm/test/tools/llvm-mca/RISCV/instrument-at-start.s ../llvm/test/tools/llvm-mca/RISCV/instrument-in-middle.s ../llvm/test/tools/llvm-mca/RISCV/instrument-in-region.s ../llvm/test/tools/llvm-mca/RISCV/instrument-straddles-region.s ../llvm/test/tools/llvm-mca/RISCV/multiple-same-instruments.s ../llvm/test/tools/llvm-mca/RISCV/riscv-instrument-no-data-is-err.s ../llvm/test/tools/llvm-mca/RISCV/unknown-instrument-is-err.s ../llvm/test/tools/llvm-mca/RISCV/unknown-lmul-is-err.s
>
> I also see these kinds of errors when I run `valgrind --leak-check=yes bin/llvm-lit ../llvm/test/tools/llvm-mca/X86/*` with and without my memory leak fix, although these test cases do not cause LSan to complain upstream.
>
> I re-ran without the `leack-check=yes` option on RISCV tests with my fix, RISCV tests without my fix and on x86 before the original instrument changes were made and all three have many instances of `definitely lost: n bytes in m blocks`. I'm not sure how helpful valgrind is here as it looks like it may struggle with the python driver of llvm-lit.

I suspected that llvm-lit was the problem, so I re-ran valgrind directly on llvm-mca. I find that without my fix there is a 112 byte leak and after my change there is an 80 byte leak. Both of these leaks come from calling std::make_unique it seems:

  ==1378324==    at 0x4C378C3: operator new(unsigned long) (vg_replace_malloc.c:422)
  ==1378324==    by 0x43CF71: llvm::mca::RISCVInstrumentManager::createInstrument(llvm::StringRef, llvm::StringRef) (in /home/mmaitland/repos/llvm-project/build/bin/llvm-mca)
  ==1378324==    by 0x4159D5: llvm::mca::InstrumentRegionCommentConsumer::HandleComment(llvm::SMLoc, llvm::StringRef) (in /home/mmaitland/repos/llvm-project/build/bin/llvm-mca)

Let me take another look at what is going wrong here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150816/new/

https://reviews.llvm.org/D150816



More information about the llvm-commits mailing list