wrench::MemoryManager

class MemoryManager : public wrench::Service

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

Public Functions

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

Add a file to cache.

Parameters
  • filename – file name

  • location – file location

  • amount – number of bytes

  • is_dirty – true or false

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

Evicted clean data from page cache.

Parameters
  • amount – the requested amount of data to be evicted

  • excluded_filename – name of file that cannot be evicted

Returns

evicted amount

void export_log(std::string filename)

Export the log to a file.

Parameters

filename – file path

double flush(double amount, const std::string &excluded_filename)

Flush dirty data from cache.

Parameters
  • amount – request amount to be flushed

  • excluded_filename – name of file to exclude

Returns

flushed amount

double getAvailableMemory()

Get currently available cache memory.

Returns

a number of bytes

double getCachedAmount(std::string filename)

Get amount of cached data of a file in cache.

Parameters

filename – name of the file

Returns

the amount of cached data

std::vector<Block*> 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

double getDirty() const

Get number of dirty bytes.

Returns

a number of bytes

double getDirtyRatio() const

Get the dirty ratio.

Returns

the dirty ratio

double getEvictableMemory()

Get current evictable memory.

Returns

a number of bytes

double getFreeMemory() const

Get the amount of free memory.

Returns

a number of bytes

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

Get the memory disk.

Returns

the disk that acts as the memory cache

double getTotalCachedAmount() const

Get total number of cached bytes.

Returns

a number of bytes

double getTotalMemory()

Get total available cache memory.

Returns

a number of bytes

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.

Parameters
  • filename – name of the file read

  • amount – number of bytes

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

Read data from disk to cache.

Parameters
  • filename – file name

  • location – file location

  • amount – number of bytes

  • async – tue if operation is asynchronous

Returns

a simgrid pointer to a pending I/O operation, or nullptr

void releaseMemory(double released_amt)

Release memory.

Parameters

released_amt – number of bytes to release

void setDirtyRatio(double dirty_ratio)

Set the dirty ratio.

Parameters

dirty_ratio – the dirty ratio

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

Set the memory disk.

Parameters

memory – a disk that acts as the memory cache

void useAnonymousMemory(double used_amt)

Update the amount of used memory.

Parameters

used_amt – number of bytes

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

Simulate a file write to cache.

Parameters
  • filename – name of the file written

  • location – file location

  • amount – amount of data written

  • is_dirty – true or false

Public Static Functions

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

Retrieve the disk where the file is stored.

Parameters
  • mountpoint – mountpoint on the disk where the file is stored

  • hostname – host at which the file is stored

Returns

static std::shared_ptr<MemoryManager> initAndStart(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.

Parameters
  • simulation

  • memory – disk model used to simulate memory_manager_service

  • dirty_ratio – dirty_ratio parameter as in the Linux kernel

  • interval – the interval that periodical flushing awakes in milliseconds

  • expired_time – the expired time of dirty data to be flushed in milliseconds

  • hostname – name of the host on which periodical flushing starts

Returns