20 #ifndef MANAGEDMEMORY_H
21 #define MANAGEDMEMORY_H
41 class managedFileSwap_Unit_ManualSwapping_Test;
42 class managedFileSwap_Unit_ManualSwappingDelete_Test;
43 class managedFileSwap_Unit_ManualMultiSwapping_Test;
44 class managedFileSwap_Unit_CheckSwapStats_Test;
45 class cyclicManagedMemory_Integration_ArrayAccess_Test;
50 class managedFileSwap;
51 class managedDummySwap;
53 template<
class T,
int dim>
132 #ifdef PARENTAL_CONTROL
237 template<
class T,
int dim>
244 friend class ::managedFileSwap_Unit_ManualSwapping_Test;
245 friend class ::managedFileSwap_Unit_ManualMultiSwapping_Test;
246 friend class ::managedFileSwap_Unit_ManualSwappingDelete_Test;
247 friend class ::cyclicManagedMemory_Integration_ArrayAccess_Test;
248 friend class ::managedFileSwap_Unit_CheckSwapStats_Test;
virtual bool swapIn(memoryID id)
Convenience function for swapIn ( managedMemoryChunk &chunk )
Exception for errors with the memory.
global_bytesize swap_misses
virtual swapErrorCode swapOut(global_bytesize min_size)=0
swaps out at least min_size bytes
bool setOutOfSwapIsFatal(bool fatal=true)
set policy what to do when out of memory in both ram and swap
global_bytesize getSwappedMemory() const
returns current swap usage
Swapping action was successful.
bool waitForSwapout(managedMemoryChunk &chunk, bool keepSwapLock=false)
Waits until a certain chunk is swapped out.
static void sigswapstats(int sig)
static binding that will print out some stats. Compile with cmake -DSWAPSTATS=on and send process SIG...
static void signalSwappingCond()
signals that a swapping action has completed and memory limits have changed
void recursiveMfree(memoryID id)
recursively deletes the objects in memory, first children, then parents.
bool setUse(memoryID id)
Convenience interface for setUse( managedMemoryChunk &chunk, bool writeAccess )
global_bytesize getTotalSwapMemory() const
return current swap capacity
static bool Throw(memoryException e)
Custom throw function, as we need to prevent throwing exceptions in construtors.
bool mrealloc(memoryID id, global_bytesize sizereq)
this function is a stub. In the future it should be capable of resizing an existing allocation ...
virtual void untouch(managedMemoryChunk &chunk)=0
marks chunk as recently not needed any more
global_bytesize getUsedMemory() const
returns current ram usage
static void versionInfo()
prints out a GIT version info and a diff on this version at compile time
static pthread_cond_t swappingCond
Class that serves as a backend to managedMemory to actual write/read managedMemoryChunks to/from hard...
bool prepareUse(rambrain::managedMemoryChunk &chunk, bool acquireLock=true)
Triggers swapin of chunk.
Main class to allocate memory that is managed by the rambrain memory defaultManager.
global_bytesize swap_out_scheduled_bytes
global_bytesize memory_tobefreed
global_bytesize n_swap_out
static managedMemory * defaultManager
global_bytesize swap_in_bytes_last
An implementation of managedSwap that is capable of kernel asynchronousIO.
void claimTobefreed(global_bytesize bytes, bool tobefreed)
account for future availability of bytes
void resetSwapstats()
reset statistic about the number, size and efficiency of swapping actions
virtual void schedulerRegister(managedMemoryChunk &chunk)=0
gives scheduler code the opportunity to register its own datastructures associated with a chunk ...
static const memoryID root
const global_bytesize gig
global_bytesize n_swap_in
global_bytesize swap_in_scheduled_bytes
void mfree(rambrain::memoryID id, bool inCleanup=false)
this function unregisters and deallocates a chunk
double getTotalSwappedInBytes()
simple Getter
global_bytesize swap_hits
managedMemory * previousManager
static pthread_mutex_t stateChangeMutex
global_bytesize getFreeSwapMemory() const
return current swap free capacity
friend managedSwap * configTestGetSwap(managedMemory *man)
void linearMfree()
linearly deletes all objects in memory
bool ensureEnoughSpace(global_bytesize sizereq, managedMemoryChunk *orIsSwappedin=NULL)
This function ensures that there is sizereq space left in ram.
manages all managed Chunks of raw memory
void closeSwap()
powers down the swap class, ergo a cleanup
managedMemoryChunk * mmalloc(global_bytesize sizereq)
allocates and registers a new raw memory chunk of size sizereq to be filled in by managedPtr ...
global_bytesize memory_used
virtual bool touch(managedMemoryChunk &chunk)=0
marks chunk as recently active as a hint for scheduling
void waitForAIO()
wait for some asynchronous action to occur
std::map< memoryID, managedMemoryChunk * > memChunks
The element/size requested does not fit in RAM as a whole.
void printSwapstats() const
print statistic about the number, size and efficiency of swapping actions
void claimUsageof(global_bytesize bytes, bool rambytes, bool used)
account for memory usage change
We lack reasonable candidates for swapout (too much elements in use?)
global_bytesize swap_in_bytes
bool waitForSwapin(managedMemoryChunk &chunk, bool keepSwapLock=false)
Waits until a certain chunk is present.
global_bytesize getMemoryLimit() const
returns current memory limit
virtual void schedulerDelete(managedMemoryChunk &chunk)=0
signals deletion of chunk to scheduler code
double getTotalSwappedOutBytes()
simple Getter
unsigned int getNumberOfChildren(const memoryID &id)
conveniently returns number of children of the memoryChunk with id id
global_bytesize memory_max
bool setMemoryLimit(global_bytesize size)
dynamically adjusts allowed ram usage
global_bytesize memory_swapped
static pthread_t creatingThread
static const memoryID invalid
swapErrorCode
Error codes for swapOut requests.
A dummy swap that just copies swapped out chunks to a different location in ram.
static pthread_cond_t parentalCond
static pthread_mutex_t parentalMutex
global_bytesize swap_out_bytes
managedMemoryChunk & resolveMemChunk(const memoryID &id)
returns a reference to the memoryChunk indexed by id id
double getHitsOverMisses()
returns current hits over misses rate for accessing elements.
void printTree(managedMemoryChunk *current=NULL, unsigned int nspaces=0)
prints the tree of managed objects for further inspection
global_bytesize swap_out_bytes_last
Backend class to handle raw memory and interaction/storage with managedSwap.
bool unsetUse(memoryID id)
Convenience interface for unsetUse ( managedMemoryChunk &chunk, bool writeAccess ) ...
managedMemory(managedSwap *swap, global_bytesize size=gig)
Standard constructor.