Skip to content

Commit d3c4364

Browse files
committed
Add flash metrics functionality and update LRU eviction algorithm
- Introduced flash metrics executable to calculate request and byte miss ratios, along with flash write ratios for different caching algorithms. - Updated CMakeLists.txt to include new flashMetrics source files and set properties. - Implemented metrics calculation in metrics.cpp, including handling for FIFO, CLOCK, and LRU algorithms. - Enhanced LRU eviction algorithm to track object promotions and byte promotions for improved metrics reporting.
1 parent 1dd7003 commit d3c4364

5 files changed

Lines changed: 178 additions & 3 deletions

File tree

doc/2024_google_flash_metrics.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# 2024 Google Trace Flash Metrics
2+
3+
This document records request miss ratio, byte miss ratio, and flash write
4+
ratio for FIFO, CLOCK, and LRU on the three traces under `2024_google/`.
5+
6+
## Setup
7+
8+
- Traces:
9+
- `2024_google/cluster1_16TB.lcs.zst`
10+
- `2024_google/cluster2_16TB.lcs.zst`
11+
- `2024_google/cluster3_18TB.lcs.zst`
12+
- Trace type: `lcs`
13+
- Cache fractions: `0.001`, `0.01`
14+
- Algorithms: `fifo`, `clock`, `lru`
15+
- Runner: `_build_dbg/bin/flashMetrics`
16+
17+
## Flash Write Definitions
18+
19+
- FIFO: `flash writes = byte miss ratio`
20+
- CLOCK: `flash writes = byte miss ratio + byte reinsertion ratio`
21+
- LRU: `flash writes = byte miss ratio + byte promotion ratio`
22+
23+
## Commands
24+
25+
```bash
26+
export PATH="/users/juncheng/software/cmake/bin:$PATH"
27+
bash scripts/debug.sh -c
28+
29+
_build_dbg/bin/flashMetrics 2024_google/cluster1_16TB.lcs.zst lcs fifo,clock,lru 0.001,0.01 --num-thread=2 --print-head-req=false --verbose=false
30+
_build_dbg/bin/flashMetrics 2024_google/cluster2_16TB.lcs.zst lcs fifo,clock,lru 0.001,0.01 --num-thread=2 --print-head-req=false --verbose=false
31+
_build_dbg/bin/flashMetrics 2024_google/cluster3_18TB.lcs.zst lcs fifo,clock,lru 0.001,0.01 --num-thread=2 --print-head-req=false --verbose=false
32+
```
33+
34+
## Resolved Cache Sizes
35+
36+
- `cluster1_16TB.lcs.zst`
37+
- `0.001` -> `16594555823` bytes
38+
- `0.01` -> `165945558237` bytes
39+
- `cluster2_16TB.lcs.zst`
40+
- `0.001` -> `17936923773` bytes
41+
- `0.01` -> `179369237734` bytes
42+
- `cluster3_18TB.lcs.zst`
43+
- `0.001` -> `20588812227` bytes
44+
- `0.01` -> `205888122275` bytes
45+
46+
## Results
47+
48+
| Trace | Cache frac | Algo | Cache size (bytes) | Req miss ratio | Byte miss ratio | Extra ratio | Flash writes |
49+
| --- | --- | --- | ---: | ---: | ---: | --- | ---: |
50+
| cluster1_16TB | 0.001 | FIFO | 16594555823 | 0.07250300 | 0.10009658 | none = 0.00000000 | 0.10009658 |
51+
| cluster1_16TB | 0.010 | FIFO | 165945558237 | 0.04770304 | 0.07727100 | none = 0.00000000 | 0.07727100 |
52+
| cluster1_16TB | 0.001 | CLOCK | 16594555823 | 0.07092634 | 0.09869641 | reinsertion = 0.08800090 | 0.18669730 |
53+
| cluster1_16TB | 0.010 | CLOCK | 165945558237 | 0.04411648 | 0.07548000 | reinsertion = 0.07950309 | 0.15498310 |
54+
| cluster1_16TB | 0.001 | LRU | 16594555823 | 0.07083643 | 0.09982770 | promotion = 0.80526211 | 0.90508981 |
55+
| cluster1_16TB | 0.010 | LRU | 165945558237 | 0.04360217 | 0.07543045 | promotion = 1.03627784 | 1.11170829 |
56+
| cluster2_16TB | 0.001 | FIFO | 17936923773 | 0.08057969 | 0.10995881 | none = 0.00000000 | 0.10995881 |
57+
| cluster2_16TB | 0.010 | FIFO | 179369237734 | 0.05957426 | 0.08904639 | none = 0.00000000 | 0.08904639 |
58+
| cluster2_16TB | 0.001 | CLOCK | 17936923773 | 0.07892277 | 0.10866495 | reinsertion = 0.09047547 | 0.19914042 |
59+
| cluster2_16TB | 0.010 | CLOCK | 179369237734 | 0.05604016 | 0.08592051 | reinsertion = 0.07462376 | 0.16054427 |
60+
| cluster2_16TB | 0.001 | LRU | 17936923773 | 0.07909499 | 0.10916144 | promotion = 0.60058168 | 0.70974311 |
61+
| cluster2_16TB | 0.010 | LRU | 179369237734 | 0.05565730 | 0.08578171 | promotion = 0.64529025 | 0.73107196 |
62+
| cluster3_18TB | 0.001 | FIFO | 20588812227 | 0.05021450 | 0.09560787 | none = 0.00000000 | 0.09560787 |
63+
| cluster3_18TB | 0.010 | FIFO | 205888122275 | 0.03976046 | 0.07676905 | none = 0.00000000 | 0.07676905 |
64+
| cluster3_18TB | 0.001 | CLOCK | 20588812227 | 0.04947112 | 0.09444140 | reinsertion = 0.08930696 | 0.18374837 |
65+
| cluster3_18TB | 0.010 | CLOCK | 205888122275 | 0.03857983 | 0.07492515 | reinsertion = 0.07284486 | 0.14777001 |
66+
| cluster3_18TB | 0.001 | LRU | 20588812227 | 0.04920643 | 0.09435400 | promotion = 0.80822255 | 0.90257655 |
67+
| cluster3_18TB | 0.010 | LRU | 205888122275 | 0.03830963 | 0.07459867 | promotion = 0.90057613 | 0.97517480 |
68+
69+
## Notes
70+
71+
- The LRU flash write ratio can exceed `1.0` because the promotion term is
72+
normalized by requested bytes and hot bytes can be promoted multiple times.
73+
- The CLOCK extra term is the measured byte reinsertion ratio from the cache
74+
implementation.
75+
- The FIFO extra term is zero by definition for this report.

