rambrain
rambrain::managedSwap Class Referenceabstract

Class that serves as a backend to managedMemory to actual write/read managedMemoryChunks to/from hard disk or other non random access memory. More...

#include <managedSwap.h>

Inheritance diagram for rambrain::managedSwap:
rambrain::managedDummySwap rambrain::managedFileSwap

Public Member Functions

 managedSwap (global_bytesize size)
 
virtual ~managedSwap ()
 
virtual global_bytesize swapOut (managedMemoryChunk **chunklist, unsigned int nchunks)=0
 Trigger swap out of the chunks pointed to by chunklist. More...
 
virtual global_bytesize swapOut (managedMemoryChunk *chunk)=0
 Trigger swap out of the chunk pointed to by chunk. More...
 
virtual global_bytesize swapIn (managedMemoryChunk **chunklist, unsigned int nchunks)=0
 Trigger swap in of the chunks pointed to by chunklist. More...
 
virtual global_bytesize swapIn (managedMemoryChunk *chunk)=0
 Trigger swap in of the chunk pointed to by chunk. More...
 
virtual void swapDelete (managedMemoryChunk *chunk)=0
 Mark chunk as deleted. More...
 
virtual bool extendSwapByPolicy (global_bytesize min_size)
 extend swap by policy More...
 
virtual bool extendSwap (global_bytesize size)
 extend swap by size number of bytes More...
 
virtual global_bytesize getSwapSize () const
 Simple getter. More...
 
virtual global_bytesize getUsedSwap () const
 Simple getter. More...
 
virtual global_bytesize getFreeSwap () const
 Simple getter. More...
 
virtual swapPolicy getSwapPolicy () const
 
virtual swapPolicy setSwapPolicy (swapPolicy newPolicy)
 
size_t getMemoryAlignment () const
 Returns possible memory alignment restrictions. More...
 
void claimUsageof (global_bytesize bytes, bool rambytes, bool used)
 account for memory usage change More...
 
void waitForCleanExit ()
 Function waits for all asynchronous IO to complete. The wait is implemented non-performant as a normal user does not have to wait for this. Implementing this with a _cond just destroys performance in the respective swapIn/out procedures without increasing any user space functionality. More...
 
virtual bool checkForAIO ()
 
virtual void close ()=0
 Close the swap if not already closed. More...
 
virtual bool cleanupCachedElements (rambrain::global_bytesize minimum_size=0)
 throws out cached elements still in ram but also resident on disk. This makes space in situations of low swap memory More...
 
virtual void invalidateCacheFor (managedMemoryChunk &chunk)
 tells managedFileSwap that the chunk under consideration might have been changed by user and needs to be copied out freshly More...
 

Protected Attributes

global_bytesize swapSize
 
global_bytesize swapUsed
 
global_bytesize swapFree
 
unsigned int totalSwapActionsQueued = 0
 
size_t memoryAlignment = 1
 
swapPolicy policy = swapPolicy::fixed
 
bool closed = false
 

Detailed Description

Class that serves as a backend to managedMemory to actual write/read managedMemoryChunks to/from hard disk or other non random access memory.

Note
when trying to write your own version, consider studying managedFileSwap as a reference implementation

Definition at line 35 of file managedSwap.h.

Constructor & Destructor Documentation

rambrain::managedSwap::managedSwap ( global_bytesize  size)

Definition at line 26 of file managedSwap.cpp.

rambrain::managedSwap::~managedSwap ( )
virtual

Definition at line 30 of file managedSwap.cpp.

Member Function Documentation

virtual bool rambrain::managedSwap::checkForAIO ( )
inlinevirtual

Reimplemented in rambrain::managedFileSwap.

Definition at line 122 of file managedSwap.h.

void rambrain::managedSwap::claimUsageof ( global_bytesize  bytes,
bool  rambytes,
bool  used 
)

account for memory usage change

Parameters
bytesnumber of bytes under consideration
rambytesset this to true if you want to signal different usage for bytes residing in rambytes
usedsum of bytes will be increased if true, else decreased.
Note
this function must be called having stateChangeMutex acquired.

Definition at line 35 of file managedSwap.cpp.

virtual bool rambrain::managedSwap::cleanupCachedElements ( rambrain::global_bytesize  minimum_size = 0)
inlinevirtual

throws out cached elements still in ram but also resident on disk. This makes space in situations of low swap memory

Note
this function must be called having stateChangeMutex acquired.

Reimplemented in rambrain::managedFileSwap.

Definition at line 137 of file managedSwap.h.

virtual void rambrain::managedSwap::close ( )
pure virtual

Close the swap if not already closed.

Note
Not automatically done by destructor
Warning
Swap can not be used anymore afterwards

Implemented in rambrain::managedFileSwap, and rambrain::managedDummySwap.

