Skip to content

Commit f737d1b

Browse files
committed
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc built from sources with the following options enabled: --with-jemalloc-prefix=je_ --disable-initial-exec-tls Fixes: oneapi-src#891 Fixes: oneapi-src#894 Fixes: oneapi-src#903 Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
1 parent 63746a3 commit f737d1b

27 files changed

+124
-137
lines changed

.github/docker/ubuntu-20.04.Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ ARG BASE_DEPS="\
2424

2525
# UMF's dependencies
2626
ARG UMF_DEPS="\
27-
libjemalloc-dev \
2827
libhwloc-dev \
2928
libtbb-dev"
3029

.github/docker/ubuntu-22.04.Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ ARG BASE_DEPS="\
2424

2525
# UMF's dependencies
2626
ARG UMF_DEPS="\
27-
libjemalloc-dev \
2827
libhwloc-dev \
2928
libtbb-dev"
3029

.github/workflows/coverity.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Install apt packages
3232
run: |
3333
sudo apt-get update
34-
sudo apt-get install -y cmake hwloc libhwloc-dev libjemalloc-dev libnuma-dev libtbb-dev
34+
sudo apt-get install -y cmake hwloc libhwloc-dev libnuma-dev libtbb-dev
3535
3636
- name: Download Coverity
3737
run: |

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
- name: Install apt packages
6868
run: |
6969
sudo apt-get update
70-
sudo apt-get install -y cmake hwloc libhwloc-dev libjemalloc-dev libnuma-dev libtbb-dev valgrind
70+
sudo apt-get install -y cmake hwloc libhwloc-dev libnuma-dev libtbb-dev valgrind
7171
7272
- name: Configure CMake
7373
run: >

.github/workflows/reusable_basic.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
- name: Install apt packages
125125
run: |
126126
sudo apt-get update
127-
sudo apt-get install -y clang cmake libnuma-dev libjemalloc-dev lcov
127+
sudo apt-get install -y clang cmake libnuma-dev lcov
128128
129129
- name: Install TBB apt package
130130
if: matrix.install_tbb == 'ON'
@@ -469,7 +469,7 @@ jobs:
469469
python3 -m pip install -r third_party/requirements.txt
470470
471471
- name: Install hwloc
472-
run: brew install hwloc jemalloc tbb
472+
run: brew install hwloc tbb automake
473473

474474
- name: Configure build
475475
run: >

.github/workflows/reusable_benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
if: matrix.os == 'ubuntu-latest'
3535
run: |
3636
sudo apt-get update
37-
sudo apt-get install -y cmake libhwloc-dev libnuma-dev libjemalloc-dev libtbb-dev
37+
sudo apt-get install -y cmake libhwloc-dev libnuma-dev libtbb-dev
3838
3939
- name: Initialize vcpkg
4040
if: matrix.os == 'windows-latest'

.github/workflows/reusable_codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
if: matrix.os == 'ubuntu-latest'
6363
run: |
6464
sudo apt-get update
65-
sudo apt-get install -y cmake clang libhwloc-dev libnuma-dev libjemalloc-dev libtbb-dev
65+
sudo apt-get install -y cmake clang libhwloc-dev libnuma-dev libtbb-dev
6666
6767
# Latest distros do not allow global pip installation
6868
- name: "[Lin] Install Python requirements in venv"

.github/workflows/reusable_fast.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ jobs:
7979
if: matrix.os == 'ubuntu-latest'
8080
run: |
8181
sudo apt-get update
82-
sudo apt-get install -y cmake libjemalloc-dev libhwloc-dev libnuma-dev libtbb-dev
82+
sudo apt-get install -y cmake libhwloc-dev libnuma-dev libtbb-dev
8383
8484
- name: Install dependencies (ubuntu-20.04)
8585
if: matrix.os == 'ubuntu-20.04'
8686
run: |
8787
sudo apt-get update
88-
sudo apt-get install -y cmake libjemalloc-dev libnuma-dev libtbb-dev
88+
sudo apt-get install -y cmake libnuma-dev libtbb-dev
8989
.github/scripts/install_hwloc.sh # install hwloc-2.3.0 instead of hwloc-2.1.0 present in the OS package
9090
9191
- name: Set ptrace value for IPC test (on Linux only)

.github/workflows/reusable_proxy_lib.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Install apt packages
3333
run: |
3434
sudo apt-get update
35-
sudo apt-get install -y cmake libhwloc-dev libjemalloc-dev libtbb-dev lcov
35+
sudo apt-get install -y cmake libhwloc-dev libtbb-dev lcov
3636
3737
- name: Set ptrace value for IPC test
3838
run: sudo bash -c "echo 0 > /proc/sys/kernel/yama/ptrace_scope"

