CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
MemoryManager.h File Reference

Central shared-memory manager for a Psyclone node: master segment, per-subsystem shared maps and the page-based legacy allocator. More...

#include "MemoryController.h"
#include "Utils.h"
#include "ThreadManager.h"
#include "DataMessage.h"
#include "TemporalMemory.h"
#include "ComponentMemory.h"
#include "DataMapsMemory.h"
#include "ProcessMemory.h"
Include dependency graph for MemoryManager.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cmlabs::PsycloneIndexStruct
 Header of the machine-global Psyclone instance index shared-memory segment. More...
struct  cmlabs::PsycloneIndexEntry
 One slot in the machine-global Psyclone instance index. More...
class  cmlabs::PsycloneIndex
 Accessor for the machine-global instance index segment. More...
struct  cmlabs::PerfStats
 Raw per-component performance counters sampled inside shared memory. More...
struct  cmlabs::AveragePerfStats
 Sliding-window averages derived from successive PerfStats snapshots. More...
struct  cmlabs::MemoryMasterStruct
 Root header of the node's master shared-memory segment. More...
class  cmlabs::MasterMemory
 Handle to the node's master shared-memory segment (MemoryMasterStruct). More...
class  cmlabs::MemoryManager
 Top-level facade of the shared-memory subsystem for one process. More...
struct  cmlabs::CMRegister
 Legacy registry block listing the Psyclone system ids present on this machine. More...
struct  cmlabs::MemoryID
 Decomposed form of a 64-bit global memory-block id (legacy page allocator). More...
struct  cmlabs::MemoryBlock
 Size prefix of a raw block inside a MemoryPage (legacy allocator). More...
struct  cmlabs::PagePoolHeader
 Header of the page-pool structure holding reusable, currently idle pages (legacy allocator). More...
struct  cmlabs::PagePoolEntry
 One recyclable page recorded in the page pool (legacy allocator). More...
struct  cmlabs::EOLHeader
 Header of the end-of-life (EOL) time-wheel that schedules page expiry (legacy allocator). More...
struct  cmlabs::EOLEntry
 One page/expiry pair inside an EOL time-wheel slot (legacy allocator). More...
struct  cmlabs::MemoryPage
 In-segment header of one memory page holding packed data blocks (legacy allocator). More...
struct  cmlabs::MemoryPageEntry
 Page-table slot describing one page's identity, size and lock state (legacy allocator). More...
struct  cmlabs::MemoryPageCache
 Header of a process-local (non-shared) cache of mapped page addresses (legacy allocator). More...
struct  cmlabs::MemoryPageCacheEntry
 One process-local cached page mapping; stale when serials mismatch the page table (legacy allocator). More...
struct  cmlabs::MemoryPageMaster
 Root header of the legacy page-allocator segment ("PageMaster"). More...
class  cmlabs::MemoryManagerX
 Legacy page-based shared-memory allocator (predecessor of MemoryManager). More...

Namespaces

namespace  cmlabs

Macros

#define DRAFTMSGSIZE   4096
 Fixed byte size of the per-message draft slots used in the recent-message rings of ComponentStats / ProcessStats.
#define PSYCLONE_INDEX_MAXCOUNT   128
 Maximum number of concurrently tracked Psyclone instances per machine.
#define PSYCLONE_INDEX_SIZE   (sizeof(PsycloneIndexStruct) + (PSYCLONE_INDEX_MAXCOUNT * sizeof(PsycloneIndexEntry)))
 Total byte size of the instance-index shared-memory segment.
#define MAXREGISTERCOUNT   64
 Maximum number of system ids storable in a CMRegister block.
#define NODE_PROCESS_ID   1
 Reserved process id of the node process itself.
#define MAXINSTANCES   256
 Maximum Psyclone process instances per machine.
Node lifecycle status values (PsycloneIndexEntry::status)
#define PSYCLONE_STATUS_NONE   0
 No instance recorded in this slot.
#define PSYCLONE_STATUS_ENDED   1
 Instance has shut down (or crashed and was reaped).
#define PSYCLONE_STATUS_INIT   2
 Instance is starting up, not yet serving.
#define PSYCLONE_STATUS_READY   3
 Instance is fully operational.
Legacy page-allocator address helpers

Pointer arithmetic over the raw in-segment page layout: a MemoryPage header is followed by its block-offset index table, then the packed block data.

#define MP_GetBlockIndexStartLoc(p)
#define MP_GetBlockDataStartLoc(p)
Legacy 64-bit memory-id packing macros

A global block id packs pageID (32 bits), blockID (16 bits) and nodeID (16 bits); these macros compose and extract the fields without shifting at runtime where possible.

