Skip to content

Commit d997eef

Browse files
committed
Add CONSTANT mode to Landlord, emulating GD-SIZE
1 parent 1a781b6 commit d997eef

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/simulator/cache/algorithms/landlord.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Mode(Enum):
1313
FETCH_SIZE = auto()
1414
ADD_FETCH_SIZE = auto()
1515
NO_COST = auto()
16+
CONSTANT = auto()
1617

1718
@classmethod
1819
def from_str(cls, val: str) -> 'Mode':
@@ -26,6 +27,8 @@ def from_str(cls, val: str) -> 'Mode':
2627
return cls.ADD_FETCH_SIZE
2728
elif val == 'no_cost':
2829
return cls.NO_COST
30+
elif val == 'constant':
31+
return cls.CONSTANT
2932
else:
3033
raise ValueError(f'Unknown {cls.__name__} str value {val!r}')
3134

@@ -65,6 +68,9 @@ class Landlord(StateDrivenOnlineProcessor):
6568
emulates FIFO, but not quite, as the volume credit decreases whenever an
6669
additional fraction of the file is fetched.
6770
71+
CONSTANT - The credit is set to 1.0 on every access. This corresponds to
72+
the GD-SIZE(1) policy.
73+
6874
Landlord is a generalisation of many strategies, including FIFO, LRU,
6975
GreedyDual and GreedyDual-Size.
7076
"""
@@ -182,6 +188,8 @@ def _credit(
182188
return float(total_bytes)
183189
else:
184190
return current_credit
191+
elif mode is Mode.CONSTANT:
192+
return 1.0
185193

186194
raise NotImplementedError
187195

0 commit comments

Comments
 (0)