The Pedigree Project 0.1
Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
SlamCache Class Reference

#include <SlamAllocator.h>

+ Collaboration diagram for SlamCache:

Classes

struct  Node
 
struct  Slab
 

Public Member Functions

struct SlamCache::Node __attribute__ ((aligned(16)))
 
 SlamCache ()
 
virtual ~SlamCache ()
 
void initialise (SlamAllocator *parent, size_t objectSize)
 
uintptr_t allocate ()
 
void free (uintptr_t object)
 
size_t recovery (size_t maxSlabs)
 
bool isPointerValid (uintptr_t object) const
 
size_t objectSize () const
 
size_t slabSize () const
 
size_t slabObjectCount () const
 
void trackSlab (uintptr_t slab)
 
void check ()
 

Private Member Functions

 SlamCache (const SlamCache &)
 
const SlamCache & operator= (const SlamCache &)
 
void addSlab (Slab *slab, size_t list)
 
void removeSlab (Slab *slab)
 
bool beginFastPath ()
 
void endFastPath ()
 
Node * popFreeObject (Slab *slab)
 
void pushFreeObject (Slab *slab, Node *node)
 
Node * objectAt (uintptr_t slab, size_t index) const
 
Slab * slabForObject (uintptr_t object) const
 
uintptr_t getSlab ()
 
void freeSlab (uintptr_t slab)
 
Node * initialiseSlab (uintptr_t slab)
 
size_t currentList () const
 

Private Attributes

struct SlamCache::Slab __attribute__
 
Slab * m_PartialLists [NUM_LISTS]
 
Slab * m_FastSlabs [NUM_LISTS]
 
Node * m_LargeFreeList
 
size_t m_ObjectSize
 
size_t m_SlabSize
 
size_t m_SlabObjectOffset
 
size_t m_SlabObjectCount
 
uintptr_t m_FirstSlab
 
size_t m_FastPathState
 
Spinlock m_RecoveryLock
 
SlamAllocator * m_pParentAllocator
 

Static Private Attributes

static constexpr const int NUM_LISTS
 

Detailed Description

A cache allocates objects of a constant size.

Definition at line 152 of file SlamAllocator.h.

Constructor & Destructor Documentation

◆ SlamCache()

SlamCache::SlamCache ( )

Default constructor, does nothing.

Definition at line 226 of file SlamAllocator.cc.

◆ ~SlamCache()

SlamCache::~SlamCache ( )
virtual

Destructor is not designed to be called. There is no cleanup, this is a kernel heap!

Definition at line 244 of file SlamAllocator.cc.

Member Function Documentation

◆ addSlab()

void SlamCache::addSlab ( Slab *  slab,
size_t  list 
)
private

Definition at line 298 of file SlamAllocator.cc.

◆ allocate()

uintptr_t SlamCache::allocate ( )

Allocates an object.

Definition at line 395 of file SlamAllocator.cc.

References EMIT_IF, m_pParentAllocator, m_RecoveryLock, and UNLIKELY.

Referenced by SlamAllocator::allocate().

+ Here is the caller graph for this function:

◆ beginFastPath()

bool SlamCache::beginFastPath ( )
private

Definition at line 322 of file SlamAllocator.cc.

◆ check()

void SlamCache::check ( )

Definition at line 747 of file SlamAllocator.cc.

◆ currentList()

size_t SlamCache::currentList ( ) const
private

Definition at line 278 of file SlamAllocator.cc.

◆ endFastPath()

void SlamCache::endFastPath ( )
private

Definition at line 333 of file SlamAllocator.cc.

◆ free()

void SlamCache::free ( uintptr_t  object)

Frees an object.

Definition at line 502 of file SlamAllocator.cc.

References EMIT_IF, and m_RecoveryLock.

◆ freeSlab()

void SlamCache::freeSlab ( uintptr_t  slab)
private

Definition at line 622 of file SlamAllocator.cc.

◆ getSlab()

uintptr_t SlamCache::getSlab ( )
private

Definition at line 618 of file SlamAllocator.cc.

◆ initialise()

void SlamCache::initialise ( SlamAllocator *  parent,
size_t  objectSize 
)

Main init function.

Definition at line 246 of file SlamAllocator.cc.

