rambrain
managedSwap.h
Go to the documentation of this file.
1 /* rambrain - a dynamical physical memory extender
2  * Copyright (C) 2015 M. Imgrund, A. Arth
3  * mimgrund (at) mpifr-bonn.mpg.de
4  * arth (at) usm.uni-muenchen.de
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef MANAGEDSWAP_H
21 #define MANAGEDSWAP_H
22 
23 #include "managedMemoryChunk.h"
24 #include "common.h"
25 #include "managedMemory.h"
26 #include "rambrain_atomics.h"
27 #include "configreader.h"
28 
29 namespace rambrain
30 {
31 
36 {
37 public:
39  virtual ~managedSwap();
40 
41  //Returns size of sucessfully swapped chunks
45  virtual global_bytesize swapOut ( managedMemoryChunk **chunklist, unsigned int nchunks ) = 0;
49  virtual global_bytesize swapOut ( managedMemoryChunk *chunk ) = 0;
53  virtual global_bytesize swapIn ( managedMemoryChunk **chunklist, unsigned int nchunks ) = 0;
57  virtual global_bytesize swapIn ( managedMemoryChunk *chunk ) = 0;
62  virtual void swapDelete ( managedMemoryChunk *chunk ) = 0;
63 
64 
69  virtual bool extendSwapByPolicy ( global_bytesize min_size ) {
70  errmsg ( "Your swap module does not support extending swap by policy" );
71  return false;
72  };
76  virtual bool extendSwap ( global_bytesize size ) {
77  errmsg ( "Your swap module does not support extending swap" );
78  return false;
79  }
80 
82  virtual inline global_bytesize getSwapSize() const {
83  return swapSize;
84  }
86  virtual inline global_bytesize getUsedSwap() const {
87  return swapUsed;
88  }
90  virtual inline global_bytesize getFreeSwap() const {
91  return swapFree;
92  }
93 
94  //Simple getter
95  virtual inline swapPolicy getSwapPolicy() const {
96  return policy;
97  }
98 
99  //Simple setter returning old policy
100  virtual inline swapPolicy setSwapPolicy ( swapPolicy newPolicy ) {
101  swapPolicy oldPolicy = policy;
102  policy = newPolicy;
103  return oldPolicy;
104  }
105 
107  inline size_t getMemoryAlignment() const {
108  return memoryAlignment;
109  }
115  void claimUsageof ( global_bytesize bytes, bool rambytes, bool used );
120  void waitForCleanExit();
121 
122  virtual inline bool checkForAIO() {
123  return false;
124  }
125 
131  virtual void close() = 0;
132 
133  //Caching Control.
137  virtual inline bool cleanupCachedElements ( rambrain::global_bytesize minimum_size = 0 ) {
138  return true;
139  }
143  virtual inline void invalidateCacheFor ( managedMemoryChunk &chunk ) {}
144 
145 protected:
149  unsigned int totalSwapActionsQueued = 0;
150 
151  size_t memoryAlignment = 1;
152 
154 
155  bool closed = false;
156 };
157 
158 
159 }
160 
161 
162 
163 
164 #endif
165 
166 
167 
168 
169 
170 
171 
virtual bool checkForAIO()
Definition: managedSwap.h:122
virtual bool extendSwapByPolicy(global_bytesize min_size)
extend swap by policy
Definition: managedSwap.h:69
swapPolicy
An enumeration to regulate how the swap should define when it approaches it's set boundary...
Definition: configreader.h:47
size_t getMemoryAlignment() const
Returns possible memory alignment restrictions.
Definition: managedSwap.h:107
virtual global_bytesize getUsedSwap() const
Simple getter.
Definition: managedSwap.h:86
Class that serves as a backend to managedMemory to actual write/read managedMemoryChunks to/from hard...
Definition: managedSwap.h:35
virtual global_bytesize getSwapSize() const
Simple getter.
Definition: managedSwap.h:82
void claimUsageof(global_bytesize bytes, bool rambytes, bool used)
account for memory usage change
Definition: managedSwap.cpp:35
virtual swapPolicy getSwapPolicy() const
Definition: managedSwap.h:95
global_bytesize swapUsed
Definition: managedSwap.h:147
uint64_t global_bytesize
Definition: common.h:65
unsigned int totalSwapActionsQueued
Definition: managedSwap.h:149
virtual void close()=0
Close the swap if not already closed.
managedSwap(global_bytesize size)
Definition: managedSwap.cpp:26
virtual global_bytesize swapIn(managedMemoryChunk **chunklist, unsigned int nchunks)=0
Trigger swap in of the chunks pointed to by chunklist.
virtual bool extendSwap(global_bytesize size)
extend swap by size number of bytes
Definition: managedSwap.h:76
virtual global_bytesize getFreeSwap() const
Simple getter.
Definition: managedSwap.h:90
manages all managed Chunks of raw memory
virtual global_bytesize swapOut(managedMemoryChunk **chunklist, unsigned int nchunks)=0
Trigger swap out of the chunks pointed to by chunklist.
void waitForCleanExit()
Function waits for all asynchronous IO to complete. The wait is implemented non-performant as a norma...
Definition: managedSwap.cpp:46
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 ...
Definition: managedSwap.h:137
global_bytesize swapFree
Definition: managedSwap.h:148
virtual swapPolicy setSwapPolicy(swapPolicy newPolicy)
Definition: managedSwap.h:100
virtual void invalidateCacheFor(managedMemoryChunk &chunk)
tells managedFileSwap that the chunk under consideration might have been changed by user and needs to...
Definition: managedSwap.h:143
virtual void swapDelete(managedMemoryChunk *chunk)=0
Mark chunk as deleted.
global_bytesize swapSize
Definition: managedSwap.h:146