MCPcopy Create free account
hub / github.com/bytedance/bolt / evict

Method evict

bolt/common/caching/AsyncDataCache.cpp:382–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380}
381
382uint64_t CacheShard::evict(
383 uint64_t bytesToFree,
384 bool evictAllUnpinned,
385 MachinePageCount pagesToAcquire,
386 memory::Allocation& acquired) {
387 auto* ssdCache = cache_->ssdCache();
388 const bool skipSsdSaveable = ssdCache && ssdCache->writeInProgress();
389 auto now = accessTime();
390 std::vector<memory::Allocation> toFree;
391 int64_t tinyEvicted = 0;
392 int64_t largeEvicted = 0;
393 int32_t evictSaveableSkipped = 0;
394 {
395 std::lock_guard<std::mutex> l(mutex_);
396 const size_t size = entries_.size();
397 if (size == 0) {
398 return 0;
399 }
400 int32_t counter = 0;
401 int32_t numChecked = 0;
402 auto entryIndex = (clockHand_ % size);
403 auto iter = entries_.begin() + entryIndex;
404 while (++counter <= size) {
405 if (++iter == entries_.end()) {
406 iter = entries_.begin();
407 entryIndex = 0;
408 } else {
409 ++entryIndex;
410 }
411
412 ++numEvictChecks_;
413 ++clockHand_;
414 auto candidate = iter->get();
415 if (candidate == nullptr) {
416 continue;
417 }
418
419 ++numChecked;
420 if (evictionThreshold_ == kNoThreshold ||
421 eventCounter_ > entries_.size() / 4 ||
422 numChecked > entries_.size() / 8) {
423 now = accessTime();
424 calibrateThreshold();
425 numChecked = 0;
426 eventCounter_ = 0;
427 }
428
429 int32_t score = 0;
430 if (candidate->numPins_ == 0 &&
431 (!candidate->key_.fileNum.hasValue() || evictAllUnpinned ||
432 (score = candidate->score(now)) >= evictionThreshold_)) {
433 // split cacheable_ -> cacheEntry(candidate) cacheable_ -> (can skip
434 // cache_->saveToSsd() method)->Compliant with soft affinity strategy
435 if (skipSsdSaveable && candidate->cacheable_ &&
436 candidate->ssdSaveable_ && !evictAllUnpinned) {
437 ++evictSaveableSkipped;
438 continue;
439 }

Callers 3

makeSpaceMethod · 0.45
shrinkMethod · 0.45
clearMethod · 0.45

Calls 15

accessTimeFunction · 0.85
ssdCacheMethod · 0.80
writeInProgressMethod · 0.80
appendMoveMethod · 0.80
incrementCachedPagesMethod · 0.80
saveToSsdMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getMethod · 0.45
hasValueMethod · 0.45
scoreMethod · 0.45

Tested by

no test coverage detected