Skip to content

Commit 3714df0

Browse files
Move growing ghost logic
1 parent 71820d8 commit 3714df0

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

cachelib/allocator/MMS3FIFO.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class MMS3FIFO {
110110
// The size of tiny cache, as a percentage of the total size.
111111
size_t tinySizePercent{10};
112112

113-
// The size of ghost queue, as a percentage of main queue
114-
size_t ghostSizePercent{100};
113+
// The size of ghost queue, as a percentage of total size
114+
size_t ghostSizePercent{90};
115115
};
116116

117117
// The container object which can be used to keep track of objects of type
@@ -418,7 +418,7 @@ class MMS3FIFO {
418418
// time.
419419
mutable Mutex lruMutex_;
420420

421-
// Current ghost capacity
421+
// Current capacity to track ghost size
422422
size_t capacity_{0};
423423

424424
// the lru
@@ -450,17 +450,12 @@ template <typename T, MMS3FIFO::Hook<T> T::* HookPtr>
450450
void MMS3FIFO::Container<T, HookPtr>::maybeGrowGhostLocked() noexcept {
451451
size_t capacity = lru_.size();
452452

453-
// If the new capacity ask is more than double the current size,
454-
// expand the ghost queue
455-
if (2 * capacity_ > capacity) {
453+
// Only consider growing ghost when lru size doubles.
454+
if (2 * capacity_ > capacity || capacity == 0) {
456455
return;
457456
}
458457

459-
// Capacity should be proportion of main queue
460-
size_t capacityMain = lru_.getList(LruType::Main).size();
461-
size_t expectedGhostSize =
462-
static_cast<size_t>(capacityMain * config_.ghostSizePercent / 100);
463-
458+
size_t expectedGhostSize = static_cast<size_t>(capacity * config_.ghostSizePercent / 100);
464459
ghostQueue_.resize(expectedGhostSize);
465460
capacity_ = capacity;
466461
}
@@ -546,8 +541,6 @@ bool MMS3FIFO::Container<T, HookPtr>::add(T& node) noexcept {
546541
markTiny(node);
547542
}
548543

549-
maybeGrowGhostLocked();
550-
551544
node.markInMMContainer();
552545
setUpdateTime(node, currTime);
553546
unmarkAccessed(node);
@@ -620,6 +613,8 @@ typename MMS3FIFO::Container<T, HookPtr>::LockedIterator
620613
MMS3FIFO::Container<T, HookPtr>::getEvictionIterator() noexcept {
621614
LockHolder l(lruMutex_);
622615
rebalanceForEviction();
616+
// Cache is full now so we know it's max size
617+
maybeGrowGhostLocked();
623618
return LockedIterator{std::move(l), *this};
624619
}
625620

cachelib/cachebench/util/CacheConfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ struct CacheConfig : public JSONConfig {
106106
size_t lru2qColdPct{20};
107107

108108
// S3FIFO params
109-
size_t ghostSizePercent{100};
110-
size_t tinySizePercent{10};
109+
size_t ghostSizePercent{90}; // Ghost size as percentage of whole cache
110+
size_t tinySizePercent{10}; // Tiny size as percentage of whole cache
111111

112112
double allocFactor{1.5};
113113
// maximum alloc size generated using the alloc factor above.

0 commit comments

Comments
 (0)