[PATCH] D103009: [DSE] Transform memset + malloc --> calloc (PR25892)
Alexander Kornienko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 19 15:54:27 PDT 2021
alexfh added a comment.
In D103009#2955983 <https://reviews.llvm.org/D103009#2955983>, @lebedev.ri wrote:
> I think i see where this is going - the just-`malloc`ed, but never touched memory
> doesn't need to be actually backed by an actual pages (see overcommit),
> while i guess `calloc` doesn't just mark the pages as zeroed-out,
> but actually marks them dirty and needed to be allocated,
> at least not unless you happen to allocate in multiples of page size?
I found this problem in mysql compiled with tcmalloc. Mysqld (at least in the somewhat older version I'm looking at) speculatively allocates a potentially large (depending on the configuration parameters) block of memory on start, which is normally used only partially. With `malloc` the memory is lazily given to the process when it starts using it. With `calloc` (and tcmalloc) the process actually tries to get all the pages immediately, which increases RSS (and thus, real memory usage). I guess, it may affect performance as well due to the unnecessary filling with zeroes, when user code calls `my_malloc` without `MY_ZEROFILL`.
For the context: https://fossies.org/linux/mariadb/mysys/my_malloc.c (this version seems functionally close to what I'm looking at).
> I guess the easy fix here is to require that `memset` post-dominates the `malloc`,
> but i guess we also need some langref blurb about this,
> because the transformation is correct, just-`malloc`ed memory is filed with `undef`,
> which we can always define into zeros: https://alive2.llvm.org/ce/z/C4vWH2
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103009/new/
https://reviews.llvm.org/D103009
More information about the llvm-commits
mailing list