#define MP_SYSMEMID   MP_CalcID(0, 0, pageMaster->nodeID)
#define MP_CalcID(pid, bid, nid)
#define MP_SetBlockID(id, var)
#define MP_SetNodeID(id, var)
#define MP_SetPageID(id, var)
#define MP_GetBlockID(id)
#define MP_GetNodeID(id)
#define MP_GetPageID(id)
#define MP_GetBitFieldLoc(m)
#define MP_GetPageTableLoc(m)
#define MP_GetPageEntryLoc(m, pid)
#define MP_GetPageLoc(m, pid)
Legacy page-type classification
#define MP_SYSTEMPAGE   0
 Reserved page holding allocator/system structures.
#define MP_STATICPAGE   1
 Page with non-expiring data.
#define MP_DYNAMICPAGE   2
 Page with end-of-life (expiring) data.
#define MP_GetPageType(id, eol)
 Classify a page by id and eol: reserved ids are system pages; eol > 0 means dynamic.

Functions

THREAD_RET THREAD_FUNCTION_CALL cmlabs::MemoryManagement (THREAD_ARG arg)
 Background maintenance thread entry point for MemoryManager / MemoryManagerX.

Detailed Description

Central shared-memory manager for a Psyclone node: master segment, per-subsystem shared maps and the page-based legacy allocator.

This header is the hub of the CMSDK shared-memory core. A Psyclone system runs as a collection of separate OS processes ("spaces"), each hosting one or more components. All inter-process state — component registries, process/queue tables, data maps and the temporal message store — lives in named shared-memory segments so that any process can crash without corrupting the others (crash isolation), and can re-attach on restart.

The MemoryManager singleton owns/attaches five segments per node instance (keyed by port):

  • the master segment (MasterMemory / MemoryMasterStruct): sizes, serials and time sync,
  • TemporalMemory: slot/bin allocator for time-limited DataMessages,
  • ProcessMemory: process table plus per-process command/message/signal/request queues,
  • ComponentMemory: component registry with parameters, stats and private data,
  • DataMapsMemory: type/context/tag/crank/request name-to-id maps.

On Windows the segments are named file mappings (CreateFileMapping/MapViewOfFile); on POSIX systems (Linux, macOS) they are shm_open/mmap regions — see the shared-memory helpers in Utils for the actual primitive. The structs in this file are the raw on-segment layouts.

Warning
ABI/layout sensitivity: every struct in this header is mapped simultaneously into multiple processes. Their size, field order and alignment are a de-facto ABI. If you change any of these structs you MUST rebuild every binary that maps the segment (make clean && make); mixing binaries built from different layouts silently corrupts shared memory across processes (an ODR/layout violation with no compiler diagnostic).

Definition in file MemoryManager.h.

Macro Definition Documentation

◆ DRAFTMSGSIZE

#define DRAFTMSGSIZE   4096

Fixed byte size of the per-message draft slots used in the recent-message rings of ComponentStats / ProcessStats.

Messages larger than this are truncated when recorded.

Definition at line 113 of file MemoryManager.h.

Referenced by cmlabs::ComponentMemory::addComponentStats(), cmlabs::ProcessMemory::addToProcessStats(), cmlabs::ComponentStats::toXML(), cmlabs::ProcessStats::toXML(), and cmlabs::ComponentMemory::UnitTest().

◆ MAXINSTANCES

#define MAXINSTANCES   256

Maximum Psyclone process instances per machine.

Definition at line 563 of file MemoryManager.h.

◆ MAXREGISTERCOUNT

#define MAXREGISTERCOUNT   64

Maximum number of system ids storable in a CMRegister block.

Definition at line 544 of file MemoryManager.h.

◆ MP_CalcID

#define MP_CalcID ( pid,
bid,
nid )
Value:
((uint64)pid | (((uint64)bid) << 32) | (((uint64)nid) << 48))

Definition at line 680 of file MemoryManager.h.

◆ MP_DYNAMICPAGE

#define MP_DYNAMICPAGE   2

Page with end-of-life (expiring) data.

Definition at line 697 of file MemoryManager.h.

◆ MP_GetBitFieldLoc

#define MP_GetBitFieldLoc ( m)
Value:
((char*)m + sizeof(MemoryPageMaster))

Definition at line 687 of file MemoryManager.h.

◆ MP_GetBlockDataStartLoc

#define MP_GetBlockDataStartLoc ( p)
Value:
(MP_GetBlockIndexStartLoc(p) + (p->blockTableSize*sizeof(uint32)) )
#define MP_GetBlockIndexStartLoc(p)

Definition at line 624 of file MemoryManager.h.

◆ MP_GetBlockID

#define MP_GetBlockID ( id)
Value:
(*(uint16*)((char*)&id + sizeof(uint32)))

Definition at line 684 of file MemoryManager.h.

◆ MP_GetBlockIndexStartLoc

#define MP_GetBlockIndexStartLoc ( p)
Value:
((char*)p + sizeof(MemoryPage))

Definition at line 623 of file MemoryManager.h.

◆ MP_GetNodeID

#define MP_GetNodeID ( id)
Value:
(*(uint16*)((char*)&id + sizeof(uint32) + sizeof(uint16)))

Definition at line 685 of file MemoryManager.h.

◆ MP_GetPageEntryLoc