libCacheSim/bin/customized/SOSP23/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,21 @@ target_include_directories(flash PRIVATE
2929
${GLib_INCLUDE_DIRS}
3030
)
3131
target_link_libraries(flash ${PROJECT_NAME} ${dependency_libs})
32+
33+
set(flashMetrics_sources_cpp
34+
flash/metrics.cpp
35+
../../cachesim/cli_parser.c
36+
../../cli_reader_utils.c
37+
)
38+
add_executable(flashMetrics ${flashMetrics_sources_cpp})
39+
target_include_directories(flashMetrics PRIVATE
40+
../../
41+
${libCacheSim_include_dir}
42+
${GLib_INCLUDE_DIRS}
43+
)
44+
target_link_libraries(flashMetrics ${PROJECT_NAME} ${dependency_libs})
45+
set_target_properties(flashMetrics PROPERTIES
46+
CXX_STANDARD 17
47+
CXX_STANDARD_REQUIRED YES
48+
CXX_EXTENSIONS NO
49+
)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include <inttypes.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <strings.h>
5+
6+
#include "cachesim/internal.h"
7+
#include "libCacheSim/evictionAlgo.h"
8+
#include "libCacheSim/simulator.h"
9+
10+
static double ratio_u64(uint64_t numerator, uint64_t denominator) {
11+
return denominator > 0 ? (double)numerator / (double)denominator : 0.0;
12+
}
13+
14+
static double extra_write_ratio(const cache_t *cache, uint64_t req_bytes,
15+
const char **extra_label) {
16+
*extra_label = "none";
17+
if (req_bytes == 0) {
18+
return 0.0;
19+
}
20+
21+
if (strcasecmp(cache->cache_name, "FIFO") == 0) {
22+
return 0.0;
23+
}
24+
25+
if (strncasecmp(cache->cache_name, "Clock", 5) == 0) {
26+
const Clock_params_t *params =
27+
(const Clock_params_t *)cache->eviction_params;
28+
*extra_label = "byte_reinsertion_ratio";
29+
return ratio_u64(params->n_byte_rewritten, req_bytes);
30+
}
31+
32+
if (strncasecmp(cache->cache_name, "LRU", 3) == 0) {
33+
const LRU_params_t *params = (const LRU_params_t *)cache->eviction_params;
34+
*extra_label = "byte_promotion_ratio";
35+
return ratio_u64(params->n_byte_promoted, req_bytes);
36+
}
37+
38+
fprintf(stderr, "unsupported cache for flash metrics: %s\n",
39+
cache->cache_name);
40+
exit(1);
41+
}
42+
43+
int main(int argc, char **argv) {
44+
struct arguments args;
45+
parse_cmd(argc, argv, &args);
46+
47+
int num_caches = args.n_cache_size * args.n_eviction_algo;
48+
cache_stat_t *result = simulate_with_multi_caches(
49+
args.reader, args.caches, num_caches, NULL, 0, args.warmup_sec,
50+
args.n_thread, false, true);
51+
52+
printf("RESULT,trace,cache_name,cache_size_bytes,req_miss_ratio,"
53+
"byte_miss_ratio,extra_ratio_label,extra_ratio,flash_write_ratio\n");
54+
for (int i = 0; i < num_caches; i++) {
55+
const char *extra_label = "none";
56+
double req_miss_ratio = ratio_u64(result[i].n_miss, result[i].n_req);
57+
double byte_miss_ratio =
58+
ratio_u64(result[i].n_miss_byte, result[i].n_req_byte);
59+
double extra_ratio =
60+
extra_write_ratio(args.caches[i], result[i].n_req_byte, &extra_label);
61+
double flash_write_ratio = byte_miss_ratio + extra_ratio;
62+
63+
printf("RESULT,%s,%s,%llu,%.8f,%.8f,%s,%.8f,%.8f\n", args.trace_path,
64+
args.caches[i]->cache_name,
65+
(unsigned long long)result[i].cache_size, req_miss_ratio,
66+
byte_miss_ratio, extra_label, extra_ratio, flash_write_ratio);
67+
}
68+
69+
for (int i = 0; i < num_caches; i++) {
70+
args.caches[i]->cache_free(args.caches[i]);
71+
}
72+
my_free(sizeof(cache_stat_t) * num_caches, result);
73+
free_arg(&args);
74+
75+
return 0;
76+
}

