WRENCH  1.11
Cyberinfrastructure Simulation Workbench
Overview Installation Getting Started WRENCH 101 WRENCH 102
MemoryManager.h
1 
11 #ifndef WRENCH_MEMORYMANAGER_H
12 #define WRENCH_MEMORYMANAGER_H
13 
14 #include <string>
15 #include "wrench/services/Service.h"
16 #include "wrench/simulation/Simulation.h"
17 #include "Block.h"
18 
19 namespace wrench {
20 
21  /***********************/
23  /***********************/
24 
29  class MemoryManager : public Service {
30 
31  public:
32 
33  private:
34  simgrid::s4u::Disk *memory;
35  double dirty_ratio;
36  int interval;
37  int expired_time;
38  std::vector<Block *> inactive_list;
39  std::vector<Block *> active_list;
40  double total;
41 
42  // We keep track of these properties since we don't want to traverse through two LRU lists to get them.
43  double free;
44  double cached;
45  double dirty;
46 
47  std::vector<double> time_log;
48  std::vector<double> dirty_log;
49  std::vector<double> cached_log;
50  std::vector<double> free_log;
51 
52 
53  MemoryManager(simgrid::s4u::Disk *memory, double dirty_ratio, int interval, int expired_time, std::string hostname);
54 
55  int main() override;
56 
57  void balanceLruLists();
58 
59  double pdflush();
60 
61  double flushExpiredData(std::vector<Block *> &list);
62 
63  double flushLruList(std::vector<Block *> &list, double amount, std::string excluded_filename);
64 
65  double evictLruList(std::vector<Block *> &lru_list, double amount, std::string excluded_filename);
66 
67  public:
68 
69  static std::shared_ptr<MemoryManager> initAndStart(Simulation *simulation, simgrid::s4u::Disk *memory,
70  double dirty_ratio, int interval, int expired_time,
71  std::string hostname);
72 
73  void kill();
74 
75  simgrid::s4u::Disk *getMemory() const;
76 
77  void setMemory(simgrid::s4u::Disk *memory);
78 
79  double getDirtyRatio() const;
80 
81  void setDirtyRatio(double dirty_ratio);
82 
83  double getFreeMemory() const;
84 
85  void releaseMemory(double released_amt);
86 
87  void useAnonymousMemory(double used_amt);
88 
89  double getTotalCachedAmount() const;
90 
91  double getDirty() const;
92 
93  double getEvictableMemory();
94 
95  double getAvailableMemory();
96 
97  double getTotalMemory();
98 
99  double flush(double amount, std::string excluded_filename);
100 
101  double evict(double amount, std::string excluded_filename);
102 
103  simgrid::s4u::IoPtr readToCache(std::string filename, std::shared_ptr<FileLocation> location,
104  double amount, bool async);
105 
106  void readChunkFromCache(std::string filename, double amount);
107 
108  void writebackToCache(std::string filename, std::shared_ptr<FileLocation> location, double amount, bool is_dirty);
109 
110  void addToCache(std::string filename, std::shared_ptr<FileLocation> location, double amount, bool is_dirty);
111 
112  double getCachedAmount(std::string filename);
113 
114  std::vector<Block*> getCachedBlocks(std::string filename);
115 
116  static simgrid::s4u::Disk *getDisk(std::string mountpoint, std::string hostname);
117 
118  void log();
119 
120  void export_log(std::string filename);
121 
122  /***********************/
124  /***********************/
125  };
126 
127 }
128 
129 #endif //WRENCH_MEMORYMANAGER_H
wrench::MemoryManager::readToCache
simgrid::s4u::IoPtr readToCache(std::string filename, std::shared_ptr< FileLocation > location, double amount, bool async)
Read data from disk to cache.
Definition: MemoryManager.cpp:398
wrench::MemoryManager::getDisk
static simgrid::s4u::Disk * getDisk(std::string mountpoint, std::string hostname)
Retrieve the disk where the file is stored.
Definition: MemoryManager.cpp:669
wrench::MemoryManager::getDirty
double getDirty() const
Get number of dirty bytes.
Definition: MemoryManager.cpp:165
wrench::MemoryManager
A class that implemnets a MemoryManager service to simulate Linux in-memory page caching for I/O oper...
Definition: MemoryManager.h:29
wrench::MemoryManager::addToCache
void addToCache(std::string filename, std::shared_ptr< FileLocation > location, double amount, bool is_dirty)
Add a file to cache.
Definition: MemoryManager.cpp:544
wrench::MemoryManager::getCachedBlocks
std::vector< Block * > getCachedBlocks(std::string filename)
Get list of cached blocks of a file.
Definition: MemoryManager.cpp:644
wrench::MemoryManager::flush
double flush(double amount, std::string excluded_filename)
Flush dirty data from cache.
Definition: MemoryManager.cpp:263
wrench::MemoryManager::readChunkFromCache
void readChunkFromCache(std::string filename, double amount)
Simulate a read from cache, re-access and update cached file data.
Definition: MemoryManager.cpp:423
wrench
Definition: Action.cpp:28
wrench::MemoryManager::writebackToCache
void writebackToCache(std::string filename, std::shared_ptr< FileLocation > location, double amount, bool is_dirty)
Simulate a file write to cache.
Definition: MemoryManager.cpp:528
wrench::MemoryManager::getMemory
simgrid::s4u::Disk * getMemory() const
Get the memory disk.
Definition: MemoryManager.cpp:99
wrench::MemoryManager::export_log
void export_log(std::string filename)
Export the log to a file.
Definition: MemoryManager.cpp:704
wrench::MemoryManager::getFreeMemory
double getFreeMemory() const
Get the amount of free memory.
Definition: MemoryManager.cpp:131
wrench::MemoryManager::getDirtyRatio
double getDirtyRatio() const
Get the dirty ratio.
Definition: MemoryManager.cpp:115
wrench::MemoryManager::initAndStart
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.
Definition: MemoryManager.cpp:54
wrench::MemoryManager::getAvailableMemory
double getAvailableMemory()
Get currently available cache memory.
Definition: MemoryManager.cpp:185
wrench::MemoryManager::kill
void kill()
Immediately terminate periodical flushing.
Definition: MemoryManager.cpp:91
wrench::MemoryManager::setMemory
void setMemory(simgrid::s4u::Disk *memory)
Set the memory disk.
Definition: MemoryManager.cpp:107
wrench::S4U_Daemon::hostname
std::string hostname
The name of the host on which the daemon is running.
Definition: S4U_Daemon.h:60
wrench::Simulation
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:48
wrench::MemoryManager::evict
double evict(double amount, std::string excluded_filename)
Evicted clean data from page cache.
Definition: MemoryManager.cpp:334
wrench::MemoryManager::releaseMemory
void releaseMemory(double released_amt)
Release memory.
Definition: MemoryManager.cpp:139
wrench::MemoryManager::getCachedAmount
double getCachedAmount(std::string filename)
Get amount of cached data of a file in cache.
Definition: MemoryManager.cpp:621
wrench::MemoryManager::getTotalMemory
double getTotalMemory()
Get total available cache memory.
Definition: MemoryManager.cpp:193
wrench::MemoryManager::setDirtyRatio
void setDirtyRatio(double dirty_ratio)
Set the dirty ratio.
Definition: MemoryManager.cpp:123
wrench::Service
A service that can be added to the simulation and that can be used by a WMS when executing a workflow...
Definition: Service.h:31
wrench::MemoryManager::useAnonymousMemory
void useAnonymousMemory(double used_amt)
Update the amount of used memory.
Definition: MemoryManager.cpp:148
wrench::MemoryManager::log
void log()
Append to the log.
Definition: MemoryManager.cpp:693
wrench::MemoryManager::getTotalCachedAmount
double getTotalCachedAmount() const
Get total number of cached bytes.
Definition: MemoryManager.cpp:157
wrench::MemoryManager::getEvictableMemory
double getEvictableMemory()
Get current evictable memory.
Definition: MemoryManager.cpp:173
wrench::S4U_Daemon::simulation
Simulation * simulation
a pointer to the simulation object
Definition: S4U_Daemon.h:125