diff --git a/src/mem/alloc.h b/src/mem/alloc.h index 26b3ed7..03ad7e8 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -394,12 +394,13 @@ namespace snmalloc # ifdef CHECK_CLIENT Superslab* super = Superslab::get(p); - if (size > 64 || address_cast(super) != address_cast(p)) + if (size > CMLargeMax || address_cast(super) != address_cast(p)) { error("Not deallocating start of an object"); } # endif large_dealloc(p, 1ULL << size); + #endif } @@ -435,11 +436,13 @@ namespace snmalloc auto ss = super; - while (size > 64) + while (size >= CMLargeRangeMin) { // This is a large alloc redirect. ss = pointer_offset_signed( - ss, -(static_cast(1) << (size - 64))); + ss, + -(static_cast(1) + << (size - CMLargeRangeMin + SUPERSLAB_BITS))); size = ChunkMap::get(ss); } diff --git a/src/mem/chunkmap.h b/src/mem/chunkmap.h index 286d89b..48adbca 100644 --- a/src/mem/chunkmap.h +++ b/src/mem/chunkmap.h @@ -10,11 +10,11 @@ using namespace std; namespace snmalloc { - enum ChunkMapSuperslabKind + enum ChunkMapSuperslabKind : uint8_t { CMNotOurs = 0, CMSuperslab = 1, - CMMediumslab = 2 + CMMediumslab = 2, /* * Values 3 (inclusive) through SUPERSLAB_BITS (exclusive) are as yet @@ -23,14 +23,26 @@ namespace snmalloc * Values SUPERSLAB_BITS (inclusive) through 64 (exclusive, as it would * represent the entire address space) are used for log2(size) at the * heads of large allocations. See SuperslabMap::set_large_size. - * - * Values 64 (inclusive) through 128 (exclusive) are used for entries - * within a large allocation. A value of x at pagemap entry p indicates - * that there are at least 2^(x-64) (inclusive) and at most 2^(x+1-64) - * (exclusive) page map entries between p and the start of the - * allocation. See SuperslabMap::set_large_size and external_address's + */ + CMLargeMin = SUPERSLAB_BITS, + CMLargeMax = 63, + + /* + * Values 64 (inclusive) through 64 + SUPERSLAB_BITS (exclusive) are unused + */ + + /* + * Values 64 + SUPERSLAB_BITS (inclusive) through 128 (exclusive) are used + * for entries within a large allocation. A value of x at pagemap entry p + * indicates that there are at least 2^(x-64) (inclusive) and at most + * 2^(x+1-64) (exclusive) page map entries between p and the start of the + * allocation. See ChunkMap::set_large_size and external_address's * handling of large reallocation redirections. - * + */ + CMLargeRangeMin = 64 + SUPERSLAB_BITS, + CMLargeRangeMax = 127, + + /* * Values 128 (inclusive) through 255 (inclusive) are as yet unused. */ @@ -208,7 +220,7 @@ namespace snmalloc { size_t run = 1ULL << i; PagemapProvider::pagemap().set_range( - ss, static_cast(64 + i + SUPERSLAB_BITS), run); + ss, static_cast(CMLargeRangeMin + i), run); ss = ss + SUPERSLAB_SIZE * run; } }