WRENCH  1.10
Cyberinfrastructure Simulation Workbench
Overview Installation Getting Started WRENCH 101 WRENCH 102
Public Member Functions | Static Public Member Functions | List of all members
wrench::MemoryManager Class Reference

A class that implemnets a MemoryManager service to simulate Linux in-memory page caching for I/O operations. More...

#include <MemoryManager.h>

Inheritance diagram for wrench::MemoryManager:
wrench::Service wrench::S4U_Daemon

Public Member Functions

void addToCache (std::string filename, std::shared_ptr< FileLocation > location, double amount, bool is_dirty)
 Add a file to cache. More...
 
double evict (double amount, std::string excluded_filename)
 Evicted clean data from page cache. More...
 
void export_log (std::string filename)
 Export the log to a file. More...
 
double flush (double amount, std::string excluded_filename)
 Flush dirty data from cache. More...
 
double getAvailableMemory ()
 Get currently available cache memory. More...
 
double getCachedAmount (std::string filename)
 Get amount of cached data of a file in cache. More...
 
std::vector< Block * > getCachedBlocks (std::string filename)
 Get list of cached blocks of a file. More...
 
double getDirty () const
 Get number of dirty bytes. More...
 
double getDirtyRatio () const
 Get the dirty ratio. More...
 
double getEvictableMemory ()
 Get current evictable memory. More...
 
double getFreeMemory () const
 Get the amount of free memory. More...
 
simgrid::s4u::Disk * getMemory () const
 Get the memory disk. More...
 
double getTotalCachedAmount () const
 Get total number of cached bytes. More...
 
double getTotalMemory ()
 Get total available cache memory. More...
 
void kill ()
 Immediately terminate periodical flushing.
 
void log ()
 Append to the log.
 
void readChunkFromCache (std::string filename, double amount)
 Simulate a read from cache, re-access and update cached file data. More...
 
simgrid::s4u::IoPtr readToCache (std::string filename, std::shared_ptr< FileLocation > location, double amount, bool async)
 Read data from disk to cache. More...
 
void releaseMemory (double released_amt)
 Release memory. More...
 
void setDirtyRatio (double dirty_ratio)
 Set the dirty ratio. More...
 
void setMemory (simgrid::s4u::Disk *memory)
 Set the memory disk. More...
 
void useAnonymousMemory (double used_amt)
 Update the amount of used memory. More...
 
void writebackToCache (std::string filename, std::shared_ptr< FileLocation > location, double amount, bool is_dirty)
 Simulate a file write to cache. More...
 
- Public Member Functions inherited from wrench::Service
void assertServiceIsUp ()
 Throws an exception if the service is not up. More...
 
std::string getHostname ()
 Get the name of the host on which the service is / will be running. More...
 
double getMessagePayloadValue (std::string)
 Get a message payload of the Service as a double. More...
 
double getNetworkTimeoutValue ()
 Returns the service's network timeout value. More...
 
bool getPropertyValueAsBoolean (std::string)
 Get a property of the Service as a boolean. More...
 
double getPropertyValueAsDouble (std::string)
 Get a property of the Service as a double. More...
 
std::string getPropertyValueAsString (std::string)
 Get a property of the Service as a string. More...
 
unsigned long getPropertyValueAsUnsignedLong (std::string)
 Get a property of the Service as an unsigned long. More...
 
bool isUp ()
 Returns true if the service is UP, false otherwise. More...
 
void resume ()
 Resume the service. More...
 
void setNetworkTimeoutValue (double value)
 Sets the service's network timeout value. More...
 
void setStateToDown ()
 Set the state of the service to DOWN.
 
void start (std::shared_ptr< Service > this_service, bool daemonize, bool auto_restart)
 Start the service. More...
 
virtual void stop ()
 Synchronously stop the service (does nothing if the service is already stopped) More...
 
void suspend ()
 Suspend the service.
 
- Public Member Functions inherited from wrench::S4U_Daemon
 S4U_Daemon (std::string hostname, std::string process_name_prefix, std::string mailbox_prefix)
 Constructor (daemon with a mailbox) More...
 
virtual ~S4U_Daemon ()
 
virtual void cleanup (bool has_returned_from_main, int return_value)
 Cleanup function called when the daemon terminates (for whatever reason). The default behavior is to throw an exception if the host is off. This method should be overriden in a daemons implements some fault-tolerant behavior, or is naturally tolerant. More...
 
void createLifeSaver (std::shared_ptr< S4U_Daemon > reference)
 Create a life saver for the daemon. More...
 
std::string getName ()
 Retrieve the process name. More...
 
int getReturnValue ()
 Returns the value returned by main() (if the daemon has returned from main) More...
 
S4U_Daemon::State getState ()
 Get the daemon's state. More...
 
