Skip to content

Add UMF_BUILD_OS_MEMORY_PROVIDER option to disable OS memory provider #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
compiler: [{c: gcc, cxx: g++}]
pool_tracking: ['ON', 'OFF']
shared_library: ['OFF']
os_provider: ['ON']
include:
- os: 'ubuntu-20.04'
build_type: Release
Expand All @@ -29,6 +30,18 @@ jobs:
build_type: Release
compiler: {c: gcc, cxx: g++}
shared_library: 'ON'
# test os_provider='OFF' with shared_library='ON'
- os: 'ubuntu-22.04'
build_type: Release
compiler: {c: gcc, cxx: g++}
shared_library: 'ON'
os_provider: 'OFF'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the practical reason to test without the OS memory provider?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to test if the UMF_BUILD_OS_MEMORY_PROVIDER option works correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinser52 UR or oneCCL does not require an OS provider. oneCCL does not even have libnuma or hwloc installed on its CI systems.

# test os_provider='OFF' with shared_library='OFF'
- os: 'ubuntu-22.04'
build_type: Release
compiler: {c: gcc, cxx: g++}
shared_library: 'OFF'
os_provider: 'OFF'
runs-on: ${{matrix.os}}

steps:
Expand All @@ -54,6 +67,7 @@ jobs:
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DUMF_BUILD_OS_MEMORY_PROVIDER=${{matrix.os_provider}}
-DUMF_ENABLE_POOL_TRACKING=${{matrix.pool_tracking}}
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=ON
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ include(helpers)

# Build Options
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
option(UMF_BUILD_OS_MEMORY_PROVIDER "Build OS memory provider" ON)
option(UMF_BUILD_LIBUMF_POOL_DISJOINT "Build the libumf_pool_disjoint static library" OFF)
option(UMF_BUILD_LIBUMF_POOL_JEMALLOC "Build the libumf_pool_jemalloc static library" OFF)
option(UMF_BUILD_LIBUMF_POOL_SCALABLE "Build the libumf_pool_scalable static library" OFF)
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ UMF comes with predefined pool allocators (see include/pool) and providers (see

A memory provider that provides memory from an operating system.

#### Requirements

1) Linux OS
2) The `UMF_BUILD_OS_MEMORY_PROVIDER` option turned `ON` (by default)
3) Required packages:
- libnuma-dev

## Memory pool managers

### libumf_pool_disjoint
Expand All @@ -41,7 +48,7 @@ The `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option has to be turned `ON` to build this

1) The `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option turned `ON`
2) Required packages:
- libjemalloc-dev
- libjemalloc-dev

### libumf_pool_scalable (Linux-only)

Expand All @@ -52,7 +59,7 @@ The `UMF_BUILD_LIBUMF_POOL_SCALABLE` option has to be turned `ON` to build this

1) The `UMF_BUILD_LIBUMF_POOL_SCALABLE` option turned `ON`
2) Required packages:
- libtbb-dev (libraries: libtbbmalloc.so.2)
- libtbb-dev (libraries: libtbbmalloc.so.2)

## Building

