# Pagemap The Pagemap now stores all the meta-data for the object allocation. The meta-data in the pagemap is effectively a triple of the sizeclass, the remote allocator, and a pointer to a 64 byte block of meta-data for this chunk of memory. By storing the pointer to a block, it allows the pagemap to handle multiple slab sizes without branching on the fast path. There is one entry in the pagemap per 16KiB of address space, but by using the same entry in the pagemap for 4 adjacent entries, then we can treat a 64KiB range can be treated as a single slab of allocations. This change also means there is almost no capability amplification required by the implementation on CHERI for finding meta-data. The only amplification is required, when we change the way a chunk is used to a size of object allocation. # Backend There is a second major aspect of the refactor that there is now a narrow API that abstracts the Pagemap, PAL and address space management. This should better enable the compartmentalisation and makes it easier to produce alternative backends for various research directions. This is a template parameter that can be used to specialised by the front-end in different ways. # Thread local state The thread local state has been refactored into two components, one (called 'localalloc') that is stored directly in the TLS and is constant initialised, and one that is allocated in the address space (called 'coreallloc') which is lazily created and pooled. # Difference This removes Superslabs/Medium slabs as there meta-data is now part of the pagemap.
94 lines
1.9 KiB
C++
94 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include "address.h"
|
|
#include "defines.h"
|
|
#include "ptrwrap.h"
|
|
|
|
#include <cstdint>
|
|
#include <type_traits>
|
|
|
|
namespace snmalloc
|
|
{
|
|
/**
|
|
* TODO Rewrite for actual use, no longer Cyclic or doubly linked.
|
|
*
|
|
* Special class for cyclic doubly linked non-empty linked list
|
|
*
|
|
* This code assumes there is always one element in the list. The client
|
|
* must ensure there is a sentinal element.
|
|
*/
|
|
template<template<typename> typename Ptr = Pointer>
|
|
class CDLLNode
|
|
{
|
|
Ptr<CDLLNode> next{nullptr};
|
|
|
|
constexpr void set_next(Ptr<CDLLNode> c)
|
|
{
|
|
next = c;
|
|
}
|
|
|
|
public:
|
|
/**
|
|
* Single element cyclic list. This is the empty case.
|
|
*/
|
|
constexpr CDLLNode()
|
|
{
|
|
this->set_next(nullptr);
|
|
}
|
|
|
|
SNMALLOC_FAST_PATH bool is_empty()
|
|
{
|
|
return next == nullptr;
|
|
}
|
|
|
|
SNMALLOC_FAST_PATH Ptr<CDLLNode> get_next()
|
|
{
|
|
return next;
|
|
}
|
|
|
|
/**
|
|
* Single element cyclic list. This is the uninitialised case.
|
|
*
|
|
* This entry should never be accessed and is only used to make
|
|
* a fake metaslab.
|
|
*/
|
|
constexpr CDLLNode(bool) {}
|
|
|
|
SNMALLOC_FAST_PATH Ptr<CDLLNode> pop()
|
|
{
|
|
SNMALLOC_ASSERT(!this->is_empty());
|
|
auto result = get_next();
|
|
set_next(result->get_next());
|
|
return result;
|
|
}
|
|
|
|
SNMALLOC_FAST_PATH void insert(Ptr<CDLLNode> item)
|
|
{
|
|
debug_check();
|
|
item->set_next(this->get_next());
|
|
set_next(item);
|
|
debug_check();
|
|
}
|
|
|
|
/**
|
|
* Checks the lists invariants
|
|
* x->next->prev = x
|
|
* for all x in the list.
|
|
*/
|
|
void debug_check()
|
|
{
|
|
#ifndef NDEBUG
|
|
// Ptr<CDLLNode> item = this->get_next();
|
|
// auto p = Ptr<CDLLNode>(this);
|
|
|
|
// do
|
|
// {
|
|
// SNMALLOC_ASSERT(item->prev == p);
|
|
// p = item;
|
|
// item = item->get_next();
|
|
// } while (item != Ptr<CDLLNode>(this));
|
|
#endif
|
|
}
|
|
};
|
|
} // namespace snmalloc
|