NFC: Extract MetaCommon from ChunkRecord
This commit is contained in:
committed by
Nathaniel Wesley Filardo
parent
5bb556cb68
commit
f0b7dc4b04
@@ -322,7 +322,8 @@ namespace snmalloc
|
||||
auto start_of_slab = pointer_align_down<void>(
|
||||
p, snmalloc::sizeclass_to_slab_size(sizeclass));
|
||||
// TODO Add bounds correctly here
|
||||
chunk_record->chunk = capptr::Chunk<void>(start_of_slab.unsafe_ptr());
|
||||
chunk_record->meta_common.chunk =
|
||||
capptr::Chunk<void>(start_of_slab.unsafe_ptr());
|
||||
|
||||
#ifdef SNMALLOC_TRACING
|
||||
std::cout << "Slab " << start_of_slab.unsafe_ptr()
|
||||
|
||||
@@ -541,7 +541,8 @@ namespace snmalloc
|
||||
* a CapPtr<void, Chunk> to this region internally even while it's
|
||||
* allocated.
|
||||
*/
|
||||
slab_record->chunk = capptr::Chunk<void>(p_tame.unsafe_ptr());
|
||||
slab_record->meta_common.chunk =
|
||||
capptr::Chunk<void>(p_tame.unsafe_ptr());
|
||||
check_init(
|
||||
[](
|
||||
CoreAlloc* core_alloc,
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
struct MetaCommon
|
||||
{
|
||||
capptr::Chunk<void> chunk;
|
||||
};
|
||||
|
||||
// The Metaslab represent the status of a single slab.
|
||||
// This can be either a short or a standard slab.
|
||||
class alignas(CACHELINE_SIZE) Metaslab
|
||||
|
||||
@@ -17,9 +17,13 @@ namespace snmalloc
|
||||
*/
|
||||
struct ChunkRecord
|
||||
{
|
||||
MetaCommon meta_common;
|
||||
std::atomic<ChunkRecord*> next;
|
||||
capptr::Chunk<void> chunk;
|
||||
};
|
||||
static_assert(std::is_standard_layout_v<ChunkRecord>);
|
||||
static_assert(
|
||||
offsetof(ChunkRecord, meta_common) == 0,
|
||||
"ChunkRecord and Metaslab must share a common prefix");
|
||||
|
||||
/**
|
||||
* How many slab sizes that can be provided.
|
||||
@@ -97,7 +101,7 @@ namespace snmalloc
|
||||
|
||||
if (chunk_record != nullptr)
|
||||
{
|
||||
auto slab = chunk_record->chunk;
|
||||
auto slab = chunk_record->meta_common.chunk;
|
||||
state.memory_in_stacks -= slab_size;
|
||||
auto meta = reinterpret_cast<Metaslab*>(chunk_record);
|
||||
#ifdef SNMALLOC_TRACING
|
||||
@@ -138,8 +142,8 @@ namespace snmalloc
|
||||
{
|
||||
auto& state = SharedStateHandle::get_slab_allocator_state(&local_state);
|
||||
#ifdef SNMALLOC_TRACING
|
||||
std::cout << "Return slab:" << p->chunk.unsafe_ptr() << " slab_sizeclass "
|
||||
<< slab_sizeclass << " size "
|
||||
std::cout << "Return slab:" << p->meta_common.chunk.unsafe_ptr()
|
||||
<< " slab_sizeclass " << slab_sizeclass << " size "
|
||||
<< slab_sizeclass_to_size(slab_sizeclass)
|
||||
<< " memory in stacks " << state.memory_in_stacks << std::endl;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user