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.
This commit is contained in:
committed by
GitHub
parent
8d1f3c3046
commit
4e1f5829a7
@@ -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})
|
||||
|
||||
@@ -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
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#define SNMALLOC_SGX
|
||||
#define OPEN_ENCLAVE
|
||||
#define OPEN_ENCLAVE_SIMULATION
|
||||
#define USE_RESERVE_MULTIPLE 1
|
||||
#include <iostream>
|
||||
#include <snmalloc.h>
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user