bool hasReturnedFromMain ()
 Returns true if the daemon has returned from main() (i.e., not brutally killed) More...
 
bool isDaemonized ()
 Return the daemonized status of the daemon. More...
 
bool isSetToAutoRestart ()
 Return the auto-restart status of the daemon. More...
 
std::pair< bool, int > join ()
 Join (i.e., wait for) the daemon. More...
 
void resumeActor ()
 Resume the daemon/actor.
 
void setupOnExitFunction ()
 Sets up the on_exit functionf for the actor.
 
void startDaemon (bool _daemonized, bool _auto_restart)
 Start the daemon. More...
 
void suspendActor ()
 Suspend the daemon/actor.
 

Static Public Member Functions

static simgrid::s4u::Disk * getDisk (std::string mountpoint, std::string hostname)
 Retrieve the disk where the file is stored. More...
 
static std::shared_ptr< MemoryManagerinitAndStart (Simulation *simulation, simgrid::s4u::Disk *memory, double dirty_ratio, int interval, int expired_time, std::string hostname)
 Initialize and start the memory_manager_service manager. More...
 
- Static Public Member Functions inherited from wrench::Service
static void cleanupTrackedServices ()
 Go through the tracked services and remove all entries with a refcount of 1!
 
static void clearTrackedServices ()
 Forget all tracked services.
 
static void increaseNumCompletedServicesCount ()
 Increase the completed service count.
 

Additional Inherited Members

- Public Types inherited from wrench::S4U_Daemon
enum  State { UP, DOWN, SUSPENDED }
 Daemon states. More...
 
- Public Attributes inherited from wrench::S4U_Daemon
std::string hostname
 The name of the host on which the daemon is running.
 
std::string initial_mailbox_name
 The initial name of the daemon's mailbox.
 
LifeSaver * life_saver = nullptr
 The daemon's life saver.
 
std::string mailbox_name
 The current name of the daemon's mailbox.
 
std::string process_name
 The name of the daemon.
 
Simulationsimulation
 a pointer to the simulation object
 
- Protected Member Functions inherited from wrench::Service
 Service (std::string hostname, std::string process_name_prefix, std::string mailbox_name_prefix)
 Constructor. More...
 
 ~Service ()
 Destructor.
 
template<class T >
std::shared_ptr< T > getSharedPtr ()
 Method to retrieve the shared_ptr to a service. More...
 
void serviceSanityCheck ()
 Check whether the service is properly configured and running. More...
 
void setMessagePayload (std::string, double)
 Set a message payload of the Service. More...
 
void setMessagePayloads (std::map< std::string, double > default_messagepayload_values, std::map< std::string, double > overriden_messagepayload_values)
 Set default and user-defined message payloads. More...
 
void setProperties (std::map< std::string, std::string > default_property_values, std::map< std::string, std::string > overriden_property_values)
 Set default and user-defined properties. More...
 
void setProperty (std::string, std::string)
 Set a property of the Service. More...
 
- Protected Member Functions inherited from wrench::S4U_Daemon
void acquireDaemonLock ()
 Lock the daemon's lock.
 
void killActor ()
 Kill the daemon/actor (does nothing if already dead) More...
 
void releaseDaemonLock ()
 Unlock the daemon's lock.
 
void runMainMethod ()
 Method that run's the user-defined main method (that's called by the S4U actor class)
 
- Static Protected Member Functions inherited from wrench::Service
static void assertServiceIsUp (std::shared_ptr< Service > s)
 Assert for the service being up. More...
 
template<class T >
static std::shared_ptr< T > getServiceByName (std::string name)
 Method to retrieve the shared_ptr to a service based on the service's name (not efficient) More...
 
- Protected Attributes inherited from wrench::Service
std::map< std::string, double > messagepayload_list
 The service's messagepayload list.
 
std::string name
 The service's name.
 
double network_timeout = 30.0
 The time (in seconds) after which a service that doesn't send back a reply (control) message causes a NetworkTimeOut exception. (default: 30 second; if <0 never timeout)
 
std::map< std::string, std::string > property_list
 The service's property list.
 
- Protected Attributes inherited from wrench::S4U_Daemon
unsigned int num_starts = 0
 The number of time that this daemon has started (i.e., 1 + number of restarts)
 
State state
 The service's state.
 

Detailed Description

A class that implemnets a MemoryManager service to simulate Linux in-memory page caching for I/O operations.

Member Function Documentation

◆ addToCache()

void wrench::MemoryManager::addToCache ( std::string  filename,
std::shared_ptr< FileLocation location,
double  amount,
bool  is_dirty 
)

Add a file to cache.

Parameters
filenamefile name
locationfile location
amountnumber of bytes
is_dirtytrue or false

◆ evict()

double wrench::MemoryManager::evict ( double  amount,
std::string  excluded_filename 
)

Evicted clean data from page cache.

