Skip to content

Commit 27ee09f

Browse files
authored
Merge pull request oneapi-src#941 from ldorau/Link_statically_with_custom_jemalloc_with_disabled_initial_TLS
Link statically with custom jemalloc with disabled initial TLS
2 parents ee03b29 + 614c4b5 commit 27ee09f

36 files changed

+243
-195
lines changed

.github/docker/ubuntu-20.04.Dockerfile

Lines changed: 1 addition & 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

@@ -34,6 +33,7 @@ ARG TEST_DEPS="\
3433

3534
# Miscellaneous for our builds/CI (optional)
3635
ARG MISC_DEPS="\
36+
automake \
3737
clang \
3838
g++-7 \
3939
python3-pip \

.github/docker/ubuntu-22.04.Dockerfile

Lines changed: 1 addition & 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

@@ -34,6 +33,7 @@ ARG TEST_DEPS="\
3433

3534
# Miscellaneous for our builds/CI (optional)
3635
ARG MISC_DEPS="\
36+
automake \
3737
clang \
3838
python3-pip \
3939
sudo \

.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 & 5 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'
@@ -209,7 +209,6 @@ jobs:
209209
--install-dir ${{env.INSTL_DIR}}
210210
--build-type ${{matrix.build_type}}
211211
--disjoint-pool
212-
--jemalloc-pool
213212
${{ matrix.install_tbb == 'ON' && matrix.disable_hwloc != 'ON' && matrix.shared_library == 'ON' && '--proxy' || '' }}
214213
--umf-version ${{env.UMF_VERSION}}
215214
${{ matrix.shared_library == 'ON' && '--shared-library' || '' }}
@@ -300,7 +299,6 @@ jobs:
300299
--install-dir ${{env.INSTL_DIR}}
301300
--build-type ${{matrix.build_type}}
302301
--disjoint-pool
303-
--jemalloc-pool
304302
${{matrix.shared_library == 'ON' && '--proxy' || '' }}
305303
--umf-version ${{env.UMF_VERSION}}
306304
${{ matrix.shared_library == 'ON' && '--shared-library' || ''}}
@@ -469,7 +467,7 @@ jobs:
469467
python3 -m pip install -r third_party/requirements.txt
470468
471469
- name: Install hwloc
472-
run: brew install hwloc jemalloc tbb
470+
run: brew install hwloc tbb automake
473471

474472
- name: Configure build
475473
run: >
@@ -495,7 +493,6 @@ jobs:
495493
--install-dir ${{env.INSTL_DIR}}
496494
--build-type ${{env.BUILD_TYPE}}
497495
--disjoint-pool
498-
--jemalloc-pool
499496
--proxy
500497
--umf-version ${{env.UMF_VERSION}}
501498
--shared-library

.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_multi_numa.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
-DUMF_BUILD_TESTS=ON
4646
-DUMF_DEVELOPER_MODE=ON
4747
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
48-
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
48+
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=${{ matrix.os == 'rhel-9.1' && 'OFF' || 'ON' }}
4949
-DUMF_TESTS_FAIL_ON_SKIP=ON
5050
${{ matrix.build_type == 'Debug' && matrix.os == 'ubuntu-22.04' && '-DUMF_USE_COVERAGE=ON' || '' }}
5151

.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: 92 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,95 @@ else()
111111
message(FATAL_ERROR "Unknown OS type")
112112
endif()
113113

