Skip to content

Commit 003075f

Browse files
committed
Incorporate jemalloc_pool into libumf
Remove the separate static `jemalloc_pool` library. Make the `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option turned ON by default. Incorporate jemalloc_pool into libumf. Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
1 parent e95d92e commit 003075f

17 files changed

+101
-65
lines changed

.github/workflows/reusable_basic.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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' || ''}}
@@ -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

CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ endif()
113113

114114
if(NOT UMF_BUILD_LIBUMF_POOL_JEMALLOC)
115115
set(UMF_POOL_JEMALLOC_ENABLED FALSE)
116+
set(JEMALLOC_FOUND FALSE)
117+
set(JEMALLOC_LIBRARIES FALSE)
116118
elseif(WINDOWS)
117119
pkg_check_modules(JEMALLOC jemalloc)
118120
if(NOT JEMALLOC_FOUND)
@@ -190,6 +192,12 @@ if(JEMALLOC_FOUND OR JEMALLOC_LIBRARIES)
190192
message(STATUS " JEMALLOC_LIBRARIES = ${JEMALLOC_LIBRARIES}")
191193
message(STATUS " JEMALLOC_INCLUDE_DIRS = ${JEMALLOC_INCLUDE_DIRS}")
192194
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+
)
193201
endif()
194202

195203
if(UMF_DISABLE_HWLOC)
@@ -523,14 +531,14 @@ elseif(UMF_PROXY_LIB_BASED_ON_POOL STREQUAL SCALABLE)
523531
)
524532
endif()
525533
elseif(UMF_PROXY_LIB_BASED_ON_POOL STREQUAL JEMALLOC)
526-
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
534+
if(UMF_POOL_JEMALLOC_ENABLED)
527535
set(UMF_PROXY_LIB_ENABLED ON)
528536
set(PROXY_LIB_USES_JEMALLOC_POOL ON)
529-
set(PROXY_LIBS jemalloc_pool umf)
537+
set(PROXY_LIBS umf)
530538
else()
531539
message(
532540
STATUS
533-
"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"
534542
)
535543
endif()
536544
else()

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ The default jemalloc package is required on Windows.
298298
##### Requirements
299299

300300
1) The `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option turned `ON`
301-
2) Required packages:
302-
- jemalloc (Windows only)
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
303304

304305
#### Scalable Pool (part of libumf)
305306

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
}

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ 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

287287
target_link_options(${EXAMPLE_NAME} PRIVATE "-Wl,--no-as-needed,-ldl")
288288

examples/dram_and_fsdax/CMakeLists.txt

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

24-
# find the custom jemalloc pointed by CMAKE_PREFIX_PATH
25-
find_package(JEMALLOC REQUIRED jemalloc)
26-
2724
# build the example
2825
set(EXAMPLE_NAME umf_example_dram_and_fsdax)
2926
add_executable(${EXAMPLE_NAME} dram_and_fsdax.c)
3027
target_include_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_INCLUDE_DIRS})
3128

32-
target_link_directories(
33-
${EXAMPLE_NAME}
34-
PRIVATE
35-
${LIBUMF_LIBRARY_DIRS}
36-
${LIBHWLOC_LIBRARY_DIRS}
37-
${JEMALLOC_LIBRARY_DIRS})
29+
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARY_DIRS}
30+
${LIBHWLOC_LIBRARY_DIRS})
3831

39-
target_link_libraries(
40-
${EXAMPLE_NAME} PRIVATE hwloc jemalloc_pool ${JEMALLOC_LIBRARIES}
41-
${LIBUMF_LIBRARIES})
32+
target_link_libraries(${EXAMPLE_NAME} PRIVATE hwloc ${LIBUMF_LIBRARIES})
4233

