@@ -30,14 +30,14 @@ namespace doris {
30
30
31
31
// cgroup cpu.cfs_quota_us default value, it means disable cpu hard limit
32
32
const static int CGROUP_CPU_HARD_LIMIT_DEFAULT_VALUE = -1 ;
33
+ const static std::string CGROUP_V2_CPU_HARD_LIMIT_DEFAULT_VALUE = " max 100000" ;
33
34
34
35
class CgroupCpuCtl {
35
36
public:
36
37
virtual ~CgroupCpuCtl () = default ;
37
- CgroupCpuCtl () = default ;
38
38
CgroupCpuCtl (uint64_t wg_id) { _wg_id = wg_id; }
39
39
40
- virtual Status init ();
40
+ virtual Status init () = 0 ;
41
41
42
42
virtual Status add_thread_to_cgroup () = 0;
43
43
@@ -48,18 +48,36 @@ class CgroupCpuCtl {
48
48
// for log
49
49
void get_cgroup_cpu_info (uint64_t * cpu_shares, int * cpu_hard_limit);
50
50
51
- virtual Status delete_unused_cgroup_path (std::set<uint64_t >& used_wg_ids) = 0;
51
+ static void init_doris_cgroup_path ();
52
+
53
+ static Status delete_unused_cgroup_path (std::set<uint64_t >& used_wg_ids);
54
+
55
+ static std::unique_ptr<CgroupCpuCtl> create_cgroup_cpu_ctl (uint64_t wg_id);
56
+
57
+ static bool is_a_valid_cgroup_path (std::string cg_path);
58
+
59
+ static uint64_t cpu_soft_limit_default_value ();
52
60
53
61
protected:
54
- Status write_cg_sys_file (std::string file_path, int value, std::string msg, bool is_append);
62
+ Status write_cg_sys_file (std::string file_path, std::string value, std::string msg,
63
+ bool is_append);
55
64
56
65
virtual Status modify_cg_cpu_hard_limit_no_lock (int cpu_hard_limit) = 0;
57
66
58
67
virtual Status modify_cg_cpu_soft_limit_no_lock (int cpu_shares) = 0;
59
68
60
- std::string _doris_cgroup_cpu_path;
61
- uint64_t _cpu_core_num = CpuInfo::num_cores();
62
- uint64_t _cpu_cfs_period_us = 100000 ;
69
+ Status add_thread_to_cgroup (std::string task_file);
70
+
71
+ protected:
72
+ inline static uint64_t _cpu_core_num;
73
+ const static uint64_t _cpu_cfs_period_us = 100000 ;
74
+ inline static std::string _doris_cgroup_cpu_path = " " ;
75
+ inline static std::string _doris_cgroup_cpu_query_path = " " ;
76
+ inline static bool _is_enable_cgroup_v1_in_env = false ;
77
+ inline static bool _is_enable_cgroup_v2_in_env = false ;
78
+ inline static bool _is_cgroup_query_path_valid = false ;
79
+
80
+ protected:
63
81
int _cpu_hard_limit = 0 ;
64
82
std::shared_mutex _lock_mutex;
65
83
bool _init_succ = false ;
@@ -96,20 +114,67 @@ class CgroupCpuCtl {
96
114
class CgroupV1CpuCtl : public CgroupCpuCtl {
97
115
public:
98
116
CgroupV1CpuCtl (uint64_t tg_id) : CgroupCpuCtl(tg_id) {}
99
- CgroupV1CpuCtl () = default ;
100
117
Status init () override ;
101
118
Status modify_cg_cpu_hard_limit_no_lock (int cpu_hard_limit) override ;
102
119
Status modify_cg_cpu_soft_limit_no_lock (int cpu_shares) override ;
103
120
Status add_thread_to_cgroup () override ;
104
121
105
- Status delete_unused_cgroup_path (std::set<uint64_t >& used_wg_ids) override ;
106
-
107
122
private:
108
- std::string _cgroup_v1_cpu_query_path;
109
123
std::string _cgroup_v1_cpu_tg_path; // workload group path
110
124
std::string _cgroup_v1_cpu_tg_quota_file;
111
125
std::string _cgroup_v1_cpu_tg_shares_file;
112
126
std::string _cgroup_v1_cpu_tg_task_file;
113
127
};
114
128
129
+ /*
130
+ NOTE: cgroup v2 directory structure
131
+ 1 root path:
132
+ /sys/fs/cgroup
133
+
134
+ 2 doris home path:
135
+ /sys/fs/cgroup/{doris_home}/
136
+
137
+ 3 doris home subtree_control file:
138
+ /sys/fs/cgroup/{doris_home}/cgroup.subtree_control
139
+
140
+ 4 query path:
141
+ /sys/fs/cgroup/{doris_home}/query/
142
+
143
+ 5 query path subtree_control file:
144
+ /sys/fs/cgroup/{doris_home}/query/cgroup.subtree_control
145
+
146
+ 6 workload group path:
147
+ /sys/fs/cgroup/{doris_home}/query/{workload_group_id}
148
+
149
+ 7 workload grou cpu.max file:
150
+ /sys/fs/cgroup/{doris_home}/query/{workload_group_id}/cpu.max
151
+
152
+ 8 workload grou cpu.weight file:
153
+ /sys/fs/cgroup/{doris_home}/query/{workload_group_id}/cpu.weight
154
+
155
+ 9 workload group cgroup type file:
156
+ /sys/fs/cgroup/{doris_home}/query/{workload_group_id}/cgroup.type
157
+
158
+ */
159
+ class CgroupV2CpuCtl : public CgroupCpuCtl {
160
+ public:
161
+ CgroupV2CpuCtl (uint64_t tg_id) : CgroupCpuCtl(tg_id) {}
162
+ Status init () override ;
163
+ Status modify_cg_cpu_hard_limit_no_lock (int cpu_hard_limit) override ;
164
+ Status modify_cg_cpu_soft_limit_no_lock (int cpu_shares) override ;
165
+ Status add_thread_to_cgroup () override ;
166
+
167
+ private:
168
+ Status enable_cpu_controller (std::string file);
169
+
170
+ private:
171
+ std::string _doris_cgroup_cpu_path_subtree_ctl_file;
172
+ std::string _cgroup_v2_query_path_subtree_ctl_file;
173
+ std::string _cgroup_v2_query_wg_path;
174
+ std::string _cgroup_v2_query_wg_cpu_max_file;
175
+ std::string _cgroup_v2_query_wg_cpu_weight_file;
176
+ std::string _cgroup_v2_query_wg_thread_file;
177
+ std::string _cgroup_v2_query_wg_type_file;
178
+ };
179
+
115
180
} // namespace doris
0 commit comments