-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev_blkmgr.h
276 lines (246 loc) · 6.43 KB
/
dev_blkmgr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#include "parameter.h"
#include <iostream>
#include <iomanip>
#include <set>
#include <algorithm>
class LLNode;
class FBLNode;
class FreeBlockList;
class BlockEraseCountRecord;
class MappingTable;
class ResetHintTable;
class BlockManager;
class LLNode{
friend class FBLNode;
private:
int blkid;
LLNode *next;
public:
LLNode(int blkid_): blkid(blkid_), next(nullptr){}
LLNode(int blkid_, LLNode *next_): blkid(blkid_), next(next_){}
~LLNode(){}
int GetBlkid();
};
class FBLNode{
friend class FreeBlockList;
private:
int key;
int nr;
LLNode *head;
FBLNode *left, *right;
FBLNode *p;
bool color; // true black, false red
public:
FBLNode(int key_): key(key_), nr(0), head(nullptr), left(nullptr), right(nullptr), p(nullptr), color(false){}
FBLNode(int key_, FBLNode *p_): key(key_), nr(0), head(nullptr), left(nullptr), right(nullptr), p(p_), color(false){}
FBLNode(int key_, FBLNode *p_, FBLNode *nil_): key(key_), nr(0), head(nullptr), left(nil_), right(nil_), p(p_), color(false){}
~FBLNode();
void AddLLNode(int blkid);
int DeleteLLHead();
};
class FreeBlockList{
private:
FBLNode *root_;
FBLNode *min_;
FBLNode *nil_;
void LeftRotate(FBLNode *x);
void RightRotate(FBLNode *x);
void RBTransplant(FBLNode *u, FBLNode *v);
void RBDeleteFixup(FBLNode *x);
FBLNode* TreeMinimum(FBLNode *x);
void RBInsertFixup(FBLNode *z);
public:
FreeBlockList();
~FreeBlockList();
int Pop();
void Insert(int blkid, int ec);
int GetMinEC();
void show(FBLNode*root);
void show(){show(root_);}
};
class BlockEraseCountRecord{
private:
int *record;
public:
BlockEraseCountRecord();
~BlockEraseCountRecord();
void AddEC(int blkid);
int GetEC(int blkid);
int GetECMin();
void Summary();
void show();
};
class MappingTable{
private:
int **mt;
int *allocated;
public:
MappingTable();
~MappingTable();
void AddBlockToZone(int zoneid, int blkid);
bool IsAllocated(int zoneid, int idx);
int GetSize(int zoneid);
int GetBlk(int zoneid, int idx);
void ResetMT(int zoneid);
void show();
};
class ResetHintTable{
private:
int *rht;
int nr_update;
public:
ResetHintTable();
void SetResetHint(int zoneid, int rh);
int GetResetHint(int zoneid);
int GetMinRH();
void show();
int GetNrUpdate();
};
class BlockManager{
public:
virtual int Append(int zoneid, int offset, int data_size) = 0;
virtual int Read(int zoneid, int offset, int data_size) = 0;
virtual int Reset(int zoneid) = 0;
virtual int GetECMin() = 0;
virtual int GetECMax() = 0;
virtual int GetECMinFree() = 0;
virtual int GetResetHint(int zoneid) = 0;
virtual void AddReadAmount(int i) = 0;
virtual void UpdateECMin(int val) = 0;
virtual void UpdateECMax(int val) = 0;
virtual void UpdateECMinFree(int val) = 0;
virtual void show() = 0;
};
class BlockManagerDynamic: public BlockManager{
private:
FreeBlockList *fblist;
BlockEraseCountRecord *blkec;
MappingTable *mtable;
ResetHintTable *rhtable;
int EC_max, EC_min, EC_min_free;
int Allocate(int zoneid);
int Erase(int blkid);
int64_t amount_write = 0;
int64_t amount_read = 0;
int64_t amount_erase = 0;
int nr_update = 0;
public:
BlockManagerDynamic();
~BlockManagerDynamic();
int Append(int zoneid, int offset, int data_size);
int Read(int zoneid, int offset, int data_size);
int Reset(int zoneid);
int GetECMin();
int GetECMax();
int GetECMinFree();
void UpdateECMin(int val);
void UpdateECMax(int val);
void UpdateECMinFree(int val);
int GetResetHint(int zoneid);
void AddReadAmount(int i){amount_read += i;}
void show(){
// fblist->show();
// std::cout << "\n\n";
// mtable->show();
// rhtable->show();
// blkec->show();
std::cout << "# of Updating CXL.cache: " << this->nr_update + rhtable->GetNrUpdate() << "\n";
std::cout << "Erase Count of Blocks: \n";
blkec->Summary();
std::cout << "\tEC_max: " << EC_max << ", EC_min: " << EC_min << "\n";
std::cout << "Read/Write/Erase: \n";
std::cout << "\twrite: "
<< std::setw(12) << amount_write
<< " pages\n\tread: "
<< std::setw(12) << amount_read
<< " pages\n\terase: "
<< std::setw(12) << amount_erase
<< " blocks\n";
}
};
class BlockManagerStatic: public BlockManager{
private:
BlockEraseCountRecord *blkec;
ResetHintTable *rhtable;
int EC_max, EC_min;
int Erase(int blkid);
int64_t amount_write = 0;
int64_t amount_read = 0;
int64_t amount_erase = 0;
int nr_update = 0;
public:
BlockManagerStatic();
~BlockManagerStatic();
int Append(int zoneid, int offset, int data_size){
amount_write += (data_size / SZPAGE);
return (data_size / SZPAGE) * LATENCY_WRITE;
}
int Read(int zoneid, int offset, int data_size){return -1;}
int Reset(int zoneid);
int GetECMin();
int GetECMax();
int GetECMinFree(){return -1;}
void UpdateECMin(int val);
void UpdateECMax(int val);
void UpdateECMinFree(int val){return;}
int GetResetHint(int zoneid);
void AddReadAmount(int i){amount_read += i;}
void show(){
std::cout << "Erase Count: \n";
blkec->Summary();
std::cout << "\tEC_max: " << EC_max << ", EC_min: " << EC_min << "\n";
std::cout << "Read/Write/Erase: \n";
std::cout << "\twrite: "
<< std::setw(12) << amount_write
<< " pages\n\tread: "
<< std::setw(12) << amount_read
<< " pages\n\terase: "
<< std::setw(12) << amount_erase
<< " blocks\n";
}
};
class BlockManagerWazone: public BlockManager{
private:
BlockEraseCountRecord *blkec;
ResetHintTable *rhtable;
int EC_max, EC_min;
int Erase(int blkid);
int64_t amount_write = 0;
int64_t amount_read = 0;
int64_t amount_erase = 0;
int nr_update = 0;
int *sz;
int *zoffset;
public:
BlockManagerWazone();
~BlockManagerWazone();
int Append(int zoneid, int offset, int data_size){
int idx = (offset + data_size - 1) / SZBLK;
sz[zoneid] = idx;
amount_write += (data_size / SZPAGE);
return (data_size / SZPAGE) * LATENCY_WRITE;
}
int Read(int zoneid, int offset, int data_size){return -1;}
int Reset(int zoneid);
int GetECMin();
int GetECMax();
int GetECMinFree(){return -1;}
void UpdateECMin(int val){return;}
void UpdateECMax(int val){return;}
void UpdateECMinFree(int val){return;}
int GetResetHint(int zoneid);
void AddReadAmount(int i){amount_read += i;}
void show(){
std::cout << "Erase Count: \n";
blkec->Summary();
std::cout << "\tEC_max: " << EC_max << ", EC_min: " << EC_min << "\n";
std::cout << "Read/Write/Erase: \n";
std::cout << "\twrite: "
<< std::setw(12) << amount_write
<< " pages\n\tread: "
<< std::setw(12) << amount_read
<< " pages\n\terase: "
<< std::setw(12) << amount_erase
<< " blocks\n";
}
};