be/src/runtime/memory/cache_manager.cpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "runtime/memory/cache_manager.h" |
19 | | |
20 | | #include "runtime/memory/cache_policy.h" |
21 | | #include "runtime/runtime_profile.h" |
22 | | |
23 | | namespace doris { |
24 | | #include "common/compile_check_begin.h" |
25 | | |
26 | | int64_t CacheManager::for_each_cache_prune_stale_wrap( |
27 | 96 | std::function<void(CachePolicy* cache_policy)> func, RuntimeProfile* profile) { |
28 | 96 | int64_t freed_size = 0; |
29 | 96 | std::lock_guard<std::mutex> l(_caches_lock); |
30 | 1.72k | for (const auto& pair : _caches) { |
31 | 1.72k | auto* cache_policy = pair.second; |
32 | 1.72k | if (!cache_policy->enable_prune()) { |
33 | 288 | continue; |
34 | 288 | } |
35 | 1.44k | func(cache_policy); |
36 | 1.44k | freed_size += cache_policy->profile()->get_counter("FreedMemory")->value(); |
37 | 1.44k | if (cache_policy->profile()->get_counter("FreedMemory")->value() != 0 && profile) { |
38 | 0 | profile->add_child(cache_policy->profile(), true, nullptr); |
39 | 0 | } |
40 | 1.44k | } |
41 | 96 | return freed_size; |
42 | 96 | } |
43 | | |
44 | 96 | int64_t CacheManager::for_each_cache_prune_stale(RuntimeProfile* profile) { |
45 | 96 | if (need_prune(&_last_prune_stale_timestamp, "stale")) { |
46 | 96 | return for_each_cache_prune_stale_wrap( |
47 | 1.44k | [](CachePolicy* cache_policy) { cache_policy->prune_stale(); }, profile); |
48 | 96 | } |
49 | 0 | return 0; |
50 | 96 | } |
51 | | |
52 | 0 | int64_t CacheManager::for_each_cache_prune_all(RuntimeProfile* profile, bool force) { |
53 | 0 | if (force || need_prune(&_last_prune_all_timestamp, "all")) { |
54 | 0 | return for_each_cache_prune_stale_wrap( |
55 | 0 | [force](CachePolicy* cache_policy) { cache_policy->prune_all(force); }, profile); |
56 | 0 | } |
57 | 0 | return 0; |
58 | 0 | } |
59 | | |
60 | 0 | int64_t CacheManager::cache_prune_all(CachePolicy::CacheType type, bool force) { |
61 | 0 | std::lock_guard<std::mutex> l(_caches_lock); |
62 | 0 | auto* cache_policy = _caches[type]; |
63 | 0 | cache_policy->prune_all(force); |
64 | 0 | return cache_policy->profile()->get_counter("FreedMemory")->value(); |
65 | 0 | } |
66 | | |
67 | | int64_t CacheManager::for_each_cache_refresh_capacity(double adjust_weighted, |
68 | 0 | RuntimeProfile* profile) { |
69 | 0 | int64_t freed_size = 0; |
70 | 0 | std::lock_guard<std::mutex> l(_caches_lock); |
71 | 0 | for (const auto& pair : _caches) { |
72 | 0 | auto* cache_policy = pair.second; |
73 | 0 | if (!cache_policy->enable_prune()) { |
74 | 0 | continue; |
75 | 0 | } |
76 | 0 | cache_policy->adjust_capacity_weighted(adjust_weighted); |
77 | 0 | freed_size += cache_policy->profile()->get_counter("FreedMemory")->value(); |
78 | 0 | if (cache_policy->profile()->get_counter("FreedMemory")->value() != 0 && profile) { |
79 | 0 | profile->add_child(cache_policy->profile(), true, nullptr); |
80 | 0 | } |
81 | 0 | } |
82 | 0 | return freed_size; |
83 | 0 | } |
84 | | |
85 | 0 | void CacheManager::for_each_cache_reset_initial_capacity(double adjust_weighted) { |
86 | 0 | std::lock_guard<std::mutex> l(_caches_lock); |
87 | 0 | for (const auto& pair : _caches) { |
88 | 0 | pair.second->reset_initial_capacity(adjust_weighted); |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | | #include "common/compile_check_end.h" |
93 | | } // namespace doris |