Skip to content

Commit f1dccfa

Browse files
committed
no online eviction option patch
-------------------------------- this is to be used in conjunction with the background evictors to completely disable any hot path evictions - forcing all evictions to occur via background threads
1 parent bb35a05 commit f1dccfa

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

cachelib/allocator/CacheAllocator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,7 +2996,7 @@ CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
29962996
}
29972997

29982998
if (memory == nullptr) {
2999-
if (!evict) {
2999+
if (!evict || config_.noOnlineEviction) {
30003000
return {};
30013001
}
30023002
memory = findEviction(tid, pid, cid);
@@ -3047,7 +3047,7 @@ CacheAllocator<CacheTrait>::allocateInternal(PoolId pid,
30473047
uint32_t expiryTime) {
30483048
auto tid = 0; /* TODO: consult admission policy */
30493049
for(TierId tid = 0; tid < getNumTiers(); ++tid) {
3050-
bool evict = !config_.insertToFirstFreeTier || tid == getNumTiers() - 1;
3050+
bool evict = (!config_.insertToFirstFreeTier || tid == getNumTiers() - 1);
30513051
auto handle = allocateInternalTier(tid, pid, key, size, creationTime,
30523052
expiryTime, evict);
30533053
if (handle) return handle;
@@ -4477,7 +4477,7 @@ CacheAllocator<CacheTrait>::getNextCandidate(TierId tid,
44774477
bool isExpired = false;
44784478
bool chainedItem = false;
44794479
auto& mmContainer = getMMContainer(tid, pid, cid);
4480-
bool lastTier = tid+1 >= getNumTiers();
4480+
bool lastTier = tid+1 >= getNumTiers() || config_.noOnlineEviction;
44814481

44824482
mmContainer.withEvictionIterator([this, tid, pid, cid, &candidate,
44834483
&toRecycle, &toRecycleParent,

cachelib/allocator/CacheAllocatorConfig.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ class CacheAllocatorConfig {
315315

316316
// Insert items to first free memory tier
317317
CacheAllocatorConfig& enableInsertToFirstFreeTier();
318+
319+
CacheAllocatorConfig& enableNoOnlineEviction();
318320

319321
// Passes in a callback to initialize an event tracker when the allocator
320322
// starts
@@ -547,6 +549,8 @@ class CacheAllocatorConfig {
547549
// from the bottom one if memory cache is full
548550
bool insertToFirstFreeTier = false;
549551

552+
bool noOnlineEviction = false;
553+
550554
// the number of tries to search for an item to evict
551555
// 0 means it's infinite
552556
unsigned int evictionSearchTries{50};
@@ -687,6 +691,12 @@ CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::enableInsertToFirstFreeTier()
687691
return *this;
688692
}
689693

694+
template <typename T>
695+
CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::enableNoOnlineEviction() {
696+
noOnlineEviction = true;
697+
return *this;
698+
}
699+
690700
template <typename T>
691701
CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::setCacheName(
692702
const std::string& _cacheName) {
@@ -1269,6 +1279,7 @@ std::map<std::string, std::string> CacheAllocatorConfig<T>::serialize() const {
12691279
configMap["delayCacheWorkersStart"] =
12701280
delayCacheWorkersStart ? "true" : "false";
12711281
configMap["insertToFirstFreeTier"] = std::to_string(insertToFirstFreeTier);
1282+
configMap["noOnlineEviction"] = std::to_string(noOnlineEviction);
12721283
mergeWithPrefix(configMap, throttleConfig.serialize(), "throttleConfig");
12731284
mergeWithPrefix(configMap,
12741285
chainedItemAccessConfig.serialize(),

cachelib/cachebench/cache/Cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ Cache<Allocator>::Cache(const CacheConfig& config,
579579
}
580580

581581
allocatorConfig_.insertToFirstFreeTier = config_.insertToFirstFreeTier;
582+
allocatorConfig_.noOnlineEviction = config_.noOnlineEviction;
582583

583584
auto cleanupGuard = folly::makeGuard([&] {
584585
if (!nvmCacheFilePath_.empty()) {

cachelib/cachebench/util/CacheConfig.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ CacheConfig::CacheConfig(const folly::dynamic& configJson) {
5151
JSONSetVal(configJson, useCombinedLockForIterators);
5252

5353
JSONSetVal(configJson, insertToFirstFreeTier);
54+
JSONSetVal(configJson, noOnlineEviction);
5455

5556
JSONSetVal(configJson, lru2qHotPct);
5657
JSONSetVal(configJson, lru2qColdPct);

cachelib/cachebench/util/CacheConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct CacheConfig : public JSONConfig {
9999
bool useCombinedLockForIterators{true};
100100

101101
bool insertToFirstFreeTier{false};
102+
bool noOnlineEviction{false};
102103

103104
// LRU param
104105
uint64_t lruIpSpec{0};

0 commit comments

Comments
 (0)