Skip to content

Instantly share code, notes, and snippets.

@MaskRay
Last active January 8, 2023 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MaskRay/219effe23a767b85059097f863ebc085 to your computer and use it in GitHub Desktop.
Save MaskRay/219effe23a767b85059097f863ebc085 to your computer and use it in GitHub Desktop.
lld with different malloc implementations
# Build malloc implementations.
mkdir -p /tmp/p
pushd /tmp/p
if [[ ! -d jemalloc ]]; then
git clone https://github.com/jemalloc/jemalloc
(cd jemalloc
./autogen.sh
mkdir -p out/release && cd out/release
../../configure && make -j $(nproc))
fi
if [[ ! -d mimalloc ]]; then
git clone https://github.com/microsoft/mimalloc
(cd mimalloc; cmake -GNinja -S. -Bout/release -DCMAKE_BUILD_TYPE=Release; ninja -C out/release)
fi
if [[ ! -d rpmalloc ]]; then
git clone https://github.com/mjansson/rpmalloc
(cd rpmalloc; ./configure.py; ninja)
fi
if [[ ! -d snmalloc ]]; then
git clone https://github.com/microsoft/snmalloc
(cd snmalloc; cmake -GNinja -S. -Bout/release -DCMAKE_BUILD_TYPE=Release -DSNMALLOC_STATIC_LIBRARY_PREFIX=; ninja -C out/release)
fi
popd
# In a directory extracted from an lld reproduce tarball
# In llvm-project, run: ninja lld; rm bin/lld; ninja -v lld; copy the command line, append -Wl,--reproduce=/tmp/lld.tar
# cd /tmp; tar xf lld.tar; cd lld
pushd /tmp/lld
sed -i '/--chroot/d' response.txt
ld.lld @response.txt -o lld.glibc
ld.lld /tmp/p/mimalloc/out/release/libmimalloc.a @response.txt -o lld.mi
ld.lld /tmp/p/jemalloc/out/release/lib/libjemalloc.a @response.txt -o lld.je
ld.lld /tmp/p/rpmalloc/build/ninja/linux/release/x86-64/rpmalloc-*/librpmalloc*.a @response.txt -o lld.rp
ld.lld /tmp/p/snmalloc/out/release/libsnmallocshim-static.a @response.txt /usr/lib/x86_64-linux-gnu/libatomic.so.1 -o lld.sn
popd
for m in glibc mi je rp sn; do
/tmp/lld/lld.$m -flavor gnu @response.txt --time-trace=$i.$m.time-trace
for i in 1 2 4 8 16 32 64; do
numactl -C 0-$[i-1] /tmp/lld/lld.$m -flavor gnu @response.txt --threads=$i --time-trace=$i.$m.time-trace
jq -r '.traceEvents[] | select(.name|contains("Total")) | "\(.dur/1000000) \(.name)"' < $i.$m.time-trace > $i.$m
done
done
@MaskRay
Copy link
Author

MaskRay commented Oct 26, 2022

Just a quick question. When you built snmalloc did you set -DSNMALLOC_STATIC_LIBRARY_PREFIX= ? It defaults to creating symbols like sn_malloc. The performance numbers look like is more similar to glibc than I would have expected.

Sorry, I didn't. Used -DSNMALLOC_STATIC_LIBRARY_PREFIX= now and reran the tests. (Still updating chromium ones)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment