]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/cephadm/autotune.py
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / cephadm / autotune.py
1 import logging
2 from typing import List, Optional, Callable, Any, Tuple
3
4 from orchestrator._interface import DaemonDescription
5
6 logger = logging.getLogger(__name__)
7
8
9 class MemoryAutotuner(object):
10
11 min_size_by_type = {
12 'mds': 4096 * 1048576,
13 'mgr': 4096 * 1048576,
14 'mon': 1024 * 1048576,
15 'crash': 128 * 1048576,
16 'keepalived': 128 * 1048576,
17 'haproxy': 128 * 1048576,
18 }
19 default_size = 1024 * 1048576
20
21 def __init__(
22 self,
23 daemons: List[DaemonDescription],
24 config_get: Callable[[str, str], Any],
25 total_mem: int,
26 ):
27 self.daemons = daemons
28 self.config_get = config_get
29 self.total_mem = total_mem
30
31 def tune(self) -> Tuple[Optional[int], List[str]]:
32 tuned_osds: List[str] = []
33 total = self.total_mem
34 for d in self.daemons:
35 if d.daemon_type == 'mds':
36 total -= self.config_get(d.name(), 'mds_cache_memory_limit')
37 continue
38 if d.daemon_type != 'osd':
39 assert d.daemon_type
40 total -= max(
41 self.min_size_by_type.get(d.daemon_type, self.default_size),
42 d.memory_usage or 0
43 )
44 continue
45 if not self.config_get(d.name(), 'osd_memory_target_autotune'):
46 total -= self.config_get(d.name(), 'osd_memory_target')
47 continue
48 tuned_osds.append(d.name())
49 if total < 0:
50 return None, []
51 if not tuned_osds:
52 return None, []
53 per = total // len(tuned_osds)
54 return int(per), tuned_osds