.github/workflows/reusable_sanitizers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install apt packages
3030
run: |
3131
sudo apt-get update
32-
sudo apt-get install -y clang cmake libhwloc-dev libnuma-dev libjemalloc-dev libtbb-dev
32+
sudo apt-get install -y clang cmake libhwloc-dev libnuma-dev libtbb-dev
3333
3434
- name: Install oneAPI basekit
3535
if: matrix.compiler.cxx == 'icpx'

.github/workflows/reusable_valgrind.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install apt packages
2121
run: |
2222
sudo apt-get update
23-
sudo apt-get install -y cmake hwloc libhwloc-dev libjemalloc-dev libnuma-dev libtbb-dev valgrind
23+
sudo apt-get install -y cmake hwloc libhwloc-dev libnuma-dev libtbb-dev valgrind
2424
2525
- name: Configure CMake
2626
run: >

CMakeLists.txt

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,79 @@ else()
111111
message(FATAL_ERROR "Unknown OS type")
112112
endif()
113113

114+
if(NOT UMF_BUILD_LIBUMF_POOL_JEMALLOC)
115+
message(STATUS "jemalloc is disabled")
116+
elseif(WINDOWS)
117+
pkg_check_modules(JEMALLOC jemalloc)
118+
if(NOT JEMALLOC_FOUND)
119+
find_package(JEMALLOC REQUIRED jemalloc)
120+
endif()
121+
else()
122+
if(NOT DEFINED UMF_JEMALLOC_REPO)
123+
set(UMF_JEMALLOC_REPO "https://github.com/jemalloc/jemalloc.git")
124+
endif()
125+
126+
if(NOT DEFINED UMF_JEMALLOC_TAG)
127+
set(UMF_JEMALLOC_TAG 5.3.0)
128+
endif()
129+
130+
include(FetchContent)
131+
message(
132+
STATUS
133+
"Will fetch jemalloc from ${UMF_JEMALLOC_REPO} (tag: ${UMF_JEMALLOC_TAG})"
134+
)
135+
136+
FetchContent_Declare(
137+
jemalloc_targ
138+
GIT_REPOSITORY ${UMF_JEMALLOC_REPO}
139+
GIT_TAG ${UMF_JEMALLOC_TAG})
140+
FetchContent_MakeAvailable(jemalloc_targ)
141+
142+
add_custom_command(
143+
COMMAND ./autogen.sh
144+
WORKING_DIRECTORY ${jemalloc_targ_SOURCE_DIR}
145+
OUTPUT ${jemalloc_targ_SOURCE_DIR}/configure)
146+
add_custom_command(
147+
COMMAND
148+
./configure --prefix=${jemalloc_targ_BINARY_DIR}
149+
--with-jemalloc-prefix=je_ --disable-initial-exec-tls CFLAGS=-fPIC
150+
CXXFLAGS=-fPIC
151+
WORKING_DIRECTORY ${jemalloc_targ_SOURCE_DIR}
152+
OUTPUT ${jemalloc_targ_SOURCE_DIR}/Makefile
153+
DEPENDS ${jemalloc_targ_SOURCE_DIR}/configure)
154+
add_custom_command(
155+
COMMAND make
156+
WORKING_DIRECTORY ${jemalloc_targ_SOURCE_DIR}
157+
OUTPUT ${jemalloc_targ_SOURCE_DIR}/lib/libjemalloc.la
158+
DEPENDS ${jemalloc_targ_SOURCE_DIR}/Makefile)
159+
add_custom_command(
160+
COMMAND make install
161+
WORKING_DIRECTORY ${jemalloc_targ_SOURCE_DIR}
162+
OUTPUT ${jemalloc_targ_BINARY_DIR}/lib/libjemalloc.a
163+
DEPENDS ${jemalloc_targ_SOURCE_DIR}/lib/libjemalloc.la)
164+
165+
add_custom_target(jemalloc_prod
166+
DEPENDS ${jemalloc_targ_BINARY_DIR}/lib/libjemalloc.a)
167+
add_library(jemalloc INTERFACE)
168+
target_link_libraries(
169+
jemalloc INTERFACE ${jemalloc_targ_BINARY_DIR}/lib/libjemalloc.a)
170+
add_dependencies(jemalloc jemalloc_prod)
171+
172+
set(JEMALLOC_LIBRARY_DIRS ${jemalloc_targ_BINARY_DIR}/lib)
173+
set(JEMALLOC_INCLUDE_DIRS ${jemalloc_targ_BINARY_DIR}/include)
174+
set(JEMALLOC_LIBRARIES ${jemalloc_targ_BINARY_DIR}/lib/libjemalloc.a)
175+
endif()
176+
177+
if(JEMALLOC_FOUND OR JEMALLOC_LIBRARIES)
178+
set(UMF_POOL_JEMALLOC_ENABLED TRUE)
179+
# add PATH to DLL on Windows
180+
set(DLL_PATH_LIST
181+
"${DLL_PATH_LIST};PATH=path_list_append:${JEMALLOC_DLL_DIRS}")
182+
message(STATUS " JEMALLOC_LIBRARIES = ${JEMALLOC_LIBRARIES}")
183+
message(STATUS " JEMALLOC_INCLUDE_DIRS = ${JEMALLOC_INCLUDE_DIRS}")
184+
message(STATUS " JEMALLOC_LIBRARY_DIRS = ${JEMALLOC_LIBRARY_DIRS}")
185+
endif()
186+
114187
if(UMF_DISABLE_HWLOC)
115188
message(STATUS "hwloc is disabled, hence OS provider, memtargets, "
116189
"topology discovery, examples won't be available!")
@@ -402,19 +475,6 @@ else()
402475
set(UMF_POOL_SCALABLE_ENABLED FALSE)
403476
endif()
404477

