KASKADE 7 development version
Loading...
Searching...
No Matches
Kaskade::Kalloc Class Reference

A simple memory manager for NUMA systems. More...

#include <kalloc.hh>

Inheritance diagram for Kaskade::Kalloc:
Kaskade::KallocUnlocked

Public Member Functions

 Kalloc (int node_, int align_=64, size_t blocksize_=2 *1024 *1024, bool checking=true)
 Constructor.
 Kalloc (Kalloc &&kalloc)
 Move Constructor.
 ~Kalloc ()
 Destructor.
void * alloc (size_t n)
 Allocates n bytes of memory.
void free (void *p, size_t n)
 Releases memory range.
void reserve (size_t n, size_t k)
 Tells the allocator that subsequently several blocks of the same size will be requested.
size_t alignment () const
 Reports the alignment size.
std::ostream & print (std::ostream &out) const
 Prints memory management statistics to the given stream.

Protected Member Functions

void * allocUnlocked (size_t n)
 Allocates n bytes of memory.
void freeUnlocked (void *p, size_t n)
 Releases memory range.

Detailed Description

A simple memory manager for NUMA systems.

The memory manager is not intended to be a drop-in replacement for the standard malloc (and relies itself on standard malloc). It is intended to implement standard allocators for containers that need to store their data on a particular NUMA node.

The memory is managed in two groups.

  • Very large memory ranges (larger than half of the blocksize) are allocated and released directly via libnuma. These ranges are aligned at page boundaries (usually 4k).
  • Mid and small size memory ranges are carved out from libnuma memory blocks and maintained in buckets of blocks of same size. These ranges are aligned at the given alignment value, usually at cache lines of 64 bytes.

Definition at line 39 of file kalloc.hh.

Constructor & Destructor Documentation

◆ Kalloc() [1/2]

Kaskade::Kalloc::Kalloc ( int node_,
int align_ = 64,
size_t blocksize_ = 2 *1024 *1024,
bool checking = true )

Constructor.

Parameters
nodeThe NUMA node on which to allocate memory.
alignThe alignment of the memory to return. Has to be a power of 2, and significantly below blocksize. Defaults to common cache line size of 64 bytes.
blocksizeThe size of memory blocks to be requested from libnuma. Has to be a multiple of \( 4096 \). Defaults to 2^21, which is two MB.
checkingIf true, performs additional usage sanity checks for detecting memory management bugs.

Referenced by Kalloc(), and Kaskade::KallocUnlocked::KallocUnlocked().

◆ Kalloc() [2/2]

Kaskade::Kalloc::Kalloc ( Kalloc && kalloc)

Move Constructor.

◆ ~Kalloc()

Kaskade::Kalloc::~Kalloc ( )

Destructor.

Member Function Documentation

◆ alignment()

size_t Kaskade::Kalloc::alignment ( ) const
inline

Reports the alignment size.

Definition at line 119 of file kalloc.hh.

◆ alloc()

void * Kaskade::Kalloc::alloc ( size_t n)

Allocates n bytes of memory.

If n exceeds the alignment size, the returned memory range is guaranteed to be aligned as to the value specified on construction.

The method is thread-safe.

Parameters
nrequested memory size in bytes.

◆ allocUnlocked()

void * Kaskade::Kalloc::allocUnlocked ( size_t n)
protected

Allocates n bytes of memory.

This method is NOT thread-safe. Use this only if you know exactly there's only one thread accessing the allocator.

Referenced by Kaskade::KallocUnlocked::alloc().

◆ free()

void Kaskade::Kalloc::free ( void * p,
size_t n )

Releases memory range.

The method is thread-safe.

Parameters
ppointer returned previously by alloc
nmemory size as requrested in the corresponding call to alloc

◆ freeUnlocked()

void Kaskade::Kalloc::freeUnlocked ( void * p,
size_t n )
protected

Releases memory range.

This method is NOT thread-safe. Use this only if you know exactly there's only one thread accessing the allocator.

Referenced by Kaskade::KallocUnlocked::free().

◆ print()

std::ostream & Kaskade::Kalloc::print ( std::ostream & out) const

Prints memory management statistics to the given stream.

◆ reserve()

void Kaskade::Kalloc::reserve ( size_t n,
size_t k )

Tells the allocator that subsequently several blocks of the same size will be requested.

This is a hint to the allocator that can improve its performance.

Parameters
nthe size of the memory blocks to be requested
kthe number of the memory blocks to be requested

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