Skip to content

Commit 607643c

Browse files
committed
MB-40531: [BP] Make replica eviction ignore age threshold
Backport of http://review.couchbase.org/c/kv_engine/+/134805 Normally items above a configured MFU value item_eviction_freq_counter_age_threshold and below a configured age item_eviction_age_percentage are not evicted. This avoids evicting "young" items; their MFU counter might not reflect how hot they are yet as they were only recently stored. However, when evicting from replica vbuckets, this may not be as beneficial. As active resident ratio has a direct impact on cache miss rate and average latency, it may be better to evict even young replica items to reclaim memory where possible, before considering active vbs. Change-Id: I3aaaa13e6a682000eb520e8971ad1451dbec7f48 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/134663 Tested-by: Build Bot <[email protected]> Well-Formed: Build Bot <[email protected]> Reviewed-by: Jim Walker <[email protected]> Reviewed-by: Paolo Cocchi <[email protected]>
1 parent 496664e commit 607643c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

engines/ep/src/paging_visitor.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,23 @@ bool PagingVisitor::visit(const HashTable::HashBucketLock& lh, StoredValue& v) {
122122
uint64_t age = (maxCas > v.getCas()) ? (maxCas - v.getCas()) : 0;
123123
age = age >> ItemEviction::casBitsNotTime;
124124

125-
if ((storedValueFreqCounter <= freqCounterThreshold) &&
126-
((storedValueFreqCounter < freqCounterAgeThreshold) ||
127-
(age >= ageThreshold))) {
125+
const bool belowMFUThreshold =
126+
storedValueFreqCounter <= freqCounterThreshold;
127+
// age exceeds threshold (from age histogram, set by config param
128+
// item_eviction_age_percentage
129+
// OR
130+
// MFU is below threshold set by config param
131+
// item_eviction_freq_counter_age_threshold
132+
// Below this threshold the item is considered "cold" enough
133+
// to be evicted even if it is "young".
134+
const bool meetsAgeRequirements =
135+
age >= ageThreshold ||
136+
storedValueFreqCounter < freqCounterAgeThreshold;
137+
138+
// For replica vbuckets, young items are not protected from eviction.
139+
const bool isReplica = currentBucket->getState() == vbucket_state_replica;
140+
141+
if (belowMFUThreshold && (meetsAgeRequirements || isReplica)) {
128142
/*
129143
* If the storedValue is eligible for eviction then add its
130144
* frequency counter value to the histogram, otherwise add the

0 commit comments

Comments
 (0)