Skip to content

Commit 63b584a

Browse files
llvm-project: link against jemalloc
The following symbols from musl's malloc-ng implementation were appearing in a perf profile of a kernel build within the top 20 hottest symbols by cycle count. malloc-ng: Samples: 589K of event 'cycles:ppu', Event count (approx.): 11053523397362 Overhead Shared Object Symbol + 1.57% clang [.] __libc_malloc_impl 0.69% clang [.] __libc_free + 0.65% clang [.] alloc_slot + 0.58% clang [.] get_meta $ /usr/bin/time -v make CC=clang LD=ld.lld -j72 -s Command being timed: "make CC=clang LD=ld.lld -j72 -s" User time (seconds): 2801.78 System time (seconds): 395.48 Percent of CPU this job got: 5212% Elapsed (wall clock) time (h:mm:ss or m:ss): 1:01.33 jemalloc: Samples: 569K of event 'cycles:ppu', Event count (approx.): 10681965442287 Overhead Shared Object Symbol + 0.55% clang [.] free + 0.41% clang [.] malloc $ /usr/bin/time -v make CC=clang LD=ld.lld -j72 -s Command being timed: "make CC=clang LD=ld.lld -j72 -s" User time (seconds): 2626.97 System time (seconds): 248.37 Percent of CPU this job got: 4774% Elapsed (wall clock) time (h:mm:ss or m:ss): 1:00.22 And these symbols are no longer in the top 20 hottest symbols by cycle count. Replace musl's malloc with jemalloc. Nothing major to write home about, but gives a ~2.5% speedup by cycle count (N=1). Fixes #36
1 parent ba5054b commit 63b584a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm-project/Dockerfile.epoch3

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ RUN wget --no-verbose https://git.kernel.org/torvalds/t/linux-5.18-rc6.tar.gz
55
RUN wget --no-verbose https://musl.libc.org/releases/musl-1.2.3.tar.gz
66
RUN wget --no-verbose https://zlib.net/zlib-1.2.12.tar.gz
77
RUN wget --no-verbose https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.1/llvm-project-14.0.1.src.tar.xz
8+
RUN wget --no-verbose https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2
89

910
FROM ${BASE} AS stage2
1011
FROM docker.io/alpine:edge AS stage3
@@ -60,6 +61,19 @@ RUN make -C ${ZLIB_DIR} -j$(nproc)
6061
RUN make -C ${ZLIB_DIR} -j$(nproc) install
6162
RUN apk del make
6263

64+
### Jemalloc
65+
COPY --from=source jemalloc-5.3.0.tar.bz2 .
66+
RUN tar xf jemalloc-5.3.0.tar.bz2
67+
ARG JEMALLOC_DIR=jemalloc-5.3.0/build
68+
RUN mkdir -p ${JEMALLOC_DIR}
69+
RUN cd ${JEMALLOC_DIR} && \
70+
CC=clang AR=llvm-ar NM=llvm-nm CPPFLAGS=${SYSROOT} LDFLAGS=${SYSROOT} \
71+
../configure --disable-libdl --prefix=/usr
72+
RUN apk add make
73+
RUN make -C ${JEMALLOC_DIR} -j$(nproc) build_lib_static
74+
RUN make -C ${JEMALLOC_DIR} -j$(nproc) DESTDIR=/sysroot install_lib_static
75+
RUN apk del make
76+
6377
### LLVM
6478
COPY --from=source llvm-project-14.0.1.src.tar.xz .
6579
RUN tar xf llvm-project-14.0.1.src.tar.xz && \

llvm-project/stage3.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ set(CMAKE_CXX_FLAGS "--sysroot=/sysroot" CACHE STRING "")
1313
set(CMAKE_C_FLAGS "--sysroot=/sysroot" CACHE STRING "")
1414

1515
# Statically link resulting executable.
16-
set(CMAKE_EXE_LINKER_FLAGS "-static -lc++abi" CACHE STRING "")
16+
set(CMAKE_EXE_LINKER_FLAGS "-static -lc++abi -ljemalloc" CACHE STRING "")
1717

1818
# The compiler builtins are necessary.
1919
set(COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "")

0 commit comments

Comments
 (0)