Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

first stage of pushing score decay parameters up in stack

  • Loading branch information...
commit aa722606e6dbdf6c15eb8b9294ad789814592c18 1 parent bf46321
Hubert Kario authored
79 activity_stats.c
@@ -78,36 +78,36 @@ score_decay(float curr_score, uint64_t time, double mean_lifetime) {
78 78 }
79 79
80 80 static void
81   -add_block_activity_read(struct block_activity *block, int64_t time, int granularity) {
  81 +add_block_activity_read(struct block_activity *block, int64_t time,
  82 + double mean_lifetime, double hit_score) {
82 83
83   - // TODO get from params mean lifetime and hit score
84 84 uint64_t time_diff = time - block->read_time;
85 85 if (time_diff <= 0)
86   - block->read_score += HIT_SCORE;
  86 + block->read_score += hit_score;
87 87 else {
88 88 block->read_score = score_decay(block->read_score, time_diff,
89   - MEAN_LIFETIME) + HIT_SCORE;
  89 + mean_lifetime) + hit_score;
90 90 block->read_time = time;
91 91 }
92 92 }
93 93
94 94 static void
95   -add_block_activity_write(struct block_activity *block, int64_t time, int granularity) {
  95 +add_block_activity_write(struct block_activity *block, int64_t time,
  96 + double mean_lifetime, double hit_score) {
96 97
97   - // TODO get from params mean lifetime and hit score
98 98 uint64_t time_diff = time - block->write_time;
99 99 if (time_diff <= 0)
100   - block->write_score += HIT_SCORE;
  100 + block->write_score += hit_score;
101 101 else {
102 102 block->write_score = score_decay(block->write_score, time_diff,
103   - MEAN_LIFETIME) + HIT_SCORE;
  103 + mean_lifetime) + hit_score;
104 104 block->write_time = time;
105 105 }
106 106 }
107 107
108 108 int
109 109 add_block(struct activity_stats *activity, int64_t off, int64_t time,
110   - int granularity, int type) {
  110 + double mean_lifetime, double hit_score, int type) {
111 111
112 112 int ret = 0;
113 113 struct block_activity *tmp;
@@ -142,9 +142,9 @@ add_block(struct activity_stats *activity, int64_t off, int64_t time,
142 142 }
143 143
144 144 if (type == T_READ)
145   - add_block_activity_read(&(activity->block[off]), time, granularity);
  145 + add_block_activity_read(&(activity->block[off]), time, mean_lifetime, hit_score);
146 146 else
147   - add_block_activity_write(&(activity->block[off]), time, granularity);
  147 + add_block_activity_write(&(activity->block[off]), time, mean_lifetime, hit_score);
148 148 mutex_cleanup:
149 149 pthread_mutex_unlock(&activity->mutex);
150 150
@@ -152,15 +152,17 @@ add_block(struct activity_stats *activity, int64_t off, int64_t time,
152 152 }
153 153
154 154 int
155   -add_block_read(struct activity_stats *activity, int64_t off, int64_t time, int granularity) {
  155 +add_block_read(struct activity_stats *activity, int64_t off, int64_t time,
  156 + double mean_lifetime, double hit_score) {
156 157
157   - return add_block(activity, off, time, granularity, T_READ);
  158 + return add_block(activity, off, time, mean_lifetime, hit_score, T_READ);
158 159 }
159 160
160 161 int
161   -add_block_write(struct activity_stats *activity, int64_t off, int64_t time, int granularity) {
  162 +add_block_write(struct activity_stats *activity, int64_t off, int64_t time,
  163 + double mean_lifetime, double hit_score) {
162 164
163   - return add_block(activity, off, time, granularity, T_WRITE);
  165 + return add_block(activity, off, time, mean_lifetime, hit_score, T_WRITE);
164 166 }
165 167
166 168 struct block_activity*
@@ -196,8 +198,7 @@ get_last_write_time(struct block_activity *ba)
196 198 }
197 199
198 200 float
199   -get_block_activity_raw_score(struct block_activity *block, int type,
200   - float hit_score, float scale)
  201 +get_block_activity_raw_score(struct block_activity *block, int type)
201 202 {
202 203 assert(type == T_READ || type == T_WRITE);
203 204
@@ -235,7 +236,8 @@ calculate_score(float read_score,
235 236 }
236 237
237 238 float
238   -get_block_score(struct activity_stats *activity, int64_t off, int type) {
  239 +get_block_score(struct activity_stats *activity, int64_t off, int type,
  240 + double mean_lifetime) {
239 241
240 242 double score = 0.0;
241 243 time_t time_diff;
@@ -251,33 +253,35 @@ get_block_score(struct activity_stats *activity, int64_t off, int type) {
251 253 }
252 254
253 255 if (time_diff > 0)
254   - score *= exp(-1.0 * time_diff / MEAN_LIFETIME);
  256 + score *= exp(-1.0 * time_diff / mean_lifetime);
255 257
256 258 return score;
257 259 }
258 260
259 261 float
260   -get_block_write_score(struct activity_stats *activity, int64_t off) {
  262 +get_block_write_score(struct activity_stats *activity, int64_t off,
  263 + double mean_lifetime) {
261 264
262   - return get_block_score(activity, off, T_WRITE);
  265 + return get_block_score(activity, off, T_WRITE, mean_lifetime);
263 266 }
264 267
265 268 float
266   -get_block_read_score(struct activity_stats *activity, int64_t off) {
  269 +get_block_read_score(struct activity_stats *activity, int64_t off,
  270 + double mean_lifetime) {
267 271
268   - return get_block_score(activity, off, T_READ);
  272 + return get_block_score(activity, off, T_READ, mean_lifetime);
269 273 }
270 274
271 275 float
272 276 get_raw_block_read_score(struct block_activity *ba)
273 277 {
274   - return get_block_activity_raw_score(ba, T_READ, HIT_SCORE, MEAN_LIFETIME);
  278 + return get_block_activity_raw_score(ba, T_READ);
275 279 }
276 280
277 281 float
278 282 get_raw_block_write_score(struct block_activity *ba)
279 283 {
280   - return get_block_activity_raw_score(ba, T_WRITE, HIT_SCORE, MEAN_LIFETIME);
  284 + return get_block_activity_raw_score(ba, T_WRITE);
281 285 }
282 286
283 287 void
@@ -574,11 +578,13 @@ print_block_scores(struct block_scores *bs, size_t size)
574 578 * 0 to get only writes
575 579 * @val write_multiplier How much are writes more important than reads, provide
576 580 * 0 to get only reads
  581 + * @val mean_lifetime Exponential time constant in exponential decay
577 582 * @return 0 if everything is OK, non zero if it isn't
578 583 */
579 584 int
580 585 get_best_blocks(struct activity_stats *activity, struct block_scores **bs,
581   - size_t size, int read_multiplier, int write_multiplier)
  586 + size_t size, int read_multiplier, int write_multiplier,
  587 + double mean_lifetime)
582 588 {
583 589 assert(read_multiplier || write_multiplier);
584 590 int f_ret = 0;
@@ -595,14 +601,14 @@ get_best_blocks(struct activity_stats *activity, struct block_scores **bs,
595 601
596 602 for (size_t i=0; i<size; i++) {
597 603 block.offset = i;
598   - block.score = get_block_read_score(activity, i) * read_multiplier +
599   - get_block_write_score(activity, i) * write_multiplier;
  604 + block.score = get_block_read_score(activity, i, mean_lifetime) * read_multiplier +
  605 + get_block_write_score(activity, i, mean_lifetime) * write_multiplier;
600 606 add_score_to_block_scores(*bs, i, &block);
601 607 }
602 608
603 609 for (size_t i=size; i<activity->len; i++) {
604   - block.score = get_block_read_score(activity, i) * read_multiplier +
605   - get_block_write_score(activity, i) * write_multiplier;
  610 + block.score = get_block_read_score(activity, i, mean_lifetime) * read_multiplier +
  611 + get_block_write_score(activity, i, mean_lifetime) * write_multiplier;
606 612 if (block.score > (*bs)[size-1].score) {
607 613 block.offset = i;
608 614 insert_score_to_block_scores(*bs, size, &block);
@@ -626,8 +632,9 @@ get_best_blocks(struct activity_stats *activity, struct block_scores **bs,
626 632 * @return 0 if everything is OK, non zero if it isn't
627 633 */
628 634 int
629   -get_best_blocks_with_max_score(struct activity_stats *activity, struct block_scores **bs,
630   - size_t size, int read_multiplier, int write_multiplier, float max_score)
  635 +get_best_blocks_with_max_score(struct activity_stats *activity,
  636 + struct block_scores **bs, size_t size, int read_multiplier,
  637 + int write_multiplier, double mean_lifetime, float max_score)
631 638 {
632 639 assert(read_multiplier || write_multiplier);
633 640 int f_ret = 0;
@@ -646,8 +653,8 @@ get_best_blocks_with_max_score(struct activity_stats *activity, struct block_sco
646 653 size_t i=0;
647 654 for (; count<size && count < activity->len; i++) {
648 655 block.offset = i;
649   - block.score = get_block_read_score(activity, i) * read_multiplier +
650   - get_block_write_score(activity, i) * write_multiplier;
  656 + block.score = get_block_read_score(activity, i, mean_lifetime) * read_multiplier +
  657 + get_block_write_score(activity, i, mean_lifetime) * write_multiplier;
651 658 if (block.score > max_score)
652 659 continue;
653 660 add_score_to_block_scores(*bs, count, &block);
@@ -658,8 +665,8 @@ get_best_blocks_with_max_score(struct activity_stats *activity, struct block_sco
658 665 return f_ret; // there are less qualifying blocks in activity that places in block_scores
659 666
660 667 for (; i<activity->len; i++) {
661   - block.score = get_block_read_score(activity, i) * read_multiplier +
662   - get_block_write_score(activity, i) * write_multiplier;
  668 + block.score = get_block_read_score(activity, i, mean_lifetime) * read_multiplier +
  669 + get_block_write_score(activity, i, mean_lifetime) * write_multiplier;
663 670 if (block.score > max_score)
664 671 continue;
665 672 if (block.score > (*bs)[size-1].score) {
14 activity_stats.h
@@ -50,12 +50,14 @@ void destroy_activity_stats(struct activity_stats *);
50 50 int add_block_read(struct activity_stats *activity,
51 51 int64_t off,
52 52 int64_t time,
53   - int granularity);
  53 + double mean_lifetime,
  54 + double hit_score);
54 55
55 56 int add_block_write(struct activity_stats *activity,
56 57 int64_t off,
57 58 int64_t time,
58   - int granularity);
  59 + double mean_lifetime,
  60 + double hit_score);
59 61
60 62 /* print statistics to stdout */
61 63 void dump_activity_stats(struct activity_stats *activity);
@@ -66,11 +68,12 @@ int write_activity_stats(struct activity_stats *activity, char *file);
66 68 int read_activity_stats(struct activity_stats **activity, char *file);
67 69
68 70 int get_best_blocks(struct activity_stats *activity, struct block_scores **bs,
69   - size_t size, int read_multiplier, int write_multiplier);
  71 + size_t size, int read_multiplier, int write_multiplier,
  72 + double mean_lifetime);
70 73
71 74 int get_best_blocks_with_max_score(struct activity_stats *activity,
72 75 struct block_scores **bs, size_t size, int read_multiplier,
73   - int write_multiplier, float max_score);
  76 + int write_multiplier, double mean_lifetime, float max_score);
74 77
75 78 /**
76 79 * returns reference to activity stats from single block
@@ -113,7 +116,6 @@ float calculate_score( float read_score,
113 116 /**
114 117 * Return raw read and write scores for single block
115 118 */
116   -float get_block_activity_raw_score(struct block_activity *block, int type,
117   - float hit_score, float scale);
  119 +float get_block_activity_raw_score(struct block_activity *block, int type);
118 120
119 121 #endif
5 lvmtscat.c
@@ -156,6 +156,7 @@ main(int argc, char **argv)
156 156 {
157 157 int ret = 0;
158 158 int n;
  159 + double mean_lifetime = 3 * 24 * 60 * 60;
159 160
160 161 if (parse_arguments(argc, argv))
161 162 return 1;
@@ -188,9 +189,9 @@ main(int argc, char **argv)
188 189
189 190 if(get_max)
190 191 get_best_blocks_with_max_score(as, &bs, blocks, read_mult,
191   - write_mult, max_score);
  192 + write_mult, mean_lifetime, max_score);
192 193 else
193   - get_best_blocks(as, &bs, blocks, read_mult, write_mult);
  194 + get_best_blocks(as, &bs, blocks, read_mult, write_mult, mean_lifetime);
194 195
195 196 if (pvmove_output) {
196 197 if (print_le) {
11 lvmtscd.c
@@ -266,6 +266,9 @@ collect_trace_points(char *device,
266 266 int64_t tim;
267 267 int64_t trace_start = time(NULL);
268 268 int64_t extent;
  269 + double mean_lifetime = 3*24*60*60.0L; // TODO
  270 + double hit_score = 16.0L; // TODO
  271 +
269 272
270 273 n = asprintf(&command, TRACE_APP " %s", device);
271 274 if (n <= 0)
@@ -287,17 +290,17 @@ collect_trace_points(char *device,
287 290 &tp->len, &extent,
288 291 ssize, esize))
289 292 add_block_read(activity, extent, tim,
290   - granularity);
  293 + mean_lifetime, hit_score);
291 294 add_block_read(activity, extent, tim,
292   - granularity);
  295 + mean_lifetime, hit_score);
293 296 } else if (strchr(tp->rwbs_data, 'W') != NULL ) { // write
294 297 while(trace_blocks_to_extents(&tp->block,
295 298 &tp->len, &extent,
296 299 ssize, esize))
297 300 add_block_write(activity, extent, tim,
298   - granularity);
  301 + mean_lifetime, hit_score);
299 302 add_block_write(activity, extent, tim,
300   - granularity);
  303 + mean_lifetime, hit_score);
301 304 } // ignore other types of operations
302 305 }
303 306 }
4 volumes.c
@@ -157,10 +157,10 @@ get_volume_stats(struct program_params *pp, const char *lv_name, struct extent_s
157 157 e->le = i;
158 158 e->pe = pv_i->start_seg;
159 159 e->read_score =
160   - get_block_activity_raw_score(ba, T_READ, hit_score, scale);
  160 + get_block_activity_raw_score(ba, T_READ);
161 161 e->last_read_access = get_last_read_time(ba);
162 162 e->write_score =
163   - get_block_activity_raw_score(ba, T_WRITE, hit_score, scale);
  163 + get_block_activity_raw_score(ba, T_WRITE);
164 164 e->last_write_access = get_last_write_time(ba);
165 165
166 166 e->score = calculate_score( e->read_score,

0 comments on commit aa72260

Please sign in to comment.
Something went wrong with that request. Please try again.