#define MP_GetPageEntryLoc ( m,
pid )
Value:
(MP_GetPageTableLoc(m) + (pid * sizeof(MemoryPageEntry)) )
#define MP_GetPageTableLoc(m)

Definition at line 689 of file MemoryManager.h.

◆ MP_GetPageID

#define MP_GetPageID ( id)
Value:
(*(uint32*)(char*)&id)

Definition at line 686 of file MemoryManager.h.

◆ MP_GetPageLoc

#define MP_GetPageLoc ( m,
pid )
Value:
((MemoryPageEntry*)MP_GetPageEntryLoc(m,pid))->page
#define MP_GetPageEntryLoc(m, pid)

Definition at line 690 of file MemoryManager.h.

◆ MP_GetPageTableLoc

#define MP_GetPageTableLoc ( m)
Value:
(MP_GetBitFieldLoc(m) + m->bitFieldSize )
#define MP_GetBitFieldLoc(m)

Definition at line 688 of file MemoryManager.h.

◆ MP_GetPageType

#define MP_GetPageType ( id,
eol )
Value:
#define MP_SYSTEMPAGE
Reserved page holding allocator/system structures.
#define MP_DYNAMICPAGE
Page with end-of-life (expiring) data.
#define MP_STATICPAGE
Page with non-expiring data.
#define RESERVEDPAGECOUNT
Number of reserved system pages.
Definition MemoryMaps.h:37

Classify a page by id and eol: reserved ids are system pages; eol > 0 means dynamic.

Definition at line 699 of file MemoryManager.h.

◆ MP_SetBlockID

#define MP_SetBlockID ( id,
var )
Value:
var |= (((uint64)id) << 32)

Definition at line 681 of file MemoryManager.h.

◆ MP_SetNodeID

#define MP_SetNodeID ( id,
var )
Value:
var |= (((uint64)id) << 48)

Definition at line 682 of file MemoryManager.h.

◆ MP_SetPageID

#define MP_SetPageID ( id,
var )
Value:
var |= ((uint64)id)

Definition at line 683 of file MemoryManager.h.

◆ MP_STATICPAGE

#define MP_STATICPAGE   1

Page with non-expiring data.

Definition at line 696 of file MemoryManager.h.

◆ MP_SYSMEMID

#define MP_SYSMEMID   MP_CalcID(0, 0, pageMaster->nodeID)

Definition at line 679 of file MemoryManager.h.

◆ MP_SYSTEMPAGE

#define MP_SYSTEMPAGE   0

Reserved page holding allocator/system structures.

Definition at line 695 of file MemoryManager.h.

◆ NODE_PROCESS_ID

#define NODE_PROCESS_ID   1

Reserved process id of the node process itself.

Definition at line 561 of file MemoryManager.h.

◆ PSYCLONE_INDEX_MAXCOUNT

#define PSYCLONE_INDEX_MAXCOUNT   128

Maximum number of concurrently tracked Psyclone instances per machine.

Definition at line 139 of file MemoryManager.h.

Referenced by cmlabs::PsycloneIndex::GetStatus(), and cmlabs::PsycloneIndex::init().

◆ PSYCLONE_INDEX_SIZE

#define PSYCLONE_INDEX_SIZE   (sizeof(PsycloneIndexStruct) + (PSYCLONE_INDEX_MAXCOUNT * sizeof(PsycloneIndexEntry)))

Total byte size of the instance-index shared-memory segment.

Definition at line 141 of file MemoryManager.h.

Referenced by cmlabs::PsycloneIndex::GetStatus(), cmlabs::PsycloneIndex::init(), cmlabs::MasterMemory::~MasterMemory(), and cmlabs::PsycloneIndex::~PsycloneIndex().

◆ PSYCLONE_STATUS_ENDED

#define PSYCLONE_STATUS_ENDED   1

Instance has shut down (or crashed and was reaped).

Definition at line 106 of file MemoryManager.h.

Referenced by cmlabs::MemoryManager::connect(), cmlabs::MemoryManager::~MemoryManager(), and cmlabs::PsycloneIndex::~PsycloneIndex().

◆ PSYCLONE_STATUS_INIT

#define PSYCLONE_STATUS_INIT   2

Instance is starting up, not yet serving.

Definition at line 107 of file MemoryManager.h.

Referenced by cmlabs::MemoryManager::connect(), and cmlabs::MemoryManager::create().

◆ PSYCLONE_STATUS_NONE

#define PSYCLONE_STATUS_NONE   0

No instance recorded in this slot.

Definition at line 105 of file MemoryManager.h.

Referenced by cmlabs::MemoryManager::connect(), cmlabs::MemoryManager::getNodeStatus(), and cmlabs::PsycloneIndex::GetStatus().

◆ PSYCLONE_STATUS_READY

#define PSYCLONE_STATUS_READY   3

Instance is fully operational.

Definition at line 108 of file MemoryManager.h.

Referenced by cmlabs::MemoryManager::create(), and cmlabs::PsySpace::isConnected().