Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update max freq on insertion, change debug invariant #130

Merged
merged 1 commit into from
Feb 26, 2025

Conversation

williamnixon20
Copy link
Contributor

@williamnixon20 williamnixon20 commented Feb 26, 2025

Hello! This is my attempt to fix the issue.

The problem arises because:

  • max_freq is not updated upon insertion of a new freq node. Currently max_freq is only updated upon hits. However, newly inserted freq nodes can have higher values in LFUDA.
  • an edge case in evicting the last object in the cache. In this case, update_min_freq will not change values, and the assertion will fail.

I have implemented small fixes for this, and have tried to verify that it works.

Thanks!

@williamnixon20 williamnixon20 mentioned this pull request Feb 26, 2025
@@ -216,6 +216,7 @@ static cache_obj_t *LFUDA_insert(cache_t *cache, const request_t *req) {
memset(new_node, 0, sizeof(freq_node_t));
new_node->freq = cache_obj->lfu.freq;
g_hash_table_insert(params->freq_map, key, new_node);
params->max_freq = params->max_freq < cache_obj->lfu.freq ? cache_obj->lfu.freq : params->max_freq;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update max_freq if a new node is added. Current behaviour only updates max_freq upon a cache hit.

@williamnixon20
Copy link
Contributor Author

Result of execution:

`./bin/cachesim ../_build/data.csv csv lfuda 0.8,0.9 -t "time-col=1,obj-id-col=3,obj-size-col=4,delimiter=,,obj-id-is-num=0"
[INFO] 02-26-2025 11:50:38 csv.c:152 (tid=139714098439104): detect csv trace has header 1
[DEBUG] 02-26-2025 11:50:38 reader.c:494 (tid=139714098439104): reset reader current offset 100
[INFO] 02-26-2025 11:50:38 cli_reader_utils.c:252 (tid=139714098439104): calculating working set size...
[INFO] 02-26-2025 11:50:38 cli_reader_utils.c:278 (tid=139714098439104): working set size: 9 object 1522722 byte
[DEBUG] 02-26-2025 11:50:38 reader.c:494 (tid=139714098439104): reset reader current offset 100
[INFO] 02-26-2025 11:50:38 cli_parser.c:553 (tid=139714098439104): trace path: ../_build/data.csv, trace_type CSV_TRACE, ofilepath result/data.csv.cachesim, 48 threads, warmup -1 sec, total 1 algo x 2 size = 2 caches, lfuda, trace-type-params: time-col=1,obj-id-col=3,obj-size-col=4,delimiter=,,obj-id-is-num=0
[INFO] 02-26-2025 11:50:38 simulator.c:287 (tid=139714098439104): simulate_with_multi_caches starts computation, num_warmup_req 0, start cache LFUDA size 1MiB, end cache LFUDA size 1MiB, 2 caches, 48 threads, please wait
[WARN] 02-26-2025 11:50:38 cache.c:156 (tid=139713829979712): 7 req, obj 1743089132010364587, size 1316252 larger than cache size 1218177

../_build/data.csv LFUDA cache size 1MiB, 9 req, miss ratio 1.0000, byte miss ratio 1.0000
../_build/data.csv LFUDA cache size 1MiB, 9 req, miss ratio 1.0000, byte miss ratio 1.0000`

@@ -353,7 +354,8 @@ static void update_min_freq(LFUDA_params_t *params) {
break;
}
}
DEBUG_ASSERT(params->min_freq > old_min_freq);
// If cache is empty, min_freq will be unchanged.
DEBUG_ASSERT(params->min_freq >= old_min_freq);
Copy link
Contributor Author

@williamnixon20 williamnixon20 Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the assertion to include equality too (params->min_freq >= old_min_freq).

This is because on a cache with only 1 item gets evicted, the min_freq will stay unchanged.

For example we have 1 item in cache like so, with current min freq = 2:
Freq 2: Object A

If this object A gets evicted, min_freq should will stay at 2, thus the assert failed.

Note: LFU will also trigger this debug assertion. LFU.c solves this by resetting the min_freq directly to 0 without calling the function

@1a1a11a
Copy link
Owner

1a1a11a commented Feb 26, 2025

Thank you!

@1a1a11a 1a1a11a merged commit 079a379 into 1a1a11a:develop Feb 26, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants