Merge pull request #5 from Microsoft/AddressSpace

Address space constrained option
This commit is contained in:
Matthew Parkinson 2019-01-17 18:43:40 +00:00 коммит произвёл GitHub
Родитель cf8699df4f 4748f25e57
Коммит 5076bf6f32
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 24 добавлений и 19 удалений

Просмотреть файл

@ -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()

Просмотреть файл

@ -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};

Просмотреть файл

@ -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

Просмотреть файл

@ -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");

Просмотреть файл

@ -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<T> top[ENTRIES];
public:

Просмотреть файл

@ -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();

Просмотреть файл

@ -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 {}