4334
# an optional part - adds a test of this example
4435
add_test(
@@ -54,6 +45,6 @@ if(LINUX)
5445
TEST ${EXAMPLE_NAME}
5546
PROPERTY
5647
ENVIRONMENT_MODIFICATION
57-
"LD_LIBRARY_PATH=path_list_append:${LIBUMF_LIBRARY_DIRS};LD_LIBRARY_PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS};LD_LIBRARY_PATH=path_list_append:${JEMALLOC_LIBRARY_DIRS}"
48+
"LD_LIBRARY_PATH=path_list_append:${LIBUMF_LIBRARY_DIRS};LD_LIBRARY_PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}"
5849
)
5950
endif()

scripts/qemu/run-build.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ cmake .. \
2626
-DUMF_FORMAT_CODE_STYLE=OFF \
2727
-DUMF_DEVELOPER_MODE=ON \
2828
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON \
29-
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON \
3029
-DUMF_BUILD_EXAMPLES=ON \
3130
-DUMF_USE_COVERAGE=${COVERAGE} \
3231
-DUMF_TESTS_FAIL_ON_SKIP=ON

src/CMakeLists.txt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,19 @@ set(UMF_SOURCES
6969
critnib/critnib.c
7070
ravl/ravl.c
7171
pool/pool_proxy.c
72+
pool/pool_jemalloc.c
7273
pool/pool_scalable.c)
7374

75+
if(UMF_POOL_JEMALLOC_ENABLED)
76+
set(UMF_LIBS ${UMF_LIBS} ${JEMALLOC_LIBRARIES})
77+
set(UMF_PRIVATE_LIBRARY_DIRS ${UMF_PRIVATE_LIBRARY_DIRS}
78+
${JEMALLOC_LIBRARY_DIRS})
79+
set(UMF_PRIVATE_INCLUDE_DIRS ${UMF_PRIVATE_INCLUDE_DIRS}
80+
${JEMALLOC_INCLUDE_DIRS})
81+
set(UMF_COMMON_COMPILE_DEFINITIONS ${UMF_COMMON_COMPILE_DEFINITIONS}
82+
"UMF_POOL_JEMALLOC_ENABLED=1")
83+
endif()
84+
7485
if(NOT UMF_DISABLE_HWLOC)
7586
set(UMF_SOURCES ${UMF_SOURCES} ${HWLOC_DEPENDENT_SOURCES}
7687
memtargets/memtarget_numa.c)
@@ -146,15 +157,19 @@ else()
146157
LIBS ${UMF_LIBS})
147158
endif()
148159

160+
target_include_directories(umf PRIVATE ${UMF_PRIVATE_INCLUDE_DIRS})
161+
target_link_directories(umf PRIVATE ${UMF_PRIVATE_LIBRARY_DIRS})
162+
target_compile_definitions(umf PRIVATE ${UMF_COMMON_COMPILE_DEFINITIONS})
163+
149164
add_dependencies(umf coarse)
150165

151166
if(UMF_LINK_HWLOC_STATICALLY)
152167
add_dependencies(umf ${UMF_HWLOC_NAME})
153168
endif()
154169

155-
target_link_directories(umf PRIVATE ${UMF_PRIVATE_LIBRARY_DIRS})
156-
157-
target_compile_definitions(umf PRIVATE ${UMF_COMMON_COMPILE_DEFINITIONS})
170+
if(NOT WINDOWS AND UMF_POOL_JEMALLOC_ENABLED)
171+
add_dependencies(umf jemalloc)
172+
endif()
158173

159174
if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
160175
if(LINUX)

src/libumf.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ EXPORTS
3636
umfFileMemoryProviderParamsSetVisibility
3737
umfGetIPCHandle
3838
umfGetLastFailedMemoryProvider
39+
umfJemallocPoolOps
40+
umfJemallocPoolParamsCreate
41+
umfJemallocPoolParamsDestroy
42+
umfJemallocPoolParamsSetKeepAllMemory
3943
umfLevelZeroMemoryProviderOps
4044
umfLevelZeroMemoryProviderParamsCreate
4145
umfLevelZeroMemoryProviderParamsDestroy