114+
if(NOT UMF_BUILD_LIBUMF_POOL_JEMALLOC)
115+
set(UMF_POOL_JEMALLOC_ENABLED FALSE)
116+
set(JEMALLOC_FOUND FALSE)
117+
set(JEMALLOC_LIBRARIES FALSE)
118+
elseif(WINDOWS)
119+
pkg_check_modules(JEMALLOC jemalloc)
120+
if(NOT JEMALLOC_FOUND)
121+
find_package(JEMALLOC REQUIRED jemalloc)
122+
endif()
123+
else()
124+
if(NOT DEFINED UMF_JEMALLOC_REPO)
125+
set(UMF_JEMALLOC_REPO "https://github.com/jemalloc/jemalloc.git")
126+
endif()
127+
128+
if(NOT DEFINED UMF_JEMALLOC_TAG)
129+
set(UMF_JEMALLOC_TAG 5.3.0)
130+
endif()
131+
132+
include(FetchContent)
133+
message(
134+
STATUS
135+
"Will fetch jemalloc from ${UMF_JEMALLOC_REPO} (tag: ${UMF_JEMALLOC_TAG})"
136+
)
137+
138+
FetchContent_Declare(
139+
jemalloc_targ
140+
GIT_REPOSITORY ${UMF_JEMALLOC_REPO}
141+
GIT_TAG ${UMF_JEMALLOC_TAG})
142+
FetchContent_MakeAvailable(jemalloc_targ)
143+
144+
add_custom_command(
145+
COMMAND ./autogen.sh
146+
WORKING_DIRECTORY ${jemalloc_targ_SOURCE_DIR}
147+
OUTPUT ${jemalloc_targ_SOURCE_DIR}/configure)
148+
add_custom_command(
149+
# Custom jemalloc build. Non-default options used:
150+
# --with-jemalloc-prefix=je_ - add je_ prefix to all public APIs
151+
# --disable-cxx - Disable C++ integration. This will cause new and
152+
# delete operators implementations to be omitted.
153+
# --disable-initial-exec-tls - Disable the initial-exec TLS model for
154+
# jemalloc's internal thread-local storage (on those platforms that
155+
# support explicit settings). This can allow jemalloc to be dynamically
156+
# loaded after program startup (e.g. using dlopen).
157+
COMMAND
158+
./configure --prefix=${jemalloc_targ_BINARY_DIR}
159+
--with-jemalloc-prefix=je_ --disable-cxx --disable-initial-exec-tls
160+
CFLAGS=-fPIC
161+
WORKING_DIRECTORY ${jemalloc_targ_SOURCE_DIR}
162+
OUTPUT ${jemalloc_targ_SOURCE_DIR}/Makefile
163+
DEPENDS ${jemalloc_targ_SOURCE_DIR}/configure)
164+
add_custom_command(
165+
COMMAND make
166+
WORKING_DIRECTORY ${jemalloc_targ_SOURCE_DIR}
167+
OUTPUT ${jemalloc_targ_SOURCE_DIR}/lib/libjemalloc.la
168+
DEPENDS ${jemalloc_targ_SOURCE_DIR}/Makefile)
169+
add_custom_command(
170+
COMMAND make install
171+
WORKING_DIRECTORY ${jemalloc_targ_SOURCE_DIR}
172+
OUTPUT ${jemalloc_targ_BINARY_DIR}/lib/libjemalloc.a
173+
DEPENDS ${jemalloc_targ_SOURCE_DIR}/lib/libjemalloc.la)
174+
175+
add_custom_target(jemalloc_prod
176+
DEPENDS ${jemalloc_targ_BINARY_DIR}/lib/libjemalloc.a)
177+
add_library(jemalloc INTERFACE)
178+
target_link_libraries(
179+
jemalloc INTERFACE ${jemalloc_targ_BINARY_DIR}/lib/libjemalloc.a)
180+
add_dependencies(jemalloc jemalloc_prod)
181+
182+
set(JEMALLOC_LIBRARY_DIRS ${jemalloc_targ_BINARY_DIR}/lib)
183+
set(JEMALLOC_INCLUDE_DIRS ${jemalloc_targ_BINARY_DIR}/include)
184+
set(JEMALLOC_LIBRARIES ${jemalloc_targ_BINARY_DIR}/lib/libjemalloc.a)
185+
endif()
186+
187+
if(JEMALLOC_FOUND OR JEMALLOC_LIBRARIES)
188+
set(UMF_POOL_JEMALLOC_ENABLED TRUE)
189+
# add PATH to DLL on Windows
190+
set(DLL_PATH_LIST
191+
"${DLL_PATH_LIST};PATH=path_list_append:${JEMALLOC_DLL_DIRS}")
192+
message(STATUS " JEMALLOC_LIBRARIES = ${JEMALLOC_LIBRARIES}")
193+
message(STATUS " JEMALLOC_INCLUDE_DIRS = ${JEMALLOC_INCLUDE_DIRS}")
194+
message(STATUS " JEMALLOC_LIBRARY_DIRS = ${JEMALLOC_LIBRARY_DIRS}")
195+
else()
196+
set(UMF_POOL_JEMALLOC_ENABLED FALSE)
197+
message(
198+
STATUS
199+
"Disabling the Jemalloc Pool and tests and benchmarks that use it because jemalloc was not built/found."
200+
)
201+
endif()
202+
114203
if(UMF_DISABLE_HWLOC)
115204
message(STATUS "hwloc is disabled, hence OS provider, memtargets, "
116205
"topology discovery, examples won't be available!")
@@ -402,19 +491,6 @@ else()
402491
set(UMF_POOL_SCALABLE_ENABLED FALSE)
403492
endif()
404493

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-
418494
if(WINDOWS)
419495
# TODO: enable the proxy library in the Debug build on Windows
420496
#
@@ -455,14 +531,14 @@ elseif(UMF_PROXY_LIB_BASED_ON_POOL STREQUAL SCALABLE)
455531
)
456532
endif()
457533
elseif(UMF_PROXY_LIB_BASED_ON_POOL STREQUAL JEMALLOC)
458-
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
534+
if(UMF_POOL_JEMALLOC_ENABLED)
459535
set(UMF_PROXY_LIB_ENABLED ON)
460536
set(PROXY_LIB_USES_JEMALLOC_POOL ON)
461-
set(PROXY_LIBS jemalloc_pool umf)
537+
set(PROXY_LIBS umf)
462538
else()
463539
message(
464540
STATUS
465-
"Disabling the proxy library, because UMF_PROXY_LIB_BASED_ON_POOL==JEMALLOC but UMF_BUILD_LIBUMF_POOL_JEMALLOC is OFF"
541+
"Disabling the proxy library, because UMF_PROXY_LIB_BASED_ON_POOL==JEMALLOC but the jemalloc pool is disabled"
466542
)
467543
endif()
468544
else()

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,26 @@ pool manager built as a separate static library: libjemalloc_pool.a on Linux and
281281
jemalloc_pool.lib on Windows.
282282
The `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option has to be turned `ON` to build this library.
283283

284+
[jemalloc](https://github.com/jemalloc/jemalloc) is required to build the jemalloc pool.
285+
286+
In case of Linux OS jemalloc is built from the (fetched) sources with the following
287+
non-default options enabled:
288+
- `--with-jemalloc-prefix=je_` - adds the `je_` prefix to all public APIs,
289+
- `--disable-cxx` - disables C++ integration, it will cause the `new` and the `delete`
290+
operators implementations to be omitted.
291+
- `--disable-initial-exec-tls` - disables the initial-exec TLS model for jemalloc's
292+
internal thread-local storage (on those platforms that support
293+
explicit settings), it can allow jemalloc to be dynamically
294+
loaded after program startup (e.g. using `dlopen()`).
295+
296+
The default jemalloc package is required on Windows.
297+
284298
##### Requirements
285299

286300
1) The `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option turned `ON`
287-
2) Required packages:
288-
- libjemalloc-dev (Linux) or jemalloc (Windows)
301+
2) jemalloc is required:
302+
- on Linux and MacOS: jemalloc is fetched and built from sources (a custom build),
303+
- on Windows: the default jemalloc package is required
289304

