libfoedus-core
FOEDUS Core Library

NUMA-Aware Memory Hierarchy in libfoedus-core. More...

Detailed Description

NUMA-Aware Memory Hierarchy in libfoedus-core.

Overview
We have a memory hierarchy of three levels in libfoedus, resembling the memory hiearchy in NUMA architecture:
  • Memories shared engine-wide (EngineMemory)
  • Memories shared NUMA-Node-wide (NumaNodeMemory)
  • Private Memories in each core (NumaCoreMemory)
The resemblance is intentinal to achieve the best performance of memory allocation/deallocation/sharing in NUMA setting.
Absolutely no global nor truly TLS variables
You might notice that the top level of the hierarchy is engine-wide, not global. libfoedus uses absolutely no global nor static variables except const primitive types. This simplifies the design of memory management in the library and allows running multiple instances (engines) of our library even in one process. What we have in Engine object is everything. When Engine's uninitialize() is invoked, everything the Engine acquired is released, separately from other Engine's. This also means that memory-leak checkers like valgrind can easily check for potential errors.
Note
Unfortunately, there is one exception to this rule; google-logging. google::InitGoogleLogging() and ShutdownGoogleLogging() must be called exactly once in the process. So, we do them in Engine's initialize()/uninitialize() with a process-global atomic counter to make sure we call them only once.
Memories shared engine-wide (EngineMemory)
Overview
This is the top-level memory repository in our engine. All other memory types are contained in this object.
List of engine-wide memories
  • List of NumaNodeMemory, one for each NUMA socket in the machine.
  • Page pool for volatile read/write store (VolatilePage) and the read-only bufferpool (SnapshotPage).
Memories shared NUMA-Node-wide (NumaNodeMemory)
One NumaNodeMemory corresponds to one foedus::thread::ThreadGroup. All threads in the thread group belong to the NUMA node, thus sharing memories between them must be efficient. So, all memories here are allocated/freed via numa_alloc_interleaved(), numa_alloc_onnode(), and numa_free() (except the user specifies to not use them).
Private Memories in each core (NumaCoreMemory)
One NumaCoreMemory corresponds to one foedus::thread::Thread. Each Thread exclusively access its NumaCoreMemory so that it needs no synchronization nor causes cache misses/cache-line ping-pongs. All memories here are allocated/freed via numa_alloc_interleaved(), numa_alloc_onnode(), and numa_free() (except the user specifies to not use them).
Collaboration diagram for Memory Hierarchy:

Classes

class  foedus::memory::EngineMemory
 Repository of all memories dynamically acquired and shared within one database engine. More...
 
struct  foedus::memory::ScopedNumaPreferred
 Automatically sets and resets numa_set_preferred(). More...
 
struct  foedus::memory::NumaCoreMemory::SmallThreadLocalMemoryPieces
 Packs pointers to pieces of small_thread_local_memory_. More...
 
class  foedus::memory::NumaCoreMemory
 Repository of memories dynamically acquired within one CPU core (thread). More...
 
class  foedus::memory::NumaNodeMemory
 Repository of memories dynamically acquired and shared within one NUMA node (socket). More...
 
class  foedus::memory::NumaNodeMemoryRef
 A view of NumaNodeMemory for other SOCs and master engine. More...
 
struct  foedus::thread::NumaThreadScope
 Pin the current thread to the given NUMA node in this object's scope. More...
 

Class Documentation

struct foedus::memory::NumaCoreMemory::SmallThreadLocalMemoryPieces

Packs pointers to pieces of small_thread_local_memory_.

Definition at line 49 of file numa_core_memory.hpp.

Class Members
char * sysxct_workspace_memory_
char * xct_lock_free_read_access_memory_
char * xct_lock_free_write_access_memory_
char * xct_page_version_memory_
char * xct_pointer_access_memory_
char * xct_read_access_memory_
char * xct_write_access_memory_