405-
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
406-
pkg_check_modules(JEMALLOC jemalloc)
407-
if(NOT JEMALLOC_FOUND)
408-
find_package(JEMALLOC REQUIRED jemalloc)
409-
endif()
410-
if(JEMALLOC_FOUND OR JEMALLOC_LIBRARIES)
411-
set(UMF_POOL_JEMALLOC_ENABLED TRUE)
412-
# add PATH to DLL on Windows
413-
set(DLL_PATH_LIST
414-
"${DLL_PATH_LIST};PATH=path_list_append:${JEMALLOC_DLL_DIRS}")
415-
endif()
416-
endif()
417-
418478
if(WINDOWS)
419479
# TODO: enable the proxy library in the Debug build on Windows
420480
#

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ The `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option has to be turned `ON` to build this
262262

263263
1) The `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option turned `ON`
264264
2) Required packages:
265-
- libjemalloc-dev (Linux) or jemalloc (Windows)
265+
- jemalloc (Windows only)
266266

267267
#### Scalable Pool (part of libumf)
268268

benchmark/ubench.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ static void do_ipc_get_put_benchmark(alloc_t *allocs, size_t num_allocs,
445445
}
446446
}
447447

448-
int create_level_zero_params(ze_context_handle_t *context,
449-
ze_device_handle_t *device) {
448+
static int create_level_zero_params(ze_context_handle_t *context,
449+
ze_device_handle_t *device) {
450450
uint32_t driver_idx = 0;
451451
ze_driver_handle_t driver = NULL;
452452

examples/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,11 @@ if(LINUX)
282282
SRCS dram_and_fsdax/dram_and_fsdax.c
283283
LIBS umf jemalloc_pool)
284284

285-
target_link_directories(${EXAMPLE_NAME} PRIVATE
286-
${LIBHWLOC_LIBRARY_DIRS})
285+
target_link_options(${EXAMPLE_NAME} PRIVATE "-Wl,--no-as-needed,-ldl")
286+
287+
target_link_directories(
288+
${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS}
289+
${JEMALLOC_LIBRARY_DIRS})
287290

288291
add_test(
289292
NAME ${EXAMPLE_NAME}

examples/cmake/FindJEMALLOC.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
message(STATUS "Checking for module 'jemalloc' using find_library()")
5+
message(
6+
STATUS "Looking for the static 'libjemalloc.a' library using find_library()"
7+
)
68

7-
find_library(JEMALLOC_LIBRARY NAMES libjemalloc jemalloc)
9+
find_library(JEMALLOC_LIBRARY NAMES libjemalloc.a jemalloc.a)
810
set(JEMALLOC_LIBRARIES ${JEMALLOC_LIBRARY})
911

1012
get_filename_component(JEMALLOC_LIB_DIR ${JEMALLOC_LIBRARIES} DIRECTORY)

examples/dram_and_fsdax/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ if(NOT LIBHWLOC_FOUND)
2121
find_package(LIBHWLOC 2.3.0 REQUIRED hwloc)
2222
endif()
2323

24-
pkg_check_modules(JEMALLOC jemalloc)
25-
if(NOT JEMALLOC_FOUND)
26-
find_package(JEMALLOC REQUIRED jemalloc)
27-
endif()
24+
# find the custom jemalloc pointed by CMAKE_PREFIX_PATH
25+
find_package(JEMALLOC REQUIRED jemalloc)
2826

2927
# build the example
3028
set(EXAMPLE_NAME umf_example_dram_and_fsdax)

scripts/qemu/run-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pwd
1414

1515
echo password | sudo -Sk apt-get update
1616
echo password | sudo -Sk apt-get install -y git cmake gcc g++ pkg-config \
17-
numactl libnuma-dev hwloc libhwloc-dev libjemalloc-dev libtbb-dev valgrind lcov
17+
numactl libnuma-dev hwloc libhwloc-dev libtbb-dev valgrind lcov
1818

1919
mkdir build
2020
cd build

src/pool/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
4545
NAME jemalloc_pool
4646
TYPE STATIC
4747
SRCS pool_jemalloc.c ${POOL_EXTRA_SRCS}
48-
LIBS jemalloc ${POOL_EXTRA_LIBS})
48+
LIBS ${JEMALLOC_LIBRARIES} ${POOL_EXTRA_LIBS})
4949
target_include_directories(jemalloc_pool PRIVATE ${JEMALLOC_INCLUDE_DIRS})
5050
target_compile_definitions(jemalloc_pool
5151
PRIVATE ${POOL_COMPILE_DEFINITIONS})
5252
add_library(${PROJECT_NAME}::jemalloc_pool ALIAS jemalloc_pool)
53+
if(NOT WINDOWS)
54+
add_dependencies(jemalloc_pool jemalloc)
55+
endif()
5356
install(TARGETS jemalloc_pool EXPORT ${PROJECT_NAME}-targets)
5457
endif()

