From 43e7e7bdc2433162202a5c95e8537a7f6391c48b Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 8 Jul 2020 15:25:01 +0100 Subject: [PATCH 1/5] Change default chunksize to 1MiB 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 | 18 +++++++++--------- src/mem/allocconfig.h | 14 +++++++------- src/test/func/two_alloc_types/alloc1.cc | 4 ++-- src/test/func/two_alloc_types/alloc2.cc | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7014b4fa7..2035cffd3 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) @@ -240,8 +240,8 @@ 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}) @@ -250,8 +250,8 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY) 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) @@ -259,8 +259,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 +277,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/src/mem/allocconfig.h b/src/mem/allocconfig.h index ae6240bdb..2dba28615 100644 --- a/src/mem/allocconfig.h +++ b/src/mem/allocconfig.h @@ -41,8 +41,8 @@ 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 + static constexpr size_t USE_LARGE_CHUNKS = +#ifdef SNMALLOC_USE_LARGE_CHUNKS true #else // In 32 bit uses smaller superslab. @@ -51,8 +51,8 @@ namespace snmalloc ; // 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 + static constexpr size_t USE_SMALL_CHUNKS = +#ifdef SNMALLOC_USE_SMALL_CHUNKS true #else false @@ -109,9 +109,9 @@ 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 ? + static constexpr size_t SLAB_BITS = USE_SMALL_CHUNKS ? 13 : - (ADDRESS_SPACE_CONSTRAINED ? 14 : 16); + (USE_LARGE_CHUNKS ? 16 : 14); static constexpr size_t SLAB_SIZE = 1 << SLAB_BITS; static constexpr size_t SLAB_MASK = ~(SLAB_SIZE - 1); @@ -119,7 +119,7 @@ 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); diff --git a/src/test/func/two_alloc_types/alloc1.cc b/src/test/func/two_alloc_types/alloc1.cc index f6966005f..aa17d95f1 100644 --- a/src/test/func/two_alloc_types/alloc1.cc +++ b/src/test/func/two_alloc_types/alloc1.cc @@ -1,9 +1,9 @@ -#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_USE_SMALL_CHUNKS #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 67be116d9..21316ebd9 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 From d5d106f01448eaa789c7ae390ae104f1e6d027a9 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 8 Jul 2020 15:34:16 +0100 Subject: [PATCH 2/5] Fixup CI --- ci/scripts/test.sh | 6 ++++-- src/mem/allocconfig.h | 5 ++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ci/scripts/test.sh b/ci/scripts/test.sh index 1d1176e50..02e2e6534 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 2dba28615..5102eb11b 100644 --- a/src/mem/allocconfig.h +++ b/src/mem/allocconfig.h @@ -109,9 +109,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 = USE_SMALL_CHUNKS ? - 13 : - (USE_LARGE_CHUNKS ? 16 : 14); + 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); From 8e4ba72fbdd6a046635565e7a9225c186d9065c0 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 8 Jul 2020 16:40:50 +0100 Subject: [PATCH 3/5] Fixup --- src/mem/allocconfig.h | 6 +++--- src/test/func/two_alloc_types/alloc1.cc | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mem/allocconfig.h b/src/mem/allocconfig.h index 5102eb11b..21f167dbd 100644 --- a/src/mem/allocconfig.h +++ b/src/mem/allocconfig.h @@ -43,10 +43,10 @@ namespace snmalloc // constrained scenarios. static constexpr size_t USE_LARGE_CHUNKS = #ifdef SNMALLOC_USE_LARGE_CHUNKS - true -#else // In 32 bit uses smaller superslab. - (!bits::is64()) + (bits::is64()) +#else + false #endif ; diff --git a/src/test/func/two_alloc_types/alloc1.cc b/src/test/func/two_alloc_types/alloc1.cc index aa17d95f1..abff1c84b 100644 --- a/src/test/func/two_alloc_types/alloc1.cc +++ b/src/test/func/two_alloc_types/alloc1.cc @@ -3,7 +3,6 @@ #define OPEN_ENCLAVE_SIMULATION #define USE_RESERVE_MULTIPLE 1 #define NO_BOOTSTRAP_ALLOCATOR -#define SNMALLOC_USE_SMALL_CHUNKS #define SNMALLOC_EXPOSE_PAGEMAP #define SNMALLOC_NAME_MANGLE(a) enclave_##a // Redefine the namespace, so we can have two versions. From bc370db3cfdaa3a15bf875c04bc36aa815b53612 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 8 Jul 2020 16:41:42 +0100 Subject: [PATCH 4/5] Remove unused defin --- src/mem/allocconfig.h | 9 --------- src/test/func/fixed_region/fixed_region.cc | 1 - src/test/func/two_alloc_types/alloc1.cc | 1 - 3 files changed, 11 deletions(-) diff --git a/src/mem/allocconfig.h b/src/mem/allocconfig.h index 21f167dbd..0ea5257c5 100644 --- a/src/mem/allocconfig.h +++ b/src/mem/allocconfig.h @@ -59,14 +59,6 @@ namespace snmalloc #endif ; - static constexpr size_t RESERVE_MULTIPLE = -#ifdef USE_RESERVE_MULTIPLE - USE_RESERVE_MULTIPLE -#else - bits::is64() ? 16 : 2 -#endif - ; - enum DecommitStrategy { /** @@ -123,7 +115,6 @@ namespace snmalloc 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 4f64700b2..8f25c5756 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 abff1c84b..0f3a9cb71 100644 --- a/src/test/func/two_alloc_types/alloc1.cc +++ b/src/test/func/two_alloc_types/alloc1.cc @@ -1,7 +1,6 @@ #undef SNMALLOC_USE_LARGE_CHUNKS #define OPEN_ENCLAVE #define OPEN_ENCLAVE_SIMULATION -#define USE_RESERVE_MULTIPLE 1 #define NO_BOOTSTRAP_ALLOCATOR #define SNMALLOC_EXPOSE_PAGEMAP #define SNMALLOC_NAME_MANGLE(a) enclave_##a From faa8e36d3d6091f1c9d59888293eb18073c94b45 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 9 Jul 2020 11:05:17 +0100 Subject: [PATCH 5/5] Add original library targets back in. --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2035cffd3..611d7302e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,16 +240,20 @@ 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) 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}) 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. @@ -259,6 +263,7 @@ 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) add_shim(snmallocshim-16mib-rust STATIC src/override/rust.cc) target_compile_definitions(snmallocshim-16mib-rust PRIVATE SNMALLOC_USE_LARGE_CHUNKS) endif()