Skip to content

Commit 0da0bc4

Browse files
committed
Single process
1 parent 77131d0 commit 0da0bc4

10 files changed

Lines changed: 84 additions & 7 deletions

File tree

libCacheSim-python/libcachesim/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ThreeLCache,
2222
TinyLFU,
2323
TwoQ,
24+
S4FIFO,
2425
)
2526

2627
from .const import HF_CACHE_DIR
@@ -36,6 +37,7 @@
3637
"Clock",
3738
"Reader",
3839
"Request",
40+
"S4FIFO",
3941
"Sieve",
4042
"ThreeLCache",
4143
"TinyLFU",

libCacheSim-python/libcachesim/__init__.pyi

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ def TwoQ_init(
132132
Create a TwoQ cache instance.
133133
"""
134134

135+
136+
def S4FIFO_init(
137+
cache_size: int,
138+
small_size_ratio: float = 0.10,
139+
ghost_size_ratio: float = 0.90,
140+
move_to_main_threshold: int = 2,
141+
small_skip_ratio: float = 0
142+
) -> Cache:
143+
"""
144+
Create a S4FIFO cache instance.
145+
"""
146+
147+
135148
class reader_init_param_t:
136149
time_field: int
137150
obj_id_field: int
@@ -164,7 +177,6 @@ class Reader:
164177
def __iter__(self) -> Reader: ...
165178
def __next__(self) -> Request: ...
166179

167-
168180
# -----------------------------
169181
def get_trace_file_lists(trace_set_name: str) -> list[str]: ...
170182
def get_trace_file_path(trace_file_name: str) -> str: ...

libCacheSim-python/libcachesim/eviction.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
ThreeLCache_init,
1818
TinyLFU_init,
1919
TwoQ_init,
20+
S4FIFO_init,
2021
)
2122

2223

@@ -300,3 +301,27 @@ def __repr__(self):
300301
return f"{self.__class__.__name__}(cache_size={self.cache.cache_size}, " \
301302
f"main_cache={self.main_cache}, " \
302303
f"window_size={self.window_size})"
304+
305+
306+
class S4FIFO(EvictionPolicy):
307+
"""S4FIFO replacement policy.
308+
309+
Args:
310+
cache_size: Size of the cache
311+
"""
312+
def init_cache(self, cache_size: int, **kwargs):
313+
small_size_ratio = kwargs.get('small_size_ratio', 0.10)
314+
ghost_size_ratio = kwargs.get('ghost_size_ratio', 0.90)
315+
move_to_main_threshold = kwargs.get('move_to_main_threshold', 2)
316+
small_skip_ratio = kwargs.get('small_skip_ratio', 0)
317+
318+
if small_size_ratio <= 0 or ghost_size_ratio <= 0:
319+
msg = "small_size_ratio and ghost_size_ratio must be greater than 0"
320+
raise ValueError(msg)
321+
if move_to_main_threshold < 0:
322+
msg = "move_to_main_threshold must be greater or equal to 0"
323+
raise ValueError(msg)
324+
return S4FIFO_init(cache_size, small_size_ratio, ghost_size_ratio, move_to_main_threshold, small_skip_ratio)
325+
326+
def __repr__(self):
327+
return f"{self.__class__.__name__}(cache_size={self.cache.cache_size})"

libCacheSim-python/src/pylibcachesim.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,31 @@ PYBIND11_MODULE(_libcachesim, m) { // NOLINT(readability-named-parameter)
570570
Cache: A new TwoQ cache instance.
571571
)pbdoc");
572572

573+
// S4FIFO
574+
m.def(
575+
"S4FIFO_init",
576+
[](uint64_t cache_size, double small_size_ratio, double ghost_size_ratio, int move_to_main_threshold, double small_skip_ratio) {
577+
common_cache_params_t cc_params = {.cache_size = cache_size};
578+
cache_t* ptr = S4FIFO_init(cc_params, ("small-size-ratio=" + std::to_string(small_size_ratio) + "," +
579+
"ghost-size-ratio=" + std::to_string(ghost_size_ratio) + "," +
580+
"move-to-main-threshold=" + std::to_string(move_to_main_threshold) + "," +
581+
"small-skip-ratio=" + std::to_string(small_skip_ratio))
582+
.c_str());
583+
return std::unique_ptr<cache_t, CacheDeleter>(ptr);
584+
},
585+
py::arg("cache_size"), py::arg("small_size_ratio") = 0.10,
586+
py::arg("ghost_size_ratio") = 0.90, py::arg("move_to_main_threshold") = 2,
587+
py::arg("small_skip_ratio") = 0,
588+
R"pbdoc(
589+
Create a S4FIFO cache instance.
590+
591+
Args:
592+
cache_size (int): Size of the cache in bytes.
593+
small_size_ratio (float): Ratio of small size to cache size (default: 0.10).
594+
ghost_size_ratio (float): Ratio of ghost size to cache size (default: 0.90).
595+
move_to_main_threshold (int): Threshold for moving to main queue (default: 2).
596+
)pbdoc");
597+
573598
#ifdef VERSION_INFO
574599
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
575600
#else

libCacheSim/bin/cachesim/cache_init.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ static inline cache_t *create_cache(const char *trace_path,
6767
{"s3-fifo", S3FIFO_init},
6868
{"s3-fifov0", S3FIFOv0_init},
6969
{"s3fifo", S3FIFO_init},
70+
{"s4fifo", S4FIFO_init},
7071
{"s3fifod", S3FIFOd_init},
7172
{"s3fifov0", S3FIFOv0_init},
7273
{"size", Size_init},

libCacheSim/cache/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ set(eviction_sources_c
5151
eviction/RandomLRU.c
5252
eviction/RandomTwo.c
5353
eviction/S3FIFO.c
54+
eviction/S4FIFO.c
5455
eviction/Sieve.c
5556
eviction/Size.c
5657
eviction/SLRU.c
@@ -81,24 +82,24 @@ set(eviction_sources_cpp
8182

8283
# LRB
8384
if (ENABLE_LRB)
84-
set (eviction_sources_cpp ${eviction_sources_cpp}
85+
set (eviction_sources_cpp ${eviction_sources_cpp}
8586
eviction/LRB/lrb.cpp
8687
eviction/LRB/LRB_Interface.cpp
8788
)
8889
endif()
8990

9091
# 3L Cache
9192
if (ENABLE_3L_CACHE)
92-
set (eviction_sources_cpp ${eviction_sources_cpp}
93+
set (eviction_sources_cpp ${eviction_sources_cpp}
9394
eviction/3LCache/ThreeLCache_Interface.cpp
9495
eviction/3LCache/ThreeLCache.cpp
9596
)
9697
endif()
9798

9899
# GLCache
99100
if (ENABLE_GLCACHE)
100-
set(eviction_sources_c
101-
${eviction_sources_c}
101+
set(eviction_sources_c
102+
${eviction_sources_c}
102103
eviction/GLCache/bucket.c
103104
eviction/GLCache/dataPrep.c
104105
eviction/GLCache/eviction.c

libCacheSim/include/libCacheSim/cacheObj.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ typedef struct {
132132
int32_t main_insert_freq;
133133
} S3FIFO_obj_metadata_t;
134134

135+
typedef struct {
136+
int64_t insertion_time; // measured in number of objects inserted
137+
int64_t freq;
138+
int32_t main_insert_freq;
139+
} S4FIFO_obj_metadata_t;
140+
135141
typedef struct {
136142
// int32_t freq;
137143
int lru_id;
@@ -158,6 +164,7 @@ typedef struct cache_obj {
158164
struct cache_obj *prev;
159165
struct cache_obj *next;
160166
} queue; // for LRU, FIFO, etc.
167+
int64_t time_stamp;
161168
#ifdef SUPPORT_TTL
162169
uint32_t exp_time;
163170
#endif
@@ -189,6 +196,7 @@ typedef struct cache_obj {
189196
QDLP_obj_metadata_t QDLP;
190197
LIRS_obj_metadata_t LIRS;
191198
S3FIFO_obj_metadata_t S3FIFO;
199+
S4FIFO_obj_metadata_t S4FIFO;
192200
Sieve_obj_params_t sieve;
193201
CAR_obj_metadata_t CAR;
194202

libCacheSim/include/libCacheSim/evictionAlgo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ cache_t *S3FIFOd_init(const common_cache_params_t ccache_params,
144144
cache_t *S3FIFOv0_init(const common_cache_params_t ccache_params,
145145
const char *cache_specific_params);
146146

147+
cache_t *S4FIFO_init(const common_cache_params_t ccache_params,
148+
const char *cache_specific_params);
149+
147150
cache_t *S3LRU_init(const common_cache_params_t ccache_params,
148151
const char *cache_specific_params);
149152

scripts/install_libcachesim.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ DIR=$(dirname "${SOURCE}")
77
cd "${DIR}"/../
88
mkdir -p _build
99
cd _build
10-
cmake -G Ninja ..
10+
cmake -G Ninja .. -DENABLE_LRB=ON
1111
ninja
1212
cd "${DIR}"

scripts/install_python.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pip install -r requirements.txt
77
pip install pytest
88

99
rm -rf ./build
10-
cmake -G Ninja -B build
10+
cmake -G Ninja -B build -DENABLE_3L_CACHE=on
1111
ninja -C build
1212
pushd libCacheSim-python
1313
pip install -e . -vvv

0 commit comments

Comments
 (0)