src/libumf.map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ UMF_1.0 {
3030
umfFileMemoryProviderParamsSetVisibility;
3131
umfGetIPCHandle;
3232
umfGetLastFailedMemoryProvider;
33+
umfJemallocPoolOps;
34+
umfJemallocPoolParamsCreate;
35+
umfJemallocPoolParamsDestroy;
36+
umfJemallocPoolParamsSetKeepAllMemory;
3337
umfLevelZeroMemoryProviderOps;
3438
umfLevelZeroMemoryProviderParamsCreate;
3539
umfLevelZeroMemoryProviderParamsDestroy;

src/pool/CMakeLists.txt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,3 @@ if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
3838

3939
install(TARGETS disjoint_pool EXPORT ${PROJECT_NAME}-targets)
4040
endif()
41-
42-
# libumf_pool_jemalloc
43-
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
44-
add_umf_library(
45-
NAME jemalloc_pool
46-
TYPE STATIC
47-
SRCS pool_jemalloc.c ${POOL_EXTRA_SRCS}
48-
LIBS ${JEMALLOC_LIBRARIES} ${POOL_EXTRA_LIBS})
49-
target_include_directories(jemalloc_pool PRIVATE ${JEMALLOC_INCLUDE_DIRS})
50-
target_compile_definitions(jemalloc_pool
51-
PRIVATE ${POOL_COMPILE_DEFINITIONS})
52-
add_library(${PROJECT_NAME}::jemalloc_pool ALIAS jemalloc_pool)
53-
if(NOT WINDOWS)
54-
add_dependencies(jemalloc_pool jemalloc)
55-
endif()
56-
install(TARGETS jemalloc_pool EXPORT ${PROJECT_NAME}-targets)
57-
endif()

src/pool/pool_jemalloc.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,32 @@
2020
#include <umf/memory_pool_ops.h>
2121
#include <umf/pools/pool_jemalloc.h>
2222

23+
#ifndef UMF_POOL_JEMALLOC_ENABLED
24+
25+
umf_memory_pool_ops_t *umfJemallocPoolOps(void) { return NULL; }
26+
27+
umf_result_t
28+
umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams) {
29+
(void)hParams; // unused
30+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
31+
}
32+
33+
umf_result_t
34+
umfJemallocPoolParamsDestroy(umf_jemalloc_pool_params_handle_t hParams) {
35+
(void)hParams; // unused
36+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
37+
}
38+
39+
umf_result_t
40+
umfJemallocPoolParamsSetKeepAllMemory(umf_jemalloc_pool_params_handle_t hParams,
41+
bool keepAllMemory) {
42+
(void)hParams; // unused
43+
(void)keepAllMemory; // unused
44+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
45+
}
46+
47+
#else
48+
2349
#include <jemalloc/jemalloc.h>
2450

2551
#define MALLOCX_ARENA_MAX (MALLCTL_ARENAS_ALL - 1)
@@ -535,3 +561,4 @@ static umf_memory_pool_ops_t UMF_JEMALLOC_POOL_OPS = {
535561
umf_memory_pool_ops_t *umfJemallocPoolOps(void) {
536562
return &UMF_JEMALLOC_POOL_OPS;
537563
}
564+
#endif /* UMF_POOL_JEMALLOC_ENABLED */

test/CMakeLists.txt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ if(UMF_BUILD_SHARED_LIBRARY)
165165
endif()
166166
endif()
167167

168-
if(UMF_POOL_JEMALLOC_ENABLED)
169-
set(LIB_JEMALLOC_POOL jemalloc_pool)
170-
endif()
171-
172168
if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
173169
set(LIB_DISJOINT_POOL disjoint_pool)
174170
endif()
@@ -236,14 +232,15 @@ if(UMF_BUILD_LIBUMF_POOL_DISJOINT
236232
add_umf_test(
237233
NAME c_api_multi_pool
238234
SRCS c_api/multi_pool.c
239-
LIBS disjoint_pool jemalloc_pool ${JEMALLOC_LIBRARIES})
235+
LIBS disjoint_pool)
240236
endif()
241237

242238
if(UMF_POOL_JEMALLOC_ENABLED AND (NOT UMF_DISABLE_HWLOC))
243239
add_umf_test(
244240
NAME jemalloc_pool
245241
SRCS pools/jemalloc_pool.cpp malloc_compliance_tests.cpp
246-
LIBS jemalloc_pool)
242+
${BA_SOURCES_FOR_TEST}
243+
LIBS ${UMF_UTILS_FOR_TEST})
247244
endif()
248245

