Skip to content

Commit

Permalink
[fix](memory) Fix prune all LRU Cache based on number #34601
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyiZzz authored May 11, 2024
1 parent fad1a21 commit dbece74
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions be/src/runtime/memory/cache_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace doris {

static constexpr int32_t CACHE_MIN_FREE_SIZE = 67108864; // 64M
static constexpr int32_t CACHE_MIN_FREE_NUMBER = 1024;

// Base of all caches. register to CacheManager when cache is constructed.
class CachePolicy {
Expand Down
46 changes: 33 additions & 13 deletions be/src/runtime/memory/lru_cache_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ class LRUCachePolicy : public CachePolicy {
uint64_t new_id() { return _cache->new_id(); };

// Subclass can override this method to determine whether to do the minor or full gc
virtual bool exceed_prune_limit() { return mem_consumption() > CACHE_MIN_FREE_SIZE; }
virtual bool exceed_prune_limit() {
return _lru_cache_type == LRUCacheType::SIZE ? mem_consumption() > CACHE_MIN_FREE_SIZE
: get_usage() > CACHE_MIN_FREE_NUMBER;
}

// Try to prune the cache if expired.
void prune_stale() override {
Expand All @@ -142,8 +145,8 @@ class LRUCachePolicy : public CachePolicy {
curtime);
};

LOG(INFO) << fmt::format("[MemoryGC] {} prune stale start, consumption {}",
type_string(_type), mem_consumption());
LOG(INFO) << fmt::format("[MemoryGC] {} prune stale start, consumption {}, usage {}",
type_string(_type), mem_consumption(), get_usage());
// Prune cache in lazy mode to save cpu and minimize the time holding write lock
PrunedInfo pruned_info = _cache->prune_if(pred, true);
COUNTER_SET(_freed_entrys_counter, pruned_info.pruned_count);
Expand All @@ -154,10 +157,19 @@ class LRUCachePolicy : public CachePolicy {
type_string(_type), _freed_entrys_counter->value(),
_freed_memory_counter->value(), _prune_stale_number_counter->value());
} else {
LOG(INFO) << fmt::format(
"[MemoryGC] {} not need prune stale, consumption {} less than "
"CACHE_MIN_FREE_SIZE {}",
type_string(_type), mem_consumption(), CACHE_MIN_FREE_SIZE);
if (_lru_cache_type == LRUCacheType::SIZE) {
LOG(INFO) << fmt::format(
"[MemoryGC] {} not need prune stale, LRUCacheType::SIZE consumption {} "
"less "
"than CACHE_MIN_FREE_SIZE {}",
type_string(_type), mem_consumption(), CACHE_MIN_FREE_SIZE);
} else if (_lru_cache_type == LRUCacheType::NUMBER) {
LOG(INFO) << fmt::format(
"[MemoryGC] {} not need prune stale, LRUCacheType::NUMBER usage {} less "
"than "
"CACHE_MIN_FREE_NUMBER {}",
type_string(_type), get_usage(), CACHE_MIN_FREE_NUMBER);
}
}
}

Expand All @@ -170,8 +182,8 @@ class LRUCachePolicy : public CachePolicy {
if ((force && mem_consumption() != 0) || exceed_prune_limit()) {
COUNTER_SET(_cost_timer, (int64_t)0);
SCOPED_TIMER(_cost_timer);
LOG(INFO) << fmt::format("[MemoryGC] {} prune all start, consumption {}",
type_string(_type), mem_consumption());
LOG(INFO) << fmt::format("[MemoryGC] {} prune all start, consumption {}, usage {}",
type_string(_type), mem_consumption(), get_usage());
PrunedInfo pruned_info = _cache->prune();
COUNTER_SET(_freed_entrys_counter, pruned_info.pruned_count);
COUNTER_SET(_freed_memory_counter, pruned_info.pruned_size);
Expand All @@ -181,10 +193,18 @@ class LRUCachePolicy : public CachePolicy {
type_string(_type), _freed_entrys_counter->value(),
_freed_memory_counter->value(), _prune_all_number_counter->value(), force);
} else {
LOG(INFO) << fmt::format(
"[MemoryGC] {} not need prune all, force is {}, consumption {}, "
"CACHE_MIN_FREE_SIZE {}",
type_string(_type), force, mem_consumption(), CACHE_MIN_FREE_SIZE);
if (_lru_cache_type == LRUCacheType::SIZE) {
LOG(INFO) << fmt::format(
"[MemoryGC] {} not need prune all, force is {}, LRUCacheType::SIZE "
"consumption {}, "
"CACHE_MIN_FREE_SIZE {}",
type_string(_type), force, mem_consumption(), CACHE_MIN_FREE_SIZE);
} else if (_lru_cache_type == LRUCacheType::NUMBER) {
LOG(INFO) << fmt::format(
"[MemoryGC] {} not need prune all, force is {}, LRUCacheType::NUMBER "
"usage {}, CACHE_MIN_FREE_NUMBER {}",
type_string(_type), force, get_usage(), CACHE_MIN_FREE_NUMBER);
}
}
}

Expand Down

0 comments on commit dbece74

Please sign in to comment.