References m_pParentAllocator.

◆ initialiseSlab()

SlamCache::Node * SlamCache::initialiseSlab ( uintptr_t  slab)
private

Definition at line 690 of file SlamAllocator.cc.

◆ isPointerValid()

bool SlamCache::isPointerValid ( uintptr_t  object) const
Todo:
need to figure out how to do this

Definition at line 586 of file SlamAllocator.cc.

References EMIT_IF, and Hex.

◆ objectAt()

SlamCache::Node * SlamCache::objectAt ( uintptr_t  slab,
size_t  index 
) const
private

Definition at line 386 of file SlamAllocator.cc.

◆ objectSize()

size_t SlamCache::objectSize ( ) const
inline

Definition at line 189 of file SlamAllocator.h.

◆ popFreeObject()

SlamCache::Node * SlamCache::popFreeObject ( Slab *  slab)
private

Definition at line 337 of file SlamAllocator.cc.

◆ pushFreeObject()

void SlamCache::pushFreeObject ( Slab *  slab,
Node *  node 
)
private

Definition at line 369 of file SlamAllocator.cc.

◆ recovery()

size_t SlamCache::recovery ( size_t  maxSlabs)

Attempt to recover slabs from this cache.

Definition at line 626 of file SlamAllocator.cc.

References EMIT_IF, and m_RecoveryLock.

◆ removeSlab()

void SlamCache::removeSlab ( Slab *  slab)
private

Definition at line 309 of file SlamAllocator.cc.

◆ slabForObject()

SlamCache::Slab * SlamCache::slabForObject ( uintptr_t  object) const
private

Definition at line 390 of file SlamAllocator.cc.

◆ slabObjectCount()

size_t SlamCache::slabObjectCount ( ) const
inline

Definition at line 197 of file SlamAllocator.h.

◆ slabSize()

size_t SlamCache::slabSize ( ) const
inline

Definition at line 193 of file SlamAllocator.h.

◆ trackSlab()

void SlamCache::trackSlab ( uintptr_t  slab)

Definition at line 803 of file SlamAllocator.cc.

Member Data Documentation

◆ m_FastPathState

size_t SlamCache::m_FastPathState
private

Definition at line 255 of file SlamAllocator.h.

◆ m_FastSlabs

Slab* SlamCache::m_FastSlabs[NUM_LISTS]
private

Definition at line 227 of file SlamAllocator.h.

◆ m_FirstSlab

uintptr_t SlamCache::m_FirstSlab
private

Definition at line 254 of file SlamAllocator.h.

◆ m_LargeFreeList

Node* SlamCache::m_LargeFreeList
private

Definition at line 228 of file SlamAllocator.h.

◆ m_ObjectSize

size_t SlamCache::m_ObjectSize
private

Definition at line 245 of file SlamAllocator.h.

◆ m_PartialLists

Slab* SlamCache::m_PartialLists[NUM_LISTS]
private

Definition at line 226 of file SlamAllocator.h.

◆ m_pParentAllocator

SlamAllocator* SlamCache::m_pParentAllocator
private

Pointer back to the associated SlamAllocator.

Definition at line 267 of file SlamAllocator.h.

Referenced by allocate(), and initialise().

◆ m_RecoveryLock

Spinlock SlamCache::m_RecoveryLock
private

Protects slab-list transitions and the slow paths. Recovery quiesces the lock-free fast path before inspecting or reclaiming slabs.

Definition at line 261 of file SlamAllocator.h.

Referenced by allocate(), free(), and recovery().

◆ m_SlabObjectCount

size_t SlamCache::m_SlabObjectCount
private

Definition at line 248 of file SlamAllocator.h.

◆ m_SlabObjectOffset

size_t SlamCache::m_SlabObjectOffset
private

Definition at line 247 of file SlamAllocator.h.

◆ m_SlabSize

size_t SlamCache::m_SlabSize
private

Definition at line 246 of file SlamAllocator.h.

◆ NUM_LISTS

constexpr const int SlamCache::NUM_LISTS
staticconstexprprivate
Initial value:
=
MULTIPROCESSOR ? 256 : 1

Definition at line 219 of file SlamAllocator.h.


The documentation for this class was generated from the following files: