Clarify ChunkMapSuperslabKind values

This commit is contained in:
Nathaniel Filardo
2020-07-31 16:54:34 +01:00
committed by Matthew Parkinson
parent b8b5f30513
commit c1d5f48797
2 changed files with 28 additions and 13 deletions

View File

@@ -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<ptrdiff_t>(1) << (size - 64)));
ss,
-(static_cast<ptrdiff_t>(1)
<< (size - CMLargeRangeMin + SUPERSLAB_BITS)));
size = ChunkMap::get(ss);
}

View File

@@ -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<uint8_t>(64 + i + SUPERSLAB_BITS), run);
ss, static_cast<uint8_t>(CMLargeRangeMin + i), run);
ss = ss + SUPERSLAB_SIZE * run;
}
}