290305
#### Scalable Pool (part of libumf)
291306

benchmark/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function(add_umf_benchmark)
5151

5252
set(BENCH_NAME umf-${ARG_NAME})
5353

54-
set(BENCH_LIBS ${ARG_LIBS} umf)
54+
set(BENCH_LIBS ${ARG_LIBS} umf umf_utils)
5555

5656
add_umf_executable(
5757
NAME ${BENCH_NAME}
@@ -121,8 +121,7 @@ set(LIB_DIRS ${LIBHWLOC_LIBRARY_DIRS})
121121
if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
122122
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} disjoint_pool)
123123
endif()
124-
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
125-
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} jemalloc_pool ${JEMALLOC_LIBRARIES})
124+
if(UMF_POOL_JEMALLOC_ENABLED)
126125
set(LIB_DIRS ${LIB_DIRS} ${JEMALLOC_LIBRARY_DIRS})
127126
endif()
128127
if(LINUX)

benchmark/multithread.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ int main() {
139139
// ctest looks for "PASSED" in the output
140140
std::cout << "PASSED" << std::endl;
141141

142+
#if defined(UMF_POOL_DISJOINT_ENABLED)
142143
ret = umfDisjointPoolParamsDestroy(hDisjointParams);
143144
if (ret != UMF_RESULT_SUCCESS) {
144145
std::cerr << "disjoint pool params destroy failed" << std::endl;
145146
return -1;
146147
}
148+
#endif
147149

148150
return 0;
149151
}

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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,13 @@ if(LINUX)
282282
add_umf_executable(
283283
NAME ${EXAMPLE_NAME}
284284
SRCS dram_and_fsdax/dram_and_fsdax.c
285-
LIBS umf jemalloc_pool)
285+
LIBS umf)
286286

287-
target_link_directories(${EXAMPLE_NAME} PRIVATE
288-
${LIBHWLOC_LIBRARY_DIRS})
287+
target_link_options(${EXAMPLE_NAME} PRIVATE "-Wl,--no-as-needed,-ldl")
288+
289+
target_link_directories(
290+
${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS}
291+
${JEMALLOC_LIBRARY_DIRS})
289292

290293
add_test(
291294
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)

0 commit comments

Comments
 (0)