virtual bool rambrain::managedSwap::extendSwap ( global_bytesize  size)
inlinevirtual

extend swap by size number of bytes

Returns
success

Reimplemented in rambrain::managedFileSwap.

Definition at line 76 of file managedSwap.h.

virtual bool rambrain::managedSwap::extendSwapByPolicy ( global_bytesize  min_size)
inlinevirtual

extend swap by policy

Returns
success
Parameters
min_sizeMinimum size the swap has to be extended before success is returned

Reimplemented in rambrain::managedFileSwap.

Definition at line 69 of file managedSwap.h.

virtual global_bytesize rambrain::managedSwap::getFreeSwap ( ) const
inlinevirtual

Simple getter.

Definition at line 90 of file managedSwap.h.

size_t rambrain::managedSwap::getMemoryAlignment ( ) const
inline

Returns possible memory alignment restrictions.

Definition at line 107 of file managedSwap.h.

virtual swapPolicy rambrain::managedSwap::getSwapPolicy ( ) const
inlinevirtual

Definition at line 95 of file managedSwap.h.

virtual global_bytesize rambrain::managedSwap::getSwapSize ( ) const
inlinevirtual

Simple getter.

Definition at line 82 of file managedSwap.h.

virtual global_bytesize rambrain::managedSwap::getUsedSwap ( ) const
inlinevirtual

Simple getter.

Definition at line 86 of file managedSwap.h.

virtual void rambrain::managedSwap::invalidateCacheFor ( managedMemoryChunk chunk)
inlinevirtual

tells managedFileSwap that the chunk under consideration might have been changed by user and needs to be copied out freshly

Note
this function must be called having stateChangeMutex acquired.

Reimplemented in rambrain::managedFileSwap.

Definition at line 143 of file managedSwap.h.

virtual swapPolicy rambrain::managedSwap::setSwapPolicy ( swapPolicy  newPolicy)
inlinevirtual

Definition at line 100 of file managedSwap.h.

virtual void rambrain::managedSwap::swapDelete ( managedMemoryChunk chunk)
pure virtual

Mark chunk as deleted.

Note
this is only called when deleting a chunk in managedMemory if chunk->swapBuf is not NULL
this function must be called having stateChangeMutex acquired.

Implemented in rambrain::managedFileSwap, and rambrain::managedDummySwap.

virtual global_bytesize rambrain::managedSwap::swapIn ( managedMemoryChunk **  chunklist,
unsigned int  nchunks 
)
pure virtual

Trigger swap in of the chunks pointed to by chunklist.

Note
this function must be called having stateChangeMutex acquired.

Implemented in rambrain::managedFileSwap, and rambrain::managedDummySwap.

virtual global_bytesize rambrain::managedSwap::swapIn ( managedMemoryChunk chunk)
pure virtual

Trigger swap in of the chunk pointed to by chunk.

Note
this function must be called having stateChangeMutex acquired.

Implemented in rambrain::managedFileSwap, and rambrain::managedDummySwap.

virtual global_bytesize rambrain::managedSwap::swapOut ( managedMemoryChunk **  chunklist,
unsigned int  nchunks 
)
pure virtual

Trigger swap out of the chunks pointed to by chunklist.

Note
this function must be called having stateChangeMutex acquired.

Implemented in rambrain::managedFileSwap, and rambrain::managedDummySwap.

virtual global_bytesize rambrain::managedSwap::swapOut ( managedMemoryChunk chunk)
pure virtual

Trigger swap out of the chunk pointed to by chunk.

Note
this function must be called having stateChangeMutex acquired.

Implemented in rambrain::managedFileSwap, and rambrain::managedDummySwap.

void rambrain::managedSwap::waitForCleanExit ( )

Function waits for all asynchronous IO to complete. The wait is implemented non-performant as a normal user does not have to wait for this. Implementing this with a _cond just destroys performance in the respective swapIn/out procedures without increasing any user space functionality.

Definition at line 46 of file managedSwap.cpp.

Member Data Documentation

bool rambrain::managedSwap::closed = false
protected

Definition at line 155 of file managedSwap.h.

size_t rambrain::managedSwap::memoryAlignment = 1
protected

Definition at line 151 of file managedSwap.h.

swapPolicy rambrain::managedSwap::policy = swapPolicy::fixed
protected

Definition at line 153 of file managedSwap.h.

global_bytesize rambrain::managedSwap::swapFree
protected

Definition at line 148 of file managedSwap.h.

global_bytesize rambrain::managedSwap::swapSize
protected

Definition at line 146 of file managedSwap.h.

global_bytesize rambrain::managedSwap::swapUsed
protected

Definition at line 147 of file managedSwap.h.

unsigned int rambrain::managedSwap::totalSwapActionsQueued = 0
protected

Definition at line 149 of file managedSwap.h.


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