diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a8daa429..3ae8c0f82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,9 @@ if (SNMALLOC_SANITIZER) message(STATUS "Using sanitizer=${SNMALLOC_SANITIZER}") endif() +set(SNMALLOC_MIN_ALLOC_SIZE "" CACHE STRING "Minimum allocation bytes (power of 2)") +set(SNMALLOC_MIN_ALLOC_STEP_SIZE "" CACHE STRING "Minimum allocation step (power of 2)") + if(MSVC AND SNMALLOC_STATIC_LIBRARY AND (SNMALLOC_STATIC_LIBRARY_PREFIX STREQUAL "")) message(FATAL_ERROR "Empty static library prefix not supported on MSVC") endif() @@ -226,6 +229,11 @@ endif() function(add_as_define FLAG) target_compile_definitions(snmalloc INTERFACE $<$:${FLAG}>) endfunction() +function(add_as_define_value KEY) + if (NOT ${${KEY}} STREQUAL "") + target_compile_definitions(snmalloc INTERFACE ${KEY}=${${KEY}}) + endif () +endfunction() add_as_define(SNMALLOC_QEMU_WORKAROUND) add_as_define(SNMALLOC_TRACING) @@ -238,6 +246,8 @@ endif() if (SNMALLOC_NO_REALLOCARR) add_as_define(SNMALLOC_NO_REALLOCARR) endif() +add_as_define_value(SNMALLOC_MIN_ALLOC_SIZE) +add_as_define_value(SNMALLOC_MIN_ALLOC_STEP_SIZE) target_compile_definitions(snmalloc INTERFACE $<$:MALLOC_USABLE_SIZE_QUALIFIER=const>) diff --git a/src/snmalloc/ds/allocconfig.h b/src/snmalloc/ds/allocconfig.h index 1218a92b9..d44509157 100644 --- a/src/snmalloc/ds/allocconfig.h +++ b/src/snmalloc/ds/allocconfig.h @@ -21,7 +21,12 @@ namespace snmalloc static constexpr size_t CACHELINE_SIZE = 64; /// The "machine epsilon" for the small sizeclass machinery. - static constexpr size_t MIN_ALLOC_STEP_SIZE = 2 * sizeof(void*); + static constexpr size_t MIN_ALLOC_STEP_SIZE = +#if defined(SNMALLOC_MIN_ALLOC_STEP_SIZE) + SNMALLOC_MIN_ALLOC_STEP_SIZE; +#else + 2 * sizeof(void*); +#endif /// Derived from MIN_ALLOC_STEP_SIZE static constexpr size_t MIN_ALLOC_STEP_BITS = @@ -34,7 +39,12 @@ namespace snmalloc * smaller than MIN_ALLOC_SIZE), which may be useful if MIN_ALLOC_SIZE must * be large or not a power of two, those smaller size classes will be unused. */ - static constexpr size_t MIN_ALLOC_SIZE = 2 * sizeof(void*); + static constexpr size_t MIN_ALLOC_SIZE = +#if defined(SNMALLOC_MIN_ALLOC_SIZE) + SNMALLOC_MIN_ALLOC_SIZE; +#else + 2 * sizeof(void*); +#endif // Minimum slab size. #if defined(SNMALLOC_QEMU_WORKAROUND) && defined(SNMALLOC_VA_BITS_64)