Skip to content
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

Change default chunksize to 1MiB #229

Merged
merged 5 commits into from
Jul 9, 2020
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
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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})
Expand Down
6 changes: 4 additions & 2 deletions ci/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 10 additions & 20 deletions src/mem/allocconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,24 @@ 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())
(bits::is64())
#else
false
#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
static constexpr size_t USE_SMALL_CHUNKS =
#ifdef SNMALLOC_USE_SMALL_CHUNKS
true
#else
false
#endif
;

static constexpr size_t RESERVE_MULTIPLE =
#ifdef USE_RESERVE_MULTIPLE
USE_RESERVE_MULTIPLE
#else
bits::is64() ? 16 : 2
#endif
;

enum DecommitStrategy
{
/**
Expand Down Expand Up @@ -109,22 +101,20 @@ 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);

// Superslabs are composed of this many slabs. Slab offsets are encoded as
// 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");

Expand Down
1 change: 0 additions & 1 deletion src/test/func/fixed_region/fixed_region.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#define SNMALLOC_SGX
#define OPEN_ENCLAVE
#define OPEN_ENCLAVE_SIMULATION
#define USE_RESERVE_MULTIPLE 1
#include <iostream>
#include <snmalloc.h>

Expand Down
4 changes: 1 addition & 3 deletions src/test/func/two_alloc_types/alloc1.cc
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/test/func/two_alloc_types/alloc2.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down