libCacheSim/cache/eviction/LRU.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ cache_t *LRU_init(const common_cache_params_t ccache_params,
7474
#endif
7575

7676
LRU_params_t *params = malloc(sizeof(LRU_params_t));
77-
params->q_head = NULL;
78-
params->q_tail = NULL;
77+
memset(params, 0, sizeof(LRU_params_t));
7978
cache->eviction_params = params;
8079

8180
return cache;
@@ -141,7 +140,11 @@ static cache_obj_t *LRU_find(cache_t *cache, const request_t *req,
141140
#ifdef USE_BELADY
142141
if (req->next_access_vtime != INT64_MAX)
143142
#endif
144-
move_obj_to_head(&params->q_head, &params->q_tail, cache_obj);
143+
if (cache_obj != params->q_head) {
144+
params->n_obj_promoted += 1;
145+
params->n_byte_promoted += cache_obj->obj_size;
146+
move_obj_to_head(&params->q_head, &params->q_tail, cache_obj);
147+
}
145148
}
146149
return cache_obj;
147150
}

libCacheSim/include/libCacheSim/evictionAlgo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ typedef struct {
1515
typedef struct {
1616
cache_obj_t *q_head;
1717
cache_obj_t *q_tail;
18+
19+
int64_t n_obj_promoted;
20+
int64_t n_byte_promoted;
1821
} LRU_params_t;
1922

2023
/* used by LFU related */

0 commit comments

Comments
 (0)