rambrain
cyclicManagedMemory.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 CYCLICMANAGEDMEMORY_H
21 #define CYCLICMANAGEDMEMORY_H
22 
23 #include "managedMemory.h"
24 
25 namespace rambrain
26 {
28 struct cyclicAtime {
32 };
33 
34 
36 
40 };
41 struct backlog_entry {
44 };
45 
46 
47 
48 
51 {
52 public:
54  virtual ~cyclicManagedMemory();
55 
57  void printCycle() const;
59  void printMemUsage() const;
62  bool checkCycle();
63 
70  bool setPreemptiveLoading ( bool preemptive );
77  bool setPreemptiveUnloading ( bool preemptive );
78 
79  struct chain {
81  };
82 
83 
84 
85 private:
90  virtual bool swapIn ( managedMemoryChunk &chunk );
95  virtual swapErrorCode swapOut ( global_bytesize min_size );
96  virtual bool touch ( managedMemoryChunk &chunk );
98  virtual void untouch ( managedMemoryChunk &chunk );
99  virtual void schedulerRegister ( managedMemoryChunk &chunk );
100  virtual void schedulerDelete ( managedMemoryChunk &chunk );
102  void decay ( global_bytesize bytes );
103 
104 
105  //loop pointers:
109 
110  float swapOutFrac = .8;
111  float swapInFrac = .9;
112 
113  bool preemtiveSwapIn = true;
114  bool preemtiveSwapOut = true;
117  unsigned int preemptiveSinceLast = 0;
118 
119  static pthread_mutex_t cyclicTopoLock;
120 
122 
123 
125  struct cyclicManagedMemory::chain filterChain ( chain &toFilter, const memoryStatus *separateStatus, bool *preemptiveLoaded = NULL );
126  static void insertBefore ( cyclicAtime *pos, chain separated );
127  static void printChain ( const char *name, const chain mchain );
128 
129  void printBacklog() const;
130  static const unsigned int backlog_size = 100;
132  unsigned int backlog_pos = 0;
133 
134 };
135 
136 #define MUTUAL_CONNECT(A,B) A->next = B; B->prev = A;
137 
138 #define BACKLOG_ADD_SIZE(maction,mvalue) {backlog[backlog_pos].action = maction;backlog[backlog_pos].value.size= mvalue;backlog_pos=(backlog_pos+1)%backlog_size;};
139 #define BACKLOG_ADD_ID(maction,mvalue) {backlog[backlog_pos].action = maction;backlog[backlog_pos].value.id= mvalue ;backlog_pos=(backlog_pos+1)%backlog_size;};
140 
141 
142 }
143 
144 #endif
145 
structure created by scheduler to track access times of memoryChunks
cyclicAtime * next
The chunk.
static void printChain(const char *name, const chain mchain)
virtual void schedulerRegister(managedMemoryChunk &chunk)
gives scheduler code the opportunity to register its own datastructures associated with a chunk ...
static void insertBefore(cyclicAtime *pos, chain separated)
void printMemUsage() const
prints out current memory usage
uint64_t memoryID
Class that serves as a backend to managedMemory to actual write/read managedMemoryChunks to/from hard...
Definition: managedSwap.h:35
bool setPreemptiveLoading(bool preemptive)
sets whether scheduler should guess next needed items
virtual bool swapIn(managedMemoryChunk &chunk)
cyclic implementation of swapIn, see paper
virtual void untouch(managedMemoryChunk &chunk)
tries to regulate immediately usable free memory in ram to a level optimal for preemptive loading ...
bool checkCycle()
checks whether the scheduler believes to be sane and prints an error message if not ...
uint64_t global_bytesize
Definition: common.h:65
struct cyclicManagedMemory::chain filterChain(chain &toFilter, const memoryStatus *separateStatus, bool *preemptiveLoaded=NULL)
: separates all chunks matching state in list separateStatus or preeemptiveLoaded from the ring ...
static pthread_mutex_t cyclicTopoLock
virtual swapErrorCode swapOut(global_bytesize min_size)
cyclic implementation of swapOut, see paper
void decay(global_bytesize bytes)
: Tries to unload around bytes bytes of preemptive elements
cyclicAtime * prev
Next chunk in cycle.
virtual void schedulerDelete(managedMemoryChunk &chunk)
signals deletion of chunk to scheduler code
manages all managed Chunks of raw memory
bool setPreemptiveUnloading(bool preemptive)
sets whether scheduler should swap out elements without strict need
scheduler working with a double linked cycle. Details see paper.
void printCycle() const
prints out all elements known to the scheduler with their respective status
static const unsigned int backlog_size
virtual bool touch(managedMemoryChunk &chunk)
marks chunk as recently active as a hint for scheduling
swapErrorCode
Error codes for swapOut requests.
managedMemoryChunk * chunk
backlog_entry backlog[backlog_size]
Backend class to handle raw memory and interaction/storage with managedSwap.
Definition: managedMemory.h:68
cyclicManagedMemory(rambrain::managedSwap *swap, rambrain::global_bytesize size)