From 4e1f5829a754ab9c170ec090979d3a670d2d5d1a Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 9 Jul 2020 13:22:32 +0100 Subject: [PATCH] Change default chunksize to 1MiB (#229) This change makes the original 16MiB option not the common option. It also changes the names of the defines to SNMALLOC_USE_LARGE_CHUNKS SNMALLOC_USE_SMALL_CHUNKS The second should be set for Open Enclave configuration, and results in 256KiB chunk sizes. The first being set builds the original 16MiB chunk sizes. If neither is set, then we default to 1MiB chunk sizes. --- CMakeLists.txt | 17 ++++++++---- ci/scripts/test.sh | 6 ++-- src/mem/allocconfig.h | 32 ++++++++-------------- src/test/func/fixed_region/fixed_region.cc | 1 - src/test/func/two_alloc_types/alloc1.cc | 4 +-- src/test/func/two_alloc_types/alloc2.cc | 4 +-- 6 files changed, 29 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7014b4f..611d730 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ macro(warnings_high) endmacro() macro(oe_simulate target) - target_compile_definitions(${target} PRIVATE IS_REALLY_ADDRESS_SPACE_CONSTRAINED) + target_compile_definitions(${target} PRIVATE SNMALLOC_USE_SMALL_CHUNKS) endmacro() macro(clangformat_targets) @@ -241,17 +241,21 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY) if (SNMALLOC_STATIC_LIBRARY) add_shim(snmallocshim-static STATIC src/override/malloc.cc) add_shim(snmallocshim-1mib-static STATIC src/override/malloc.cc) - target_compile_definitions(snmallocshim-1mib-static PRIVATE IS_ADDRESS_SPACE_CONSTRAINED + add_shim(snmallocshim-16mib-static STATIC src/override/malloc.cc) + target_compile_definitions(snmallocshim-16mib-static PRIVATE SNMALLOC_USE_LARGE_CHUNKS SNMALLOC_STATIC_LIBRARY_PREFIX=${SNMALLOC_STATIC_LIBRARY_PREFIX}) target_compile_definitions(snmallocshim-static PRIVATE SNMALLOC_STATIC_LIBRARY_PREFIX=${SNMALLOC_STATIC_LIBRARY_PREFIX}) + target_compile_definitions(snmallocshim-1mib-static PRIVATE + SNMALLOC_STATIC_LIBRARY_PREFIX=${SNMALLOC_STATIC_LIBRARY_PREFIX}) endif () if(NOT WIN32) set(SHARED_FILES src/override/new.cc src/override/malloc.cc) add_shim(snmallocshim SHARED ${SHARED_FILES}) add_shim(snmallocshim-1mib SHARED ${SHARED_FILES}) - target_compile_definitions(snmallocshim-1mib PRIVATE IS_ADDRESS_SPACE_CONSTRAINED) + add_shim(snmallocshim-16mib SHARED ${SHARED_FILES}) + target_compile_definitions(snmallocshim-16mib PRIVATE SNMALOC_USE_LARGE_CHUNKS) # Build a shim with some settings from oe. add_shim(snmallocshim-oe SHARED ${SHARED_FILES}) oe_simulate(snmallocshim-oe) @@ -260,7 +264,8 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY) if(SNMALLOC_RUST_SUPPORT) add_shim(snmallocshim-rust STATIC src/override/rust.cc) add_shim(snmallocshim-1mib-rust STATIC src/override/rust.cc) - target_compile_definitions(snmallocshim-1mib-rust PRIVATE IS_ADDRESS_SPACE_CONSTRAINED) + add_shim(snmallocshim-16mib-rust STATIC src/override/rust.cc) + target_compile_definitions(snmallocshim-16mib-rust PRIVATE SNMALLOC_USE_LARGE_CHUNKS) endif() enable_testing() @@ -277,8 +282,8 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY) set(TESTNAME "${TEST_CATEGORY}-${TEST}-${SUPER_SLAB_SIZE}") add_executable(${TESTNAME} ${SRC}) - if (${SUPER_SLAB_SIZE} EQUAL 1) - target_compile_definitions(${TESTNAME} PRIVATE IS_ADDRESS_SPACE_CONSTRAINED) + if (${SUPER_SLAB_SIZE} EQUAL 16) + target_compile_definitions(${TESTNAME} PRIVATE SNMALLOC_USE_LARGE_CHUNKS) endif() if (${SUPER_SLAB_SIZE} EQUAL oe) oe_simulate(${TESTNAME}) diff --git a/ci/scripts/test.sh b/ci/scripts/test.sh index 1d1176e..02e2e65 100755 --- a/ci/scripts/test.sh +++ b/ci/scripts/test.sh @@ -4,9 +4,11 @@ cd build if [ $SELF_HOST = false ]; then ctest -j 4 --output-on-failure -C $BUILD_TYPE else - sudo cp libsnmallocshim.so libsnmallocshim-1mib.so /usr/local/lib/ + sudo cp libsnmallocshim.so libsnmallocshim-16mib.so libsnmallocshim-oe.so /usr/local/lib/ ninja clean LD_PRELOAD=/usr/local/lib/libsnmallocshim.so ninja ninja clean - LD_PRELOAD=/usr/local/lib/libsnmallocshim-1mib.so ninja + LD_PRELOAD=/usr/local/lib/libsnmallocshim-16mib.so ninja + ninja clean + LD_PRELOAD=/usr/local/lib/libsnmallocshim-oe.so ninja fi \ No newline at end of file diff --git a/src/mem/allocconfig.h b/src/mem/allocconfig.h index ae6240b..0ea5257 100644 --- a/src/mem/allocconfig.h +++ b/src/mem/allocconfig.h @@ -41,29 +41,21 @@ namespace snmalloc // Specifies smaller slab and super slab sizes for address space // constrained scenarios. - static constexpr size_t ADDRESS_SPACE_CONSTRAINED = -#ifdef IS_ADDRESS_SPACE_CONSTRAINED - true -#else + static constexpr size_t USE_LARGE_CHUNKS = +#ifdef SNMALLOC_USE_LARGE_CHUNKS // In 32 bit uses smaller superslab. - (!bits::is64()) -#endif - ; - - // Specifies even smaller slab and super slab sizes for open enclave. - static constexpr size_t REALLY_ADDRESS_SPACE_CONSTRAINED = -#ifdef IS_REALLY_ADDRESS_SPACE_CONSTRAINED - true + (bits::is64()) #else false #endif ; - static constexpr size_t RESERVE_MULTIPLE = -#ifdef USE_RESERVE_MULTIPLE - USE_RESERVE_MULTIPLE + // Specifies even smaller slab and super slab sizes for open enclave. + static constexpr size_t USE_SMALL_CHUNKS = +#ifdef SNMALLOC_USE_SMALL_CHUNKS + true #else - bits::is64() ? 16 : 2 + false #endif ; @@ -109,9 +101,8 @@ namespace snmalloc static constexpr size_t MIN_ALLOC_BITS = bits::ctz_const(MIN_ALLOC_SIZE); // Slabs are 64 KiB unless constrained to 16 KiB. - static constexpr size_t SLAB_BITS = REALLY_ADDRESS_SPACE_CONSTRAINED ? - 13 : - (ADDRESS_SPACE_CONSTRAINED ? 14 : 16); + static constexpr size_t SLAB_BITS = + USE_SMALL_CHUNKS ? 13 : (USE_LARGE_CHUNKS ? 16 : 14); static constexpr size_t SLAB_SIZE = 1 << SLAB_BITS; static constexpr size_t SLAB_MASK = ~(SLAB_SIZE - 1); @@ -119,12 +110,11 @@ namespace snmalloc // a byte, so the maximum count is 256. This must be a power of two to // allow fast masking to find a superslab start address. static constexpr size_t SLAB_COUNT_BITS = - REALLY_ADDRESS_SPACE_CONSTRAINED ? 5 : (ADDRESS_SPACE_CONSTRAINED ? 6 : 8); + USE_SMALL_CHUNKS ? 5 : (USE_LARGE_CHUNKS ? 8 : 6); static constexpr size_t SLAB_COUNT = 1 << SLAB_COUNT_BITS; static constexpr size_t SUPERSLAB_SIZE = SLAB_SIZE * SLAB_COUNT; static constexpr size_t SUPERSLAB_MASK = ~(SUPERSLAB_SIZE - 1); static constexpr size_t SUPERSLAB_BITS = SLAB_BITS + SLAB_COUNT_BITS; - static constexpr size_t RESERVE_SIZE = SUPERSLAB_SIZE * RESERVE_MULTIPLE; static_assert((1ULL << SUPERSLAB_BITS) == SUPERSLAB_SIZE, "Sanity check"); diff --git a/src/test/func/fixed_region/fixed_region.cc b/src/test/func/fixed_region/fixed_region.cc index 4f64700..8f25c57 100644 --- a/src/test/func/fixed_region/fixed_region.cc +++ b/src/test/func/fixed_region/fixed_region.cc @@ -1,7 +1,6 @@ #define SNMALLOC_SGX #define OPEN_ENCLAVE #define OPEN_ENCLAVE_SIMULATION -#define USE_RESERVE_MULTIPLE 1 #include #include diff --git a/src/test/func/two_alloc_types/alloc1.cc b/src/test/func/two_alloc_types/alloc1.cc index f696600..0f3a9cb 100644 --- a/src/test/func/two_alloc_types/alloc1.cc +++ b/src/test/func/two_alloc_types/alloc1.cc @@ -1,9 +1,7 @@ -#undef IS_ADDRESS_SPACE_CONSTRAINED +#undef SNMALLOC_USE_LARGE_CHUNKS #define OPEN_ENCLAVE #define OPEN_ENCLAVE_SIMULATION -#define USE_RESERVE_MULTIPLE 1 #define NO_BOOTSTRAP_ALLOCATOR -#define IS_ADDRESS_SPACE_CONSTRAINED #define SNMALLOC_EXPOSE_PAGEMAP #define SNMALLOC_NAME_MANGLE(a) enclave_##a // Redefine the namespace, so we can have two versions. diff --git a/src/test/func/two_alloc_types/alloc2.cc b/src/test/func/two_alloc_types/alloc2.cc index 67be116..21316eb 100644 --- a/src/test/func/two_alloc_types/alloc2.cc +++ b/src/test/func/two_alloc_types/alloc2.cc @@ -1,6 +1,6 @@ // Remove parameters feed from test harness -#undef ADDRESS_SPACE_CONSTRAINED -#undef REALLY_ADDRESS_SPACE_CONSTRAINED +#undef SNMALLOC_USE_LARGE_CHUNKS +#undef SNMALLOC_USE_SMALL_CHUNKS #define SNMALLOC_NAME_MANGLE(a) host_##a #define NO_BOOTSTRAP_ALLOCATOR