src/pool/pool_jemalloc.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@
2222

2323
#include <jemalloc/jemalloc.h>
2424

25-
// The Windows version of jemalloc uses API with je_ prefix,
26-
// while the Linux one does not.
27-
#ifndef _WIN32
28-
#define je_mallocx mallocx
29-
#define je_dallocx dallocx
30-
#define je_rallocx rallocx
31-
#define je_mallctl mallctl
32-
#define je_malloc_usable_size malloc_usable_size
33-
#endif
34-
3525
#define MALLOCX_ARENA_MAX (MALLCTL_ARENAS_ALL - 1)
3626

3727
typedef struct jemalloc_memory_pool_t {

test/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,13 @@ if(LINUX
749749
set(STANDALONE_CMAKE_OPTIONS
750750
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
751751
)
752+
if(JEMALLOC_INCLUDE_DIRS)
753+
# add custom jemalloc installation
754+
set(STANDALONE_CMAKE_OPTIONS
755+
"${STANDALONE_CMAKE_OPTIONS} -DCMAKE_PREFIX_PATH=${JEMALLOC_INCLUDE_DIRS}/../"
756+
)
757+
endif()
758+
752759
add_test(
753760
NAME umf-standalone_examples
754761
COMMAND

test/supp/drd-umf_test-jemalloc_coarse_devdax.supp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
11
{
2-
False-positive ConflictingAccess in libjemalloc.so
2+
False-positive ConflictingAccess in jemalloc
33
drd:ConflictingAccess
4-
obj:*/libjemalloc.so*
54
...
6-
fun:mallocx
7-
...
8-
}
9-
10-
{
11-
False-positive ConflictingAccess in libjemalloc.so
12-
drd:ConflictingAccess
13-
obj:*/libjemalloc.so*
14-
...
15-
fun:op_free
16-
...
17-
}
18-
19-
{
20-
False-positive ConflictingAccess in libjemalloc.so
21-
drd:ConflictingAccess
22-
obj:*/libjemalloc.so*
23-
...
24-
fun:__nptl_deallocate_tsd
5+
fun:je_*
256
...
267
}
278

test/supp/drd-umf_test-jemalloc_coarse_file.supp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
11
{
2-
False-positive ConflictingAccess in libjemalloc.so
2+
False-positive ConflictingAccess in jemalloc
33
drd:ConflictingAccess
4-
obj:*/libjemalloc.so*
54
...
6-
fun:mallocx
7-
...
8-
}
9-
10-
{
11-
False-positive ConflictingAccess in libjemalloc.so
12-
drd:ConflictingAccess
13-
obj:*/libjemalloc.so*
14-
...
15-
fun:op_free
16-
...
17-
}
18-
19-
{
20-
False-positive ConflictingAccess in libjemalloc.so
21-
drd:ConflictingAccess
22-
obj:*/libjemalloc.so*
23-
...
24-
fun:__nptl_deallocate_tsd
5+
fun:je_*
256
...
267
}
278

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
Conflicting Access in libjemalloc.so - internal issue of libjemalloc
2+
False-positive ConflictingAccess in jemalloc
33
drd:ConflictingAccess
4-
obj:*libjemalloc.so*
4+
...
5+
fun:je_*
56
...
67
}

0 commit comments

Comments
 (0)