Expand All @@ -61,7 +68,6 @@ The `UMF_BUILD_LIBUMF_POOL_SCALABLE` option has to be turned `ON` to build this
Required packages:
- C++ compiler with C++17 support
- [CMake](https://cmake.org/) >= 3.14.0
- Linux only: libnuma-dev

For development and contributions:
- clang-format-15.0 (can be installed with `python -m pip install clang-format==15.0.7`)
Expand Down Expand Up @@ -115,6 +121,7 @@ List of options provided by CMake:
| Name | Description | Values | Default |
| - | - | - | - |
| UMF_BUILD_SHARED_LIBRARY | Build UMF as shared library | ON/OFF | OFF |
| UMF_BUILD_OS_MEMORY_PROVIDER | Build OS memory provider | ON/OFF | ON |
| UMF_BUILD_LIBUMF_POOL_DISJOINT | Build the libumf_pool_disjoint static library | ON/OFF | OFF |
| UMF_BUILD_LIBUMF_POOL_JEMALLOC | Build the libumf_pool_jemalloc static library | ON/OFF | OFF |
| UMF_BUILD_LIBUMF_POOL_SCALABLE | Build the libumf_pool_scalable static library | ON/OFF | OFF |
Expand Down
4 changes: 4 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ target_link_libraries(ubench
pthread
m)

if (UMF_BUILD_OS_MEMORY_PROVIDER)
target_compile_definitions(ubench PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1)
endif()

if (UMF_BUILD_LIBUMF_POOL_DISJOINT)
target_compile_definitions(ubench PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT=1)
endif()
Expand Down
26 changes: 16 additions & 10 deletions benchmark/ubench.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ UBENCH_EX(simple, glibc_malloc) {
free(array);
}

#ifdef UMF_BUILD_OS_MEMORY_PROVIDER
////////////////// OS MEMORY PROVIDER

static umf_os_memory_provider_params_t UMF_OS_MEMORY_PROVIDER_PARAMS = {
Expand Down Expand Up @@ -156,10 +157,12 @@ UBENCH_EX(simple, os_memory_provider) {
umfMemoryProviderDestroy(os_memory_provider);
free(array);
}
#endif /* UMF_BUILD_OS_MEMORY_PROVIDER */

#if (defined UMF_BUILD_LIBUMF_POOL_DISJOINT) || \
(defined UMF_BUILD_LIBUMF_POOL_JEMALLOC) || \
(defined UMF_BUILD_LIBUMF_POOL_SCALABLE)
#if (defined UMF_BUILD_OS_MEMORY_PROVIDER) && \
((defined UMF_BUILD_LIBUMF_POOL_DISJOINT) || \
(defined UMF_BUILD_LIBUMF_POOL_JEMALLOC) || \
(defined UMF_BUILD_LIBUMF_POOL_SCALABLE))

static void *w_umfPoolMalloc(void *provider, size_t size, size_t alignment) {
umf_memory_pool_handle_t hPool = (umf_memory_pool_handle_t)provider;
Expand All @@ -174,9 +177,10 @@ static void w_umfPoolFree(void *provider, void *ptr, size_t size) {
exit(-1);
}
}
#endif /* (defined UMF_BUILD_LIBUMF_POOL_DISJOINT) || (defined UMF_BUILD_LIBUMF_POOL_JEMALLOC) || (defined UMF_BUILD_LIBUMF_POOL_SCALABLE) */
#endif /* (defined UMF_BUILD_OS_MEMORY_PROVIDER) && ((defined UMF_BUILD_LIBUMF_POOL_DISJOINT) || (defined UMF_BUILD_LIBUMF_POOL_JEMALLOC) || (defined UMF_BUILD_LIBUMF_POOL_SCALABLE)) */

#ifdef UMF_BUILD_LIBUMF_POOL_DISJOINT
#if (defined UMF_BUILD_LIBUMF_POOL_DISJOINT) && \
(defined UMF_BUILD_OS_MEMORY_PROVIDER)
////////////////// DISJOINT POOL WITH OS MEMORY PROVIDER

UBENCH_EX(simple, disjoint_pool_with_os_memory_provider) {
Expand Down Expand Up @@ -218,9 +222,10 @@ UBENCH_EX(simple, disjoint_pool_with_os_memory_provider) {
umfMemoryProviderDestroy(os_memory_provider);
free(array);
}
#endif /* UMF_BUILD_LIBUMF_POOL_DISJOINT */
#endif /* (defined UMF_BUILD_LIBUMF_POOL_DISJOINT) && (defined UMF_BUILD_OS_MEMORY_PROVIDER) */

#ifdef UMF_BUILD_LIBUMF_POOL_JEMALLOC
#if (defined UMF_BUILD_LIBUMF_POOL_JEMALLOC) && \
(defined UMF_BUILD_OS_MEMORY_PROVIDER)
////////////////// JEMALLOC POOL WITH OS MEMORY PROVIDER

UBENCH_EX(simple, jemalloc_pool_with_os_memory_provider) {
Expand Down Expand Up @@ -254,9 +259,10 @@ UBENCH_EX(simple, jemalloc_pool_with_os_memory_provider) {
umfMemoryProviderDestroy(os_memory_provider);
free(array);
}
#endif /* UMF_BUILD_LIBUMF_POOL_JEMALLOC */
#endif /* (defined UMF_BUILD_LIBUMF_POOL_JEMALLOC) && (defined UMF_BUILD_OS_MEMORY_PROVIDER) */

#ifdef UMF_BUILD_LIBUMF_POOL_SCALABLE
#if (defined UMF_BUILD_LIBUMF_POOL_SCALABLE) && \
(defined UMF_BUILD_OS_MEMORY_PROVIDER)
////////////////// SCALABLE (TBB) POOL WITH OS MEMORY PROVIDER

UBENCH_EX(simple, scalable_pool_with_os_memory_provider) {
Expand Down Expand Up @@ -290,6 +296,6 @@ UBENCH_EX(simple, scalable_pool_with_os_memory_provider) {
umfMemoryProviderDestroy(os_memory_provider);
free(array);
}
#endif /* UMF_BUILD_LIBUMF_POOL_SCALABLE */
#endif /* (defined UMF_BUILD_LIBUMF_POOL_SCALABLE) && (defined UMF_BUILD_OS_MEMORY_PROVIDER) */

UBENCH_MAIN();
23 changes: 11 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,35 @@ include(${UMF_CMAKE_SOURCE_DIR}/cmake/helpers.cmake)

add_subdirectory(utils)

set(UMF_LIBS umf_utils)

set(UMF_SOURCES
memory_pool.c
memory_provider.c
memory_provider_get_last_failed.c
provider/provider_os_memory.c
provider/provider_tracking.c
critnib/critnib.c
)

set(UMF_SOURCES_LINUX
provider/provider_os_memory_linux.c
)

set(UMF_SOURCES_WINDOWS
provider/provider_os_memory_windows.c
provider/provider_tracking_windows.cpp
)

if(UMF_BUILD_OS_MEMORY_PROVIDER)
set(UMF_SOURCES ${UMF_SOURCES} provider/provider_os_memory.c)
set(UMF_SOURCES_LINUX ${UMF_SOURCES_LINUX} provider/provider_os_memory_linux.c)
set(UMF_SOURCES_WINDOWS ${UMF_SOURCES_WINDOWS} provider/provider_os_memory_windows.c)
if(LINUX)
set(UMF_LIBS ${UMF_LIBS} numa)
endif()
endif()

if(LINUX)
set(UMF_SOURCES ${UMF_SOURCES} ${UMF_SOURCES_LINUX})
elseif(WINDOWS)
set(UMF_SOURCES ${UMF_SOURCES} ${UMF_SOURCES_WINDOWS})
endif()

if(LINUX)
set(UMF_LIBS umf_utils numa)
else()
set(UMF_LIBS umf_utils)
endif()

if(UMF_BUILD_SHARED_LIBRARY)
add_umf_library(NAME umf
TYPE SHARED
Expand Down
26 changes: 17 additions & 9 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,27 @@ if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
LIBS disjoint_pool)
endif()

if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
add_umf_test(NAME jemalloc_pool
SRCS pools/jemalloc_pool.cpp malloc_compliance_tests.cpp
LIBS jemalloc_pool)
if(UMF_BUILD_OS_MEMORY_PROVIDER)
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
add_umf_test(NAME jemalloc_pool
SRCS pools/jemalloc_pool.cpp malloc_compliance_tests.cpp
LIBS jemalloc_pool)
endif()
else()
message(STATUS "The jemalloc_pool test is DISABLED, because it uses OS_MEMORY_PROVIDER, while the UMF_BUILD_OS_MEMORY_PROVIDER option is set to OFF")
endif()

if(UMF_BUILD_LIBUMF_POOL_SCALABLE)
add_umf_test(NAME scalable_pool
SRCS pools/scalable_pool.cpp malloc_compliance_tests.cpp
LIBS scalable_pool)
if(UMF_BUILD_OS_MEMORY_PROVIDER)
if(UMF_BUILD_LIBUMF_POOL_SCALABLE)
add_umf_test(NAME scalable_pool
SRCS pools/scalable_pool.cpp malloc_compliance_tests.cpp
LIBS scalable_pool)
endif()
else()
message(STATUS "The scalable_pool test is DISABLED, because it uses OS_MEMORY_PROVIDER, while the UMF_BUILD_OS_MEMORY_PROVIDER option is set to OFF")
endif()

if(LINUX) # OS-specific functions are implemented only for Linux now
if(UMF_BUILD_OS_MEMORY_PROVIDER AND LINUX) # OS-specific functions are implemented only for Linux now
add_umf_test(NAME provider_os_memory
SRCS provider_os_memory.cpp
LIBS umf_utils)
Expand Down