diff --git a/CMakeLists.txt b/CMakeLists.txt index d39ff2991..b2c6ed2d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,13 @@ macro(linklibs project) endmacro() if(MSVC) - add_compile_options(/WX /W4 /wd4127 /wd4324 /wd4201 /std:c++latest) + # Force to always compile with W4 + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif() + add_compile_options(/WX /wd4127 /wd4324 /wd4201) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG") else() diff --git a/src/ds/aba.h b/src/ds/aba.h index 6c89c7c43..143c49527 100644 --- a/src/ds/aba.h +++ b/src/ds/aba.h @@ -97,7 +97,7 @@ namespace snmalloc (__int64*)&expect); # else # if defined(__GNUC__) && !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16) -#error You must compile with -mcx16 to enable 16-bit atomic compare and swap. +#error You must compile with -mcx16 to enable 16-byte atomic compare and swap. # endif Cmp xchg{value, expect.aba + 1}; diff --git a/src/mem/alloc.h b/src/mem/alloc.h index ab009e7b5..701ccf600 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -140,10 +140,6 @@ namespace snmalloc } }; - static_assert( - SUPERSLAB_SIZE == SuperslabPagemap::GRANULARITY, - "The superslab size should be the same as the pagemap granularity"); - #ifndef SNMALLOC_DEFAULT_PAGEMAP # define SNMALLOC_DEFAULT_PAGEMAP snmalloc::SuperslabMap #endif diff --git a/src/mem/allocconfig.h b/src/mem/allocconfig.h index edbdf694e..fd7fb532f 100644 --- a/src/mem/allocconfig.h +++ b/src/mem/allocconfig.h @@ -39,6 +39,17 @@ namespace snmalloc #endif ; + // 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 + // In 32 bit uses smaller superslab. + (!bits::is64()) +#endif + ; + static constexpr size_t RESERVE_MULTIPLE = #ifdef USE_RESERVE_MULTIPLE USE_RESERVE_MULTIPLE @@ -85,14 +96,14 @@ namespace snmalloc static constexpr size_t MIN_ALLOC_SIZE = 1 << MIN_ALLOC_BITS; // Slabs are 64 kb. - static constexpr size_t SLAB_BITS = 16; + static constexpr size_t SLAB_BITS = ADDRESS_SPACE_CONSTRAINED ? 14 : 16; 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 = 8; + static constexpr size_t SLAB_COUNT_BITS = ADDRESS_SPACE_CONSTRAINED ? 6 : 8; 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); @@ -111,8 +122,8 @@ namespace snmalloc MIN_ALLOC_SIZE >= (sizeof(void*) * 2), "MIN_ALLOC_SIZE must be sufficient for two pointers"); static_assert( - SLAB_BITS == (sizeof(uint16_t) * 8), - "SLAB_BITS must be the bits in a uint16_t"); + SLAB_BITS <= (sizeof(uint16_t) * 8), + "SLAB_BITS must not be more than the bits in a uint16_t"); static_assert( SLAB_COUNT == bits::next_pow2_const(SLAB_COUNT), "SLAB_COUNT must be a power of 2"); diff --git a/src/mem/pagemap.h b/src/mem/pagemap.h index b902199b7..b47bd93ba 100644 --- a/src/mem/pagemap.h +++ b/src/mem/pagemap.h @@ -189,8 +189,6 @@ namespace snmalloc } public: - static constexpr size_t GRANULARITY = 1 << GRANULARITY_BITS; - T get(void* p) { bool success; @@ -245,10 +243,6 @@ namespace snmalloc static constexpr size_t ENTRIES = 1ULL << (COVERED_BITS + CONTENT_BITS); static constexpr size_t SHIFT = GRANULARITY_BITS; - public: - static constexpr size_t GRANULARITY = 1 << GRANULARITY_BITS; - - private: std::atomic top[ENTRIES]; public: diff --git a/src/mem/slab.h b/src/mem/slab.h index 33138d966..ec9a0001a 100644 --- a/src/mem/slab.h +++ b/src/mem/slab.h @@ -58,7 +58,7 @@ namespace snmalloc { // This slab is being bump allocated. p = (void*)((size_t)this + head - 1); - meta->head = head + (uint16_t)rsize; + meta->head = (head + (uint16_t)rsize) & (SLAB_SIZE - 1); if (meta->head == 1) { meta->set_full(); diff --git a/src/pal/pal_plain.h b/src/pal/pal_plain.h index 905f32a37..965490cfe 100644 --- a/src/pal/pal_plain.h +++ b/src/pal/pal_plain.h @@ -11,8 +11,6 @@ namespace snmalloc class PALPlainMixin : public State { public: - PALPlainMixin() : State() {} - // Notify platform that we will not be using these pages void notify_not_using(void*, size_t) noexcept {}