rambrain
rambrain::cyclicManagedMemory Class Reference

scheduler working with a double linked cycle. Details see paper. More...

#include <cyclicManagedMemory.h>

Inheritance diagram for rambrain::cyclicManagedMemory:
rambrain::managedMemory

Classes

struct  chain
 

Public Member Functions

 cyclicManagedMemory (rambrain::managedSwap *swap, rambrain::global_bytesize size)
 
virtual ~cyclicManagedMemory ()
 
void printCycle () const
 prints out all elements known to the scheduler with their respective status More...
 
void printMemUsage () const
 prints out current memory usage More...
 
bool checkCycle ()
 checks whether the scheduler believes to be sane and prints an error message if not More...
 
bool setPreemptiveLoading (bool preemptive)
 sets whether scheduler should guess next needed items More...
 
bool setPreemptiveUnloading (bool preemptive)
 sets whether scheduler should swap out elements without strict need More...
 
- Public Member Functions inherited from rambrain::managedMemory
 managedMemory (managedSwap *swap, global_bytesize size=gig)
 Standard constructor. More...
 
virtual ~managedMemory ()
 
void closeSwap ()
 powers down the swap class, ergo a cleanup More...
 
bool setMemoryLimit (global_bytesize size)
 dynamically adjusts allowed ram usage More...
 
global_bytesize getMemoryLimit () const
 returns current memory limit More...
 
global_bytesize getUsedMemory () const
 returns current ram usage More...
 
global_bytesize getSwappedMemory () const
 returns current swap usage More...
 
global_bytesize getFreeSwapMemory () const
 return current swap free capacity More...
 
global_bytesize getTotalSwapMemory () const
 return current swap capacity More...
 
bool setOutOfSwapIsFatal (bool fatal=true)
 set policy what to do when out of memory in both ram and swap More...
 
bool prepareUse (rambrain::managedMemoryChunk &chunk, bool acquireLock=true)
 Triggers swapin of chunk. More...
 
bool setUse (memoryID id)
 Convenience interface for setUse( managedMemoryChunk &chunk, bool writeAccess ) More...
 
bool unsetUse (memoryID id)
 Convenience interface for unsetUse ( managedMemoryChunk &chunk, bool writeAccess ) More...
 
bool setUse (managedMemoryChunk &chunk, bool writeAccess)
 Marks chunk as used and prevents swapout. More...
 
bool unsetUse (managedMemoryChunk &chunk, unsigned int no_unsets=1)
 Marks chunk as unused again. More...
 
unsigned int getNumberOfChildren (const memoryID &id)
 conveniently returns number of children of the memoryChunk with id id More...
 
void printTree (managedMemoryChunk *current=NULL, unsigned int nspaces=0)
 prints the tree of managed objects for further inspection More...
 
void recursiveMfree (memoryID id)
 recursively deletes the objects in memory, first children, then parents. More...
 
void linearMfree ()
 linearly deletes all objects in memory More...
 
void printSwapstats () const
 print statistic about the number, size and efficiency of swapping actions More...
 
void resetSwapstats ()
 reset statistic about the number, size and efficiency of swapping actions More...
 
double getHitsOverMisses ()
 returns current hits over misses rate for accessing elements. More...
 
double getTotalSwappedOutBytes ()
 simple Getter More...
 
double getTotalSwappedInBytes ()
 simple Getter More...
 

Private Member Functions

virtual bool swapIn (managedMemoryChunk &chunk)
 cyclic implementation of swapIn, see paper More...
 
virtual swapErrorCode swapOut (global_bytesize min_size)
 cyclic implementation of swapOut, see paper More...
 
virtual bool touch (managedMemoryChunk &chunk)
 marks chunk as recently active as a hint for scheduling More...
 
virtual void untouch (managedMemoryChunk &chunk)
 tries to regulate immediately usable free memory in ram to a level optimal for preemptive loading More...
 
virtual void schedulerRegister (managedMemoryChunk &chunk)
 gives scheduler code the opportunity to register its own datastructures associated with a chunk More...
 
virtual void schedulerDelete (managedMemoryChunk &chunk)
 signals deletion of chunk to scheduler code More...
 
void decay (global_bytesize bytes)
 : Tries to unload around bytes bytes of preemptive elements More...
 
