@@ -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>
450450void 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
620613MMS3FIFO::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
0 commit comments