Parameters
amountthe requested amount of data to be evicted
excluded_filenamename of file that cannot be evicted
Returns
evicted amount

◆ export_log()

void wrench::MemoryManager::export_log ( std::string  filename)

Export the log to a file.

Parameters
filenamefile path

◆ flush()

double wrench::MemoryManager::flush ( double  amount,
std::string  excluded_filename 
)

Flush dirty data from cache.

Parameters
amountrequest amount to be flushed
excluded_filenamename of file to exclude
Returns
flushed amount

◆ getAvailableMemory()

double wrench::MemoryManager::getAvailableMemory ( )

Get currently available cache memory.

Returns
a number of bytes

◆ getCachedAmount()

double wrench::MemoryManager::getCachedAmount ( std::string  filename)

Get amount of cached data of a file in cache.

Parameters
filenamename of the file
Returns
the amount of cached data

◆ getCachedBlocks()

std::vector< Block * > wrench::MemoryManager::getCachedBlocks ( std::string  filename)

Get list of cached blocks of a file.

Parameters
filename: name of the file
Returns
a vector of cached blocks of the file

◆ getDirty()

double wrench::MemoryManager::getDirty ( ) const

Get number of dirty bytes.

Returns
a number of bytes

◆ getDirtyRatio()

double wrench::MemoryManager::getDirtyRatio ( ) const

Get the dirty ratio.

Returns
the dirty ratio

◆ getDisk()

simgrid::s4u::Disk * wrench::MemoryManager::getDisk ( std::string  mountpoint,
std::string  hostname 
)
static

Retrieve the disk where the file is stored.

Parameters
mountpointmountpoint on the disk where the file is stored
hostnamehost at which the file is stored
Returns

◆ getEvictableMemory()

double wrench::MemoryManager::getEvictableMemory ( )

Get current evictable memory.

Returns
a number of bytes

◆ getFreeMemory()

double wrench::MemoryManager::getFreeMemory ( ) const

Get the amount of free memory.

Returns
a number of bytes

◆ getMemory()

simgrid::s4u::Disk * wrench::MemoryManager::getMemory ( ) const

Get the memory disk.

Returns
the disk that acts as the memory cache

◆ getTotalCachedAmount()

double wrench::MemoryManager::getTotalCachedAmount ( ) const

Get total number of cached bytes.

Returns
a number of bytes

◆ getTotalMemory()

double wrench::MemoryManager::getTotalMemory ( )

Get total available cache memory.

Returns
a number of bytes

◆ initAndStart()

std::shared_ptr< MemoryManager > wrench::MemoryManager::initAndStart ( wrench::Simulation simulation,
simgrid::s4u::Disk *  memory,
double  dirty_ratio,
int  interval,
int  expired_time,
std::string  hostname 
)
static

Initialize and start the memory_manager_service manager.

Parameters
simulation
memorydisk model used to simulate memory_manager_service
dirty_ratiodirty_ratio parameter as in the Linux kernel
intervalthe interval that periodical flushing awakes in milliseconds
expired_timethe expired time of dirty data to be flushed in milliseconds
hostnamename of the host on which periodical flushing starts
Returns

◆ readChunkFromCache()

void wrench::MemoryManager::readChunkFromCache ( std::string  filename,
double  amount 
)

Simulate a read from cache, re-access and update cached file data.

Parameters
filenamename of the file read
amountnumber of bytes

◆ readToCache()

simgrid::s4u::IoPtr wrench::MemoryManager::readToCache ( std::string  filename,
std::shared_ptr< FileLocation location,
double  amount,
bool  async 
)

Read data from disk to cache.

Parameters
filenamefile name
locationfile location
amountnumber of bytes
asynctue if operation is asynchronous
Returns
a simgrid pointer to a pending I/O operation, or nullptr

◆ releaseMemory()

void wrench::MemoryManager::releaseMemory ( double  released_amt)

Release memory.

Parameters
released_amtnumber of bytes to release

◆ setDirtyRatio()

void wrench::MemoryManager::setDirtyRatio ( double  dirty_ratio)

Set the dirty ratio.

Parameters
dirty_ratiothe dirty ratio

◆ setMemory()

void wrench::MemoryManager::setMemory ( simgrid::s4u::Disk *  memory)

Set the memory disk.

Parameters
memorya disk that acts as the memory cache

◆ useAnonymousMemory()

void wrench::MemoryManager::useAnonymousMemory ( double  used_amt)

Update the amount of used memory.

Parameters
used_amtnumber of bytes

◆ writebackToCache()

void wrench::MemoryManager::writebackToCache ( std::string  filename,
std::shared_ptr< FileLocation location,
double  amount,
bool  is_dirty 
)

Simulate a file write to cache.

Parameters
filenamename of the file written
locationfile location
amountamount of data written
is_dirtytrue or false

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