@@ -35,15 +35,31 @@ BackgroundEvictor<CacheT>::~BackgroundEvictor() { stop(std::chrono::seconds(0));
3535
3636template <typename CacheT>
3737void BackgroundEvictor<CacheT>::work() {
38- try {
39- for (const auto pid : cache_.getRegularPoolIds ()) {
40- // check if the pool is full - probably should be if tier is full
41- if (cache_.getPoolByTid (pid,tid_).allSlabsAllocated ()) {
42- checkAndRun (pid);
38+ if (strategy_->poll_ ) {
39+ try {
40+ for (const auto pid : cache_.getRegularPoolIds ()) {
41+ // check if the pool is full - probably should be if tier is full
42+ if (cache_.getPoolByTid (pid,tid_).allSlabsAllocated ()) {
43+ checkAndRun (pid);
44+ }
4345 }
46+ } catch (const std::exception& ex) {
47+ XLOGF (ERR, " BackgroundEvictor interrupted due to exception: {}" , ex.what ());
4448 }
45- } catch (const std::exception& ex) {
46- XLOGF (ERR, " BackgroundEvictor interrupted due to exception: {}" , ex.what ());
49+ } else {
50+ // when an eviction for a given pid,cid at tier 0 is triggered this will be run
51+ while (1 ) {
52+ std::pair p = tasks_.dequeue ();
53+ unsigned int pid = p.first ;
54+ unsigned int cid = p.second ;
55+ unsigned int batch = strategy_->calculateBatchSize (cache_,tid_,pid,cid);
56+ // try evicting BATCH items from the class in order to reach free target
57+ unsigned int evicted =
58+ BackgroundEvictorAPIWrapper<CacheT>::traverseAndEvictItems (cache_,
59+ tid_,pid,cid,batch);
60+ runCount_ = runCount_ + 1 ;
61+ }
62+
4763 }
4864}
4965
0 commit comments