struct cyclicManagedMemory::chain filterChain (chain &toFilter, const memoryStatus *separateStatus, bool *preemptiveLoaded=NULL)
 : separates all chunks matching state in list separateStatus or preeemptiveLoaded from the ring More...
 
void printBacklog () const
 

Static Private Member Functions

static void insertBefore (cyclicAtime *pos, chain separated)
 
static void printChain (const char *name, const chain mchain)
 

Private Attributes

cyclicAtimeactive = NULL
 
cyclicAtimecounterActive = NULL
 
cyclicAtimepreemptiveStart = NULL
 
float swapOutFrac = .8
 
float swapInFrac = .9
 
bool preemtiveSwapIn = true
 
bool preemtiveSwapOut = true
 
global_bytesize preemptiveBytes = 0
 
unsigned int consecutivePreemptiveTransactions = 0
 
unsigned int preemptiveSinceLast = 0
 
double preemptiveTurnoffFraction = .01
 
backlog_entry backlog [backlog_size]
 
unsigned int backlog_pos = 0
 

Static Private Attributes

static pthread_mutex_t cyclicTopoLock = PTHREAD_MUTEX_INITIALIZER
 
static const unsigned int backlog_size = 100
 

Additional Inherited Members

- Static Public Member Functions inherited from rambrain::managedMemory
static void signalSwappingCond ()
 signals that a swapping action has completed and memory limits have changed More...
 
static void sigswapstats (int sig)
 static binding that will print out some stats. Compile with cmake -DSWAPSTATS=on and send process SIGUSR1 to call this function More...
 
static void versionInfo ()
 prints out a GIT version info and a diff on this version at compile time More...
 
- Static Public Attributes inherited from rambrain::managedMemory
static const memoryID root = 1
 
static memoryID parent = managedMemory::root
 
static bool threadSynced = false
 
static pthread_mutex_t parentalMutex = PTHREAD_MUTEX_INITIALIZER
 
static pthread_cond_t parentalCond = PTHREAD_COND_INITIALIZER
 
static pthread_t creatingThread = 0
 
static managedMemorydefaultManager
 
static const memoryID invalid = 0
 
- Protected Types inherited from rambrain::managedMemory
enum  swapErrorCode { ERR_SUCCESS, ERR_SWAPFULL, ERR_MORETHANTOTALRAM, ERR_NOTENOUGHCANDIDATES }
 Error codes for swapOut requests. More...
 
- Protected Member Functions inherited from rambrain::managedMemory
managedMemoryChunkmmalloc (global_bytesize sizereq)
 allocates and registers a new raw memory chunk of size sizereq to be filled in by managedPtr More...
 
bool mrealloc (memoryID id, global_bytesize sizereq)
 this function is a stub. In the future it should be capable of resizing an existing allocation More...
 
void mfree (rambrain::memoryID id, bool inCleanup=false)
 this function unregisters and deallocates a chunk More...
 
managedMemoryChunkresolveMemChunk (const memoryID &id)
 returns a reference to the memoryChunk indexed by id id More...
 
virtual bool swapIn (memoryID id)
 Convenience function for swapIn ( managedMemoryChunk &chunk ) More...
 
bool ensureEnoughSpace (global_bytesize sizereq, managedMemoryChunk *orIsSwappedin=NULL)
 This function ensures that there is sizereq space left in ram. More...
 
bool waitForSwapin (managedMemoryChunk &chunk, bool keepSwapLock=false)
 Waits until a certain chunk is present. More...
 
bool waitForSwapout (managedMemoryChunk &chunk, bool keepSwapLock=false)
 Waits until a certain chunk is swapped out. More...
 
void claimUsageof (global_bytesize bytes, bool rambytes, bool used)
 account for memory usage change More...
 
void claimTobefreed (global_bytesize bytes, bool tobefreed)
 account for future availability of bytes More...
 
void waitForAIO ()
 wait for some asynchronous action to occur More...
 
- Static Protected Member Functions inherited from rambrain::managedMemory
static bool Throw (memoryException e)
 Custom throw function, as we need to prevent throwing exceptions in construtors. More...
 
- Protected Attributes inherited from rambrain::managedMemory
managedSwapswap = 0
 
global_bytesize memory_max
 
global_bytesize memory_used = 0
 
