|
rambrain
|
Backend class to handle raw memory and interaction/storage with managedSwap. More...
#include <managedMemory.h>
Public Member Functions | |
| 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... | |
Static Public Member Functions | |
| 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 | |
| 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 managedMemory * | defaultManager |
| static const memoryID | invalid = 0 |
Protected Types | |
| enum | swapErrorCode { ERR_SUCCESS, ERR_SWAPFULL, ERR_MORETHANTOTALRAM, ERR_NOTENOUGHCANDIDATES } |
| Error codes for swapOut requests. More... | |
Protected Member Functions | |
| managedMemoryChunk * | mmalloc (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... | |
| managedMemoryChunk & | resolveMemChunk (const memoryID &id) |
| returns a reference to the memoryChunk indexed by id id More... | |
| virtual swapErrorCode | swapOut (global_bytesize min_size)=0 |
| swaps out at least min_size bytes More... | |
| virtual bool | swapIn (memoryID id) |
| Convenience function for swapIn ( managedMemoryChunk &chunk ) More... | |
| virtual bool | swapIn (managedMemoryChunk &chunk)=0 |
| Tries to swap in chunk chunk. More... | |
| virtual bool | touch (managedMemoryChunk &chunk)=0 |
| marks chunk as recently active as a hint for scheduling More... | |
| virtual void | untouch (managedMemoryChunk &chunk)=0 |
| marks chunk as recently not needed any more More... | |
| virtual void | schedulerRegister (managedMemoryChunk &chunk)=0 |
| gives scheduler code the opportunity to register its own datastructures associated with a chunk More... | |
| virtual void | schedulerDelete (managedMemoryChunk &chunk)=0 |
| signals deletion of chunk to scheduler code 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 | |
| static bool | Throw (memoryException e) |
| Custom throw function, as we need to prevent throwing exceptions in construtors. More... | |
Protected Attributes | |
| managedSwap * | swap = 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 |
| managedMemory * | previousManager |
| 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 | |
| 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 |
Friends | |
| template<class T , int dim> | |
| class | managedPtr |
| class | managedSwap |
| class | managedFileSwap |
| class | managedDummySwap |
| class | ::managedFileSwap_Unit_ManualSwapping_Test |
| class | ::managedFileSwap_Unit_ManualMultiSwapping_Test |
| class | ::managedFileSwap_Unit_ManualSwappingDelete_Test |
| class | ::cyclicManagedMemory_Integration_ArrayAccess_Test |
| class | ::managedFileSwap_Unit_CheckSwapStats_Test |
| managedSwap * | configTestGetSwap (managedMemory *man) |
Backend class to handle raw memory and interaction/storage with managedSwap.
This class's implementation is written to standardize most of interactions between swap and managedMemory derived classes. Implementation supports asynchronous actions. While there may be more parallelism possible we currently support only one mutex ( stateChangeMutex ) to make this thread-safe to keep things simple at the moment.
Definition at line 68 of file managedMemory.h.
|
protected |
Error codes for swapOut requests.
Definition at line 171 of file managedMemory.h.
| rambrain::managedMemory::managedMemory | ( | managedSwap * | swap, |
| global_bytesize | size = gig |
||
| ) |
Standard constructor.
| swap | The swap that this manager should use. |
| size | The net size of memory that is allowed in allocation. Be aware of leaving enough space for overhead. |
Definition at line 64 of file managedMemory.cpp.
|
virtual |
Definition at line 90 of file managedMemory.cpp.
|
protected |
account for future availability of bytes
| bytes | number of bytes under consideration |
| tobefreed | sum of bytes will be increased if true, else decreased. |
Definition at line 814 of file managedMemory.cpp.
|
protected |
account for memory usage change
| bytes | number of bytes under consideration |
| rambytes | set this to true if you want to signal different usage for bytes residing in rambytes |
| used | sum of bytes will be increased if true, else decreased. |
Definition at line 804 of file managedMemory.cpp.
| void rambrain::managedMemory::closeSwap | ( | ) |
powers down the swap class, ergo a cleanup
Definition at line 118 of file managedMemory.cpp.
|
protected |
This function ensures that there is sizereq space left in ram.
| orisSwappedin | if not null, this chunk will be checked for ram presence |
orisSwappedin is set, return value tells whether the chunk orisSwappedin is pointing to has been or is about to be swapped in. Otherwise false Definition at line 185 of file managedMemory.cpp.
| global_bytesize rambrain::managedMemory::getFreeSwapMemory | ( | ) | const |
return current swap free capacity
Definition at line 136 of file managedMemory.cpp.
| double rambrain::managedMemory::getHitsOverMisses | ( | ) |
returns current hits over misses rate for accessing elements.
Definition at line 708 of file managedMemory.cpp.
|
inline |
returns current memory limit
Definition at line 93 of file managedMemory.h.
| unsigned int rambrain::managedMemory::getNumberOfChildren | ( | const memoryID & | id | ) |
conveniently returns number of children of the memoryChunk with id id
Definition at line 527 of file managedMemory.cpp.
| global_bytesize rambrain::managedMemory::getSwappedMemory | ( | ) | const |
returns current swap usage
Definition at line 131 of file managedMemory.cpp.
| global_bytesize rambrain::managedMemory::getTotalSwapMemory | ( | ) | const |
return current swap capacity
Definition at line 141 of file managedMemory.cpp.
|
inline |
simple Getter
Definition at line 318 of file managedMemory.h.
|
inline |
simple Getter
Definition at line 314 of file managedMemory.h.
| global_bytesize rambrain::managedMemory::getUsedMemory | ( | ) | const |
returns current ram usage
Definition at line 126 of file managedMemory.cpp.
| void rambrain::managedMemory::linearMfree | ( | ) |
linearly deletes all objects in memory
Definition at line 618 of file managedMemory.cpp.
|
protected |
this function unregisters and deallocates a chunk
Definition at line 460 of file managedMemory.cpp.
|
protected |
allocates and registers a new raw memory chunk of size sizereq to be filled in by managedPtr
Definition at line 235 of file managedMemory.cpp.
|
protected |
this function is a stub. In the future it should be capable of resizing an existing allocation
Definition at line 379 of file managedMemory.cpp.
| bool rambrain::managedMemory::prepareUse | ( | rambrain::managedMemoryChunk & | chunk, |
| bool | acquireLock = true |
||
| ) |
Triggers swapin of chunk.
Definition at line 297 of file managedMemory.cpp.
| void rambrain::managedMemory::printSwapstats | ( | ) | const |
print statistic about the number, size and efficiency of swapping actions
Definition at line 639 of file managedMemory.cpp.
| void rambrain::managedMemory::printTree | ( | managedMemoryChunk * | current = NULL, |
| unsigned int | nspaces = 0 |
||
| ) |
prints the tree of managed objects for further inspection
Definition at line 546 of file managedMemory.cpp.
| void rambrain::managedMemory::recursiveMfree | ( | memoryID | id | ) |
recursively deletes the objects in memory, first children, then parents.
Definition at line 597 of file managedMemory.cpp.
| void rambrain::managedMemory::resetSwapstats | ( | ) |
reset statistic about the number, size and efficiency of swapping actions
Definition at line 651 of file managedMemory.cpp.
|
protected |
returns a reference to the memoryChunk indexed by id id
Definition at line 633 of file managedMemory.cpp.
|
protectedpure virtual |
signals deletion of chunk to scheduler code
Implemented in rambrain::cyclicManagedMemory, and rambrain::dummyManagedMemory.
|
protectedpure virtual |
gives scheduler code the opportunity to register its own datastructures associated with a chunk
Implemented in rambrain::cyclicManagedMemory, and rambrain::dummyManagedMemory.
| bool rambrain::managedMemory::setMemoryLimit | ( | global_bytesize | size | ) |
dynamically adjusts allowed ram usage
| size | desired allowed ram size |
Definition at line 146 of file managedMemory.cpp.
| bool rambrain::managedMemory::setOutOfSwapIsFatal | ( | bool | fatal = true | ) |
set policy what to do when out of memory in both ram and swap
Definition at line 177 of file managedMemory.cpp.
| bool rambrain::managedMemory::setUse | ( | memoryID | id | ) |
Convenience interface for setUse( managedMemoryChunk &chunk, bool writeAccess )
Definition at line 411 of file managedMemory.cpp.
| bool rambrain::managedMemory::setUse | ( | managedMemoryChunk & | chunk, |
| bool | writeAccess = false |
||
| ) |
Marks chunk as used and prevents swapout.
| chunk | the chunk that will be used |
| writeAccess | set this to false if the chunk will not be written to |
Definition at line 333 of file managedMemory.cpp.
|
static |
signals that a swapping action has completed and memory limits have changed
Definition at line 742 of file managedMemory.cpp.
|
static |
static binding that will print out some stats. Compile with cmake -DSWAPSTATS=on and send process SIGUSR1 to call this function
Definition at line 658 of file managedMemory.cpp.
|
protectedvirtual |
Convenience function for swapIn ( managedMemoryChunk &chunk )
Definition at line 291 of file managedMemory.cpp.
|
protectedpure virtual |
Tries to swap in chunk chunk.
| chunk | the chunk subject to be swapped in Successful return does not mean that the chunk is available at an instant. It may be necessary for asynchronous swapIn to complete beforehands. |
Implemented in rambrain::cyclicManagedMemory, and rambrain::dummyManagedMemory.
|
protectedpure virtual |
swaps out at least min_size bytes
| min_size | minimum size of swapped out elements Sucessful return does not mean that the bytes are available at an instant. It may be necessary for swapOut to complete beforehands. |
Implemented in rambrain::cyclicManagedMemory, and rambrain::dummyManagedMemory.
|
staticprotected |
Custom throw function, as we need to prevent throwing exceptions in construtors.
Definition at line 443 of file managedMemory.cpp.
|
protectedpure virtual |
marks chunk as recently active as a hint for scheduling
Implemented in rambrain::cyclicManagedMemory, and rambrain::dummyManagedMemory.
| bool rambrain::managedMemory::unsetUse | ( | memoryID | id | ) |
Convenience interface for unsetUse ( managedMemoryChunk &chunk, bool writeAccess )
Definition at line 404 of file managedMemory.cpp.
| bool rambrain::managedMemory::unsetUse | ( | managedMemoryChunk & | chunk, |
| unsigned int | no_unsets = 1 |
||
| ) |
Marks chunk as unused again.
| chunk | the chunk that will not be needed in near future |
| no_unsets | if you set use to the chunk n times, you may set this to n instead of calling n times |
Definition at line 417 of file managedMemory.cpp.
|
protectedpure virtual |
marks chunk as recently not needed any more
Implemented in rambrain::cyclicManagedMemory, and rambrain::dummyManagedMemory.
|
static |
prints out a GIT version info and a diff on this version at compile time
Definition at line 716 of file managedMemory.cpp.
|
protected |
wait for some asynchronous action to occur
Definition at line 747 of file managedMemory.cpp.
|
protected |
Waits until a certain chunk is present.
Definition at line 757 of file managedMemory.cpp.
|
protected |
Waits until a certain chunk is swapped out.
Definition at line 779 of file managedMemory.cpp.
|
friend |
Definition at line 247 of file managedMemory.h.
|
friend |
Definition at line 248 of file managedMemory.h.
|
friend |
Definition at line 245 of file managedMemory.h.
|
friend |
Definition at line 244 of file managedMemory.h.
|
friend |
Definition at line 246 of file managedMemory.h.
|
friend |
Definition at line 31 of file configTest.cpp.
|
friend |
Definition at line 241 of file managedMemory.h.
|
friend |
Definition at line 240 of file managedMemory.h.
|
friend |
Definition at line 238 of file managedMemory.h.
|
friend |
Definition at line 239 of file managedMemory.h.
|
protected |
Definition at line 224 of file managedMemory.h.
|
static |
Definition at line 145 of file managedMemory.h.
|
static |
Definition at line 152 of file managedMemory.h.
|
staticprotected |
Definition at line 301 of file managedMemory.h.
|
static |
Definition at line 153 of file managedMemory.h.
|
staticprotected |
Definition at line 300 of file managedMemory.h.
|
protected |
Definition at line 222 of file managedMemory.h.
|
protected |
Definition at line 225 of file managedMemory.h.
|
protected |
Definition at line 216 of file managedMemory.h.
|
protected |
Definition at line 218 of file managedMemory.h.
|
protected |
Definition at line 219 of file managedMemory.h.
|
protected |
Definition at line 217 of file managedMemory.h.
|
protected |
Definition at line 297 of file managedMemory.h.
|
protected |
Definition at line 255 of file managedMemory.h.
|
protected |
Definition at line 254 of file managedMemory.h.
|
protected |
Definition at line 220 of file managedMemory.h.
|
static |
Definition at line 140 of file managedMemory.h.
|
static |
Definition at line 144 of file managedMemory.h.
|
static |
Definition at line 143 of file managedMemory.h.
|
protected |
Definition at line 228 of file managedMemory.h.
|
static |
Definition at line 139 of file managedMemory.h.
|
staticprotected |
Definition at line 232 of file managedMemory.h.
|
protected |
Definition at line 214 of file managedMemory.h.
|
protected |
Definition at line 266 of file managedMemory.h.
|
protected |
Definition at line 261 of file managedMemory.h.
|
protected |
Definition at line 264 of file managedMemory.h.
|
protected |
Definition at line 259 of file managedMemory.h.
|
protected |
Definition at line 267 of file managedMemory.h.
|
protected |
Definition at line 260 of file managedMemory.h.
|
protected |
Definition at line 263 of file managedMemory.h.
|
protected |
Definition at line 258 of file managedMemory.h.
|
staticprotected |
Definition at line 234 of file managedMemory.h.
|
static |
Definition at line 142 of file managedMemory.h.