249246
if(UMF_POOL_SCALABLE_ENABLED AND (NOT UMF_DISABLE_HWLOC))
@@ -266,7 +263,7 @@ if(LINUX AND (NOT UMF_DISABLE_HWLOC)) # OS-specific functions are implemented
266263
add_umf_test(
267264
NAME provider_os_memory
268265
SRCS provider_os_memory.cpp ${BA_SOURCES_FOR_TEST}
269-
LIBS ${UMF_UTILS_FOR_TEST} ${LIB_JEMALLOC_POOL} ${LIB_DISJOINT_POOL})
266+
LIBS ${UMF_UTILS_FOR_TEST} ${LIB_DISJOINT_POOL})
270267
add_umf_test(
271268
NAME provider_os_memory_multiple_numa_nodes
272269
SRCS provider_os_memory_multiple_numa_nodes.cpp
@@ -314,26 +311,28 @@ if(LINUX AND (NOT UMF_DISABLE_HWLOC)) # OS-specific functions are implemented
314311
add_umf_test(
315312
NAME provider_devdax_memory_ipc
316313
SRCS provider_devdax_memory_ipc.cpp ${BA_SOURCES_FOR_TEST}
317-
LIBS ${UMF_UTILS_FOR_TEST} ${LIB_JEMALLOC_POOL})
314+
LIBS ${UMF_UTILS_FOR_TEST})
318315
add_umf_test(
319316
NAME provider_file_memory
320317
SRCS provider_file_memory.cpp
321318
LIBS ${UMF_UTILS_FOR_TEST})
322319
add_umf_test(
323320
NAME provider_file_memory_ipc
324321
SRCS provider_file_memory_ipc.cpp ${BA_SOURCES_FOR_TEST}
325-
LIBS ${UMF_UTILS_FOR_TEST} ${LIB_JEMALLOC_POOL})
322+
LIBS ${UMF_UTILS_FOR_TEST})
326323

327324
# This test requires Linux-only file memory provider
328325
if(UMF_POOL_JEMALLOC_ENABLED)
329326
add_umf_test(
330327
NAME jemalloc_coarse_file
331328
SRCS pools/jemalloc_coarse_file.cpp malloc_compliance_tests.cpp
332-
LIBS jemalloc_pool)
329+
${BA_SOURCES_FOR_TEST}
330+
LIBS ${UMF_UTILS_FOR_TEST})
333331
add_umf_test(
334332
NAME jemalloc_coarse_devdax
335333
SRCS pools/jemalloc_coarse_devdax.cpp malloc_compliance_tests.cpp
336-
LIBS jemalloc_pool)
334+
${BA_SOURCES_FOR_TEST}
335+
LIBS ${UMF_UTILS_FOR_TEST})
337336
endif()
338337

339338
# This test requires Linux-only file memory provider
@@ -739,7 +738,7 @@ if(LINUX
739738
else()
740739
message(
741740
STATUS
742-
"The dram_and_fsdax example is supported on Linux only and requires UMF_BUILD_LIBUMF_POOL_JEMALLOC to be turned ON - skipping"
741+
"The dram_and_fsdax example is supported on Linux only and requires the jemalloc pool, but it is disabled - skipping"
743742
)
744743
endif()
745744

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
False-positive invalid write of size 8
3+
Memcheck:Addr8
4+
...
5+
fun:je_*
6+
...
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
False-positive invalid write of size 8
3+
Memcheck:Addr8
4+
...
5+
fun:je_*
6+
...
7+
}

0 commit comments

Comments
 (0)