global_bytesize memory_swapped = 0
 
global_bytesize memory_tobefreed = 0
 
bool outOfSwapIsFatal = true
 
std::map< memoryID, managedMemoryChunk * > memChunks
 
memoryAtime atime = 0
 
memoryID memID_pace = 1
 
managedMemorypreviousManager
 
global_bytesize n_swap_out = 0
 
global_bytesize n_swap_in = 0
 
global_bytesize swap_out_scheduled_bytes = 0
 
global_bytesize swap_in_scheduled_bytes = 0
 
global_bytesize swap_out_bytes = 0
 
global_bytesize swap_in_bytes = 0
 
global_bytesize swap_out_bytes_last = 0
 
global_bytesize swap_in_bytes_last = 0
 
global_bytesize swap_hits = 0
 
global_bytesize swap_misses = 0
 
size_t memoryAlignment = 1
 
- Static Protected Attributes inherited from rambrain::managedMemory
static pthread_mutex_t stateChangeMutex = PTHREAD_MUTEX_INITIALIZER
 
static pthread_cond_t swappingCond = PTHREAD_COND_INITIALIZER
 
static FILE * logFile = fopen ( "rambrain-swapstats.log", "w" )
 
static bool firstLog = true
 

Detailed Description

scheduler working with a double linked cycle. Details see paper.

Definition at line 50 of file cyclicManagedMemory.h.

Constructor & Destructor Documentation

rambrain::cyclicManagedMemory::cyclicManagedMemory ( rambrain::managedSwap swap,
rambrain::global_bytesize  size 
)

Definition at line 47 of file cyclicManagedMemory.cpp.

rambrain::cyclicManagedMemory::~cyclicManagedMemory ( )
virtual

Definition at line 1095 of file cyclicManagedMemory.cpp.

Member Function Documentation

bool rambrain::cyclicManagedMemory::checkCycle ( )

checks whether the scheduler believes to be sane and prints an error message if not

Returns
true if sane, false if not

Definition at line 653 of file cyclicManagedMemory.cpp.

void rambrain::cyclicManagedMemory::decay ( global_bytesize  bytes)
private

: Tries to unload around bytes bytes of preemptive elements

Definition at line 309 of file cyclicManagedMemory.cpp.

cyclicManagedMemory::chain rambrain::cyclicManagedMemory::filterChain ( chain toFilter,
const memoryStatus separateStatus,
bool *  preemptiveLoaded = NULL 
)
private

: separates all chunks matching state in list separateStatus or preeemptiveLoaded from the ring

Definition at line 224 of file cyclicManagedMemory.cpp.

void rambrain::cyclicManagedMemory::insertBefore ( cyclicAtime pos,
cyclicManagedMemory::chain  separated 
)
staticprivate

Definition at line 212 of file cyclicManagedMemory.cpp.

void rambrain::cyclicManagedMemory::printBacklog ( ) const
private

Definition at line 1106 of file cyclicManagedMemory.cpp.

void rambrain::cyclicManagedMemory::printChain ( const char *  name,
const chain  mchain 
)
staticprivate

Definition at line 878 of file cyclicManagedMemory.cpp.

void rambrain::cyclicManagedMemory::printCycle ( ) const

prints out all elements known to the scheduler with their respective status

Definition at line 813 of file cyclicManagedMemory.cpp.

void rambrain::cyclicManagedMemory::printMemUsage ( ) const

prints out current memory usage

Definition at line 207 of file cyclicManagedMemory.cpp.

void rambrain::cyclicManagedMemory::schedulerDelete ( managedMemoryChunk chunk)
privatevirtual

signals deletion of chunk to scheduler code

Implements rambrain::managedMemory.

Definition at line 80 of file cyclicManagedMemory.cpp.

void rambrain::cyclicManagedMemory::schedulerRegister ( managedMemoryChunk chunk)
privatevirtual

gives scheduler code the opportunity to register its own datastructures associated with a chunk

Implements rambrain::managedMemory.

Definition at line 52 of file cyclicManagedMemory.cpp.

bool rambrain::cyclicManagedMemory::setPreemptiveLoading ( bool  preemptive)

sets whether scheduler should guess next needed items

Parameters
preemtiveiff set to true, scheduler will guess (default)
Note
not thread-safe - does not make sense to call it from different threads anyway
Returns
previous value

Definition at line 193 of file cyclicManagedMemory.cpp.

bool rambrain::cyclicManagedMemory::setPreemptiveUnloading ( bool  preemptive)

sets whether scheduler should swap out elements without strict need

Parameters
preemtiveiff set to true, scheduler will guess (default)
Note
not thread-safe - does not make sense to call it from different threads anyway
Returns
previous value

Definition at line 200 of file cyclicManagedMemory.cpp.

bool rambrain::cyclicManagedMemory::swapIn ( managedMemoryChunk chunk)
privatevirtual

cyclic implementation of swapIn, see paper

Note
protect call to swapIn by topologicalMutex
Todo:
in rare cases, these two lines are necessary as the readEl is also filtered. We should find out if we can leave this out somehow more elegant.

Implements rambrain::managedMemory.

Definition at line 381 of file cyclicManagedMemory.cpp.

cyclicManagedMemory::swapErrorCode rambrain::cyclicManagedMemory::swapOut ( rambrain::global_bytesize  min_size)
privatevirtual

cyclic implementation of swapOut, see paper

Note
protect call to swapIn by topologicalMutex
Todo:
investigate if subtracting swapped out preemptive bytes is affecting performance ( too much preemptive action possible ). Naively testing, this is not the case.

Implements rambrain::managedMemory.

Definition at line 898 of file cyclicManagedMemory.cpp.

bool rambrain::cyclicManagedMemory::touch ( managedMemoryChunk chunk)
privatevirtual

marks chunk as recently active as a hint for scheduling

Implements rambrain::managedMemory.

Definition at line 128 of file cyclicManagedMemory.cpp.

void rambrain::cyclicManagedMemory::untouch ( managedMemoryChunk chunk)
privatevirtual

tries to regulate immediately usable free memory in ram to a level optimal for preemptive loading

Implements rambrain::managedMemory.

Definition at line 636 of file cyclicManagedMemory.cpp.

Member Data Documentation

cyclicAtime* rambrain::cyclicManagedMemory::active = NULL
private

Definition at line 106 of file cyclicManagedMemory.h.

backlog_entry rambrain::cyclicManagedMemory::backlog[backlog_size]
private

Definition at line 131 of file cyclicManagedMemory.h.

unsigned int rambrain::cyclicManagedMemory::backlog_pos = 0
private

Definition at line 132 of file cyclicManagedMemory.h.

const unsigned int rambrain::cyclicManagedMemory::backlog_size = 100
staticprivate

Definition at line 130 of file cyclicManagedMemory.h.

unsigned int rambrain::cyclicManagedMemory::consecutivePreemptiveTransactions = 0
private

Definition at line 116 of file cyclicManagedMemory.h.

cyclicAtime* rambrain::cyclicManagedMemory::counterActive = NULL
private

Definition at line 107 of file cyclicManagedMemory.h.

pthread_mutex_t rambrain::cyclicManagedMemory::cyclicTopoLock = PTHREAD_MUTEX_INITIALIZER
staticprivate

Definition at line 119 of file cyclicManagedMemory.h.

global_bytesize rambrain::cyclicManagedMemory::preemptiveBytes = 0
private

Definition at line 115 of file cyclicManagedMemory.h.

unsigned int rambrain::cyclicManagedMemory::preemptiveSinceLast = 0
private

Definition at line 117 of file cyclicManagedMemory.h.

cyclicAtime* rambrain::cyclicManagedMemory::preemptiveStart = NULL
private

Definition at line 108 of file cyclicManagedMemory.h.

double rambrain::cyclicManagedMemory::preemptiveTurnoffFraction = .01
private

Definition at line 121 of file cyclicManagedMemory.h.

bool rambrain::cyclicManagedMemory::preemtiveSwapIn = true
private

Definition at line 113 of file cyclicManagedMemory.h.

bool rambrain::cyclicManagedMemory::preemtiveSwapOut = true
private

Definition at line 114 of file cyclicManagedMemory.h.

float rambrain::cyclicManagedMemory::swapInFrac = .9
private

Definition at line 111 of file cyclicManagedMemory.h.

float rambrain::cyclicManagedMemory::swapOutFrac = .8
private

Definition at line 110 of file cyclicManagedMemory.h.


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