Skip to content

Commit bad5cba

Browse files
committed
Add process trace
1 parent 6c3c692 commit bad5cba

7 files changed

Lines changed: 248 additions & 93 deletions

File tree

experiments/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
## Datasets
4+
5+
6+
7+
## Algos
8+
9+
- LRU
10+
- ARC
11+
- TinyLFU
12+
- LRB
13+
- 2Q
14+
- 3LCache
15+
- S3FIFO

libCacheSim-python/libcachesim/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def create_cache(
3939
def open_trace(
4040
trace_path: str,
4141
type: TraceType,
42-
reader_init_param: dict | reader_init_param_t | None = None
42+
ignore_obj_size: bool = False
4343
) -> Reader: ...
4444

4545

libCacheSim-python/libcachesim/eviction.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class EvictionPolicyBase(ABC):
2626
def get(self, req: Request) -> bool:
2727
pass
2828

29+
@abstractmethod
30+
def process_trace(self, reader: Reader, max_requests: int = -1, max_seconds: int = -1, start_time: int = -1, end_time: int = -1) -> float:
31+
pass
32+
2933
@abstractmethod
3034
def __repr__(self) -> str:
3135
pass
@@ -43,13 +47,16 @@ def init_cache(self, cache_size: int, **kwargs) -> Cache:
4347
def get(self, req: Request) -> bool:
4448
return self.cache.get(req)
4549

50+
def process_trace(self, reader: Reader, max_requests: int = -1, max_seconds: int = -1, start_time: int = -1, end_time: int = -1) -> float:
51+
return self.cache.process_trace(reader, max_requests, max_seconds, start_time, end_time)
52+
4653
def __repr__(self):
4754
return f"{self.__class__.__name__}(cache_size={self.cache.cache_size})"
4855

4956

5057
class FIFO(EvictionPolicy):
5158
"""First In First Out replacement policy.
52-
59+
5360
Args:
5461
cache_size: Size of the cache
5562
"""
@@ -59,7 +66,7 @@ def init_cache(self, cache_size: int, **kwargs) -> Cache: # noqa: ARG002
5966

6067
class Clock(EvictionPolicy):
6168
"""Clock (Second Chance or FIFO-Reinsertion) replacement policy.
62-
69+
6370
Args:
6471
cache_size: Size of the cache
6572
n_bit_counter: Number of bits for counter (default: 1)
@@ -78,7 +85,7 @@ def init_cache(self, cache_size: int, **kwargs):
7885
if init_freq < 0 or init_freq > 2**n_bit_counter - 1:
7986
msg = "init_freq must be between 0 and 2^n_bit_counter - 1"
8087
raise ValueError(msg)
81-
88+
8289
self.init_freq = init_freq
8390
self.n_bit_counter = n_bit_counter
8491

@@ -93,9 +100,9 @@ def __repr__(self):
93100
class TwoQ(EvictionPolicy):
94101
"""2Q replacement policy.
95102
96-
2Q has three queues: Ain, Aout, Am. When a obj hits in Aout, it will be
103+
2Q has three queues: Ain, Aout, Am. When a obj hits in Aout, it will be
97104
inserted into Am otherwise it will be inserted into Ain.
98-
105+
99106
Args:
100107
cache_size: Total size of the cache
101108
ain_size_ratio: Size ratio for Ain queue (default: 0.25)
@@ -125,11 +132,11 @@ def __repr__(self):
125132

126133
class LRB(EvictionPolicy):
127134
"""LRB (Learning Relaxed Belady) replacement policy.
128-
129-
LRB is a learning-based replacement policy that uses a neural network to
135+
136+
LRB is a learning-based replacement policy that uses a neural network to
130137
predict the future access patterns of the cache, randomly select one obj
131138
outside the Belady boundary to evict.
132-
139+
133140
Args:
134141
cache_size: Size of the cache
135142
objective: Objective function to optimize (default: "byte-miss-ratio")
@@ -155,7 +162,7 @@ def __repr__(self):
155162

156163
class LRU(EvictionPolicy):
157164
"""Least Recently Used replacement policy.
158-
165+
159166
Args:
160167
cache_size: Size of the cache
161168
"""
@@ -167,10 +174,10 @@ class ARC(EvictionPolicy):
167174
"""Adaptive Replacement Cache policy.
168175
169176
ARC is a two-tiered cache with two LRU caches (T1 and T2) and two ghost
170-
lists (B1 and B2). T1 records the obj accessed only once, T2 records
171-
the obj accessed more than once. ARC has an internal parameter `p` to
177+
lists (B1 and B2). T1 records the obj accessed only once, T2 records
178+
the obj accessed more than once. ARC has an internal parameter `p` to
172179
learn and dynamically control the size of T1 and T2.
173-
180+
174181
Args:
175182
cache_size: Size of the cache
176183
"""
@@ -181,25 +188,25 @@ def init_cache(self, cache_size: int, **kwargs): # noqa: ARG002
181188
class S3FIFO(EvictionPolicy):
182189
"""S3FIFO replacement policy.
183190
184-
S3FIFO consists of three FIFO queues: Small, Main, and Ghost. Small
191+
S3FIFO consists of three FIFO queues: Small, Main, and Ghost. Small
185192
queue gets the obj and records the freq.
186-
When small queue is full, if the obj to evict satisfies the threshold,
187-
it will be moved to main queue. Otherwise, it will be evicted from small
193+
When small queue is full, if the obj to evict satisfies the threshold,
194+
it will be moved to main queue. Otherwise, it will be evicted from small
188195
queue and inserted into ghost queue.
189-
When main queue is full, the obj to evict will be evicted and reinserted
196+
When main queue is full, the obj to evict will be evicted and reinserted
190197
like Clock.
191198
If obj hits in the ghost queue, it will be moved to main queue.
192-
199+
193200
Args:
194201
cache_size: Size of the cache
195202
fifo_size_ratio: Size ratio for FIFO queue (default: 0.1)
196203
ghost_size_ratio: Size ratio for ghost queue (default: 0.9)
197204
move_to_main_threshold: Threshold for moving obj from ghost to main (default: 2)
198205
"""
199-
def __init__(self, cache_size: int, fifo_size_ratio: float = 0.1,
206+
def __init__(self, cache_size: int, fifo_size_ratio: float = 0.1,
200207
ghost_size_ratio: float = 0.9, move_to_main_threshold: int = 2):
201-
super().__init__(cache_size, fifo_size_ratio=fifo_size_ratio,
202-
ghost_size_ratio=ghost_size_ratio,
208+
super().__init__(cache_size, fifo_size_ratio=fifo_size_ratio,
209+
ghost_size_ratio=ghost_size_ratio,
203210
move_to_main_threshold=move_to_main_threshold)
204211

205212
def init_cache(self, cache_size: int, **kwargs):
@@ -231,7 +238,7 @@ class Sieve(EvictionPolicy):
231238
"""Sieve replacement policy.
232239
233240
FIFO-Reinsertion with check pointer.
234-
241+
235242
Args:
236243
cache_size: Size of the cache
237244
"""
@@ -241,7 +248,7 @@ def init_cache(self, cache_size: int, **kwargs): # noqa: ARG002
241248

242249
class ThreeLCache(EvictionPolicy):
243250
"""3L-Cache replacement policy.
244-
251+
245252
Args:
246253
cache_size: Size of the cache
247254
objective: Objective function to optimize (default: "byte-miss-ratio")
@@ -267,7 +274,7 @@ def __repr__(self):
267274

268275
class TinyLFU(EvictionPolicy):
269276
"""TinyLFU replacement policy.
270-
277+
271278
Args:
272279
cache_size: Size of the cache
273280
main_cache: Main cache to use (default: "SLRU")
@@ -292,4 +299,4 @@ def init_cache(self, cache_size: int, **kwargs):
292299
def __repr__(self):
293300
return f"{self.__class__.__name__}(cache_size={self.cache.cache_size}, " \
294301
f"main_cache={self.main_cache}, " \
295-
f"window_size={self.window_size})"
302+
f"window_size={self.window_size})"

0 commit comments

Comments
 (0)