-
Notifications
You must be signed in to change notification settings - Fork 0
/
lsm_params_module.c
161 lines (148 loc) · 3.67 KB
/
lsm_params_module.c
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
#include "lsm_params_module.h"
#include "ssd.h"
#include <cmath>
static inline int checking(uint32_t level, uint32_t size_factor, uint32_t blocknumber){
uint32_t head_num=0;
uint32_t level_head_num=1;
for(uint32_t i=0; i<=level; i++){
head_num+=level_head_num;
level_head_num*=size_factor;
}
if(head_num<blocknumber){
return -1;
}
else if(head_num > blocknumber){
return 1;
}
else return 0;
}
uint32_t get_size_factor(uint32_t level, uint32_t blocknumber){
uint32_t target=(uint32_t)(std::ceil((std::pow(blocknumber, (double)1.0/level))));
int result;
int retry_cnt=0;
retry:
switch((result=checking(level, target, blocknumber))){
case 1:
case 0:
return target;
case -1:
target++;
retry_cnt++;
if(retry_cnt>2) return UINT32_MAX;
goto retry;
}
return UINT32_MAX;
}
uint32_t get_level(uint32_t sizefactor, uint32_t blocknumber){
uint32_t target=(uint32_t)(std::ceil(std::log(blocknumber)/std::log((double)sizefactor)));
int result;
int retry_cnt=0;
retry:
switch((result=checking(target, sizefactor, blocknumber))){
case 1:
case 0:
return target;
case -1:
target++;
retry_cnt++;
if(retry_cnt>2) return UINT32_MAX;
goto retry;
}
return UINT32_MAX;
}
uint32_t get_waf(char t, uint32_t level, uint32_t size_factor){
switch (t){
case TIER:
return level;
case LEVEL:
return level*size_factor;
case HYBRIDTL:
return level-1+size_factor;
case HYBRIDLT:
return (level-1)*size_factor+1;
}
return UINT32_MAX;
}
float get_sep_waf(char t, uint32_t level, uint32_t size_factor){
switch (t){
case TIER:
return (float)(level-1)/(PAGESIZE/sizeof(uint32_t))+1+1;
case LEVEL:
return (float)(level-1)*size_factor/(PAGESIZE/sizeof(uint32_t))+size_factor+1;
case HYBRIDTL:
return level-1+size_factor;
case HYBRIDLT:
return (float)(level-1)*size_factor/(PAGESIZE/sizeof(uint32_t))+1+1;
}
return UINT32_MAX;
}
uint32_t get_raf(char t, uint32_t level, uint32_t size_factor){
switch (t){
case TIER:
return level*size_factor;
case LEVEL:
return level;
case HYBRIDTL:
return (level-1)*size_factor+1;
case HYBRIDLT:
return size_factor;
}
return UINT32_MAX;
}
uint32_t get_sparse_sorted_head(uint32_t level, uint32_t size_factor){
uint32_t head_num=0;
uint32_t level_head_num=1;
for(uint32_t i=0; i<=level-1; i++){
head_num+=level_head_num;
level_head_num*=size_factor;
}
return head_num;
}
static inline uint32_t get_total_bn(uint32_t level, uint32_t size_factor, uint32_t *array){
uint32_t res=0;
uint32_t start=1;
uint32_t sf=size_factor;
for(uint32_t i=0; i<level; i++){
if(array){
array[i]=(start*size_factor);
}
res+=(start*size_factor);
start*=size_factor;
}
return res;
}
static inline uint32_t array_some(uint32_t level, uint32_t *array){
uint32_t res=0;
for(uint32_t i=0; i<level; i++) res+=array[i];
return res;
}
uint32_t *get_blocknum_list(uint32_t *_level, uint32_t *_size_factor, uint32_t blocknum, float *ratio){
if(!(_level || _size_factor)) return NULL;
uint32_t level=*_level?*_level:get_level(*_size_factor,blocknum);
uint32_t size_factor=*_size_factor?*_size_factor:get_size_factor(*_level, blocknum);
uint32_t *res=(uint32_t *)malloc(sizeof(uint32_t)*level);
uint32_t calc_bn=get_total_bn(level, size_factor, res);
if(calc_bn>blocknum){
while(1){
calc_bn=get_total_bn(level,size_factor-1, res);
if(calc_bn > blocknum){
size_factor--;
continue;
}
else{
size_factor--;
break;
}
}
}
if(calc_bn < blocknum){
uint32_t remain=blocknum-calc_bn;
res[level-1]+=remain;
}
if(ratio){
*ratio=((float)array_some(level, res)-res[level-1])/res[level-1];
}
if(!(*_level)) *_level=level;
if(!(*_size_factor)) *_size_factor=size_factor;
return res;
}