@@ -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,44 @@ 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
52
53
- protected:
54
- Status write_cg_sys_file (std::string file_path, int value, std::string msg, bool is_append);
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);
55
58
59
+ static uint64_t cpu_soft_limit_default_value ();
60
+
61
+ protected:
56
62
virtual Status modify_cg_cpu_hard_limit_no_lock (int cpu_hard_limit) = 0;
57
63
58
64
virtual Status modify_cg_cpu_soft_limit_no_lock (int cpu_shares) = 0;
59
65
60
- std::string _doris_cgroup_cpu_path;
61
- uint64_t _cpu_core_num = CpuInfo::num_cores();
62
- uint64_t _cpu_cfs_period_us = 100000 ;
66
+ Status add_thread_to_cgroup (std::string task_file);
67
+
68
+ static Status write_cg_sys_file (std::string file_path, std::string value, std::string msg,
69
+ bool is_append);
70
+
71
+ static Status init_cgroup_v2_query_path_public_file (std::string home_path,
72
+ std::string query_path);
73
+
74
+ protected:
75
+ inline static uint64_t _cpu_core_num;
76
+ const static uint64_t _cpu_cfs_period_us = 100000 ;
77
+ inline static std::string _doris_cgroup_cpu_path = " " ;
78
+ inline static std::string _doris_cgroup_cpu_query_path = " " ;
79
+ inline static bool _is_enable_cgroup_v1_in_env = false ;
80
+ inline static bool _is_enable_cgroup_v2_in_env = false ;
81
+ inline static bool _is_cgroup_query_path_valid = false ;
82
+
83
+ // cgroup v2 public file
84
+ inline static std::string _doris_cgroup_cpu_path_subtree_ctl_file = " " ;
85
+ inline static std::string _cgroup_v2_query_path_subtree_ctl_file = " " ;
86
+ inline static std::string _doris_cg_v2_procs_file = " " ;
87
+
88
+ protected:
63
89
int _cpu_hard_limit = 0 ;
64
90
std::shared_mutex _lock_mutex;
65
91
bool _init_succ = false ;
@@ -96,20 +122,65 @@ class CgroupCpuCtl {
96
122
class CgroupV1CpuCtl : public CgroupCpuCtl {
97
123
public:
98
124
CgroupV1CpuCtl (uint64_t tg_id) : CgroupCpuCtl(tg_id) {}
99
- CgroupV1CpuCtl () = default ;
100
125
Status init () override ;
101
126
Status modify_cg_cpu_hard_limit_no_lock (int cpu_hard_limit) override ;
102
127
Status modify_cg_cpu_soft_limit_no_lock (int cpu_shares) override ;
103
128
Status add_thread_to_cgroup () override ;
104
129
105
- Status delete_unused_cgroup_path (std::set<uint64_t >& used_wg_ids) override ;
106
-
107
130
private:
108
- std::string _cgroup_v1_cpu_query_path;
109
131
std::string _cgroup_v1_cpu_tg_path; // workload group path
110
132
std::string _cgroup_v1_cpu_tg_quota_file;
111
133
std::string _cgroup_v1_cpu_tg_shares_file;
112
134
std::string _cgroup_v1_cpu_tg_task_file;
113
135
};
114
136
137
+ /*
138
+ NOTE: cgroup v2 directory structure
139
+ 1 root path:
140
+ /sys/fs/cgroup
141
+
142
+ 2 doris home path:
143
+ /sys/fs/cgroup/{doris_home}/
144
+
145
+ 3 doris home subtree_control file:
146
+ /sys/fs/cgroup/{doris_home}/cgroup.subtree_control
147
+
148
+ 4 query path:
149
+ /sys/fs/cgroup/{doris_home}/query/
150
+
151
+ 5 query path subtree_control file:
152
+ /sys/fs/cgroup/{doris_home}/query/cgroup.subtree_control
153
+
154
+ 6 query path procs file:
155
+ /sys/fs/cgroup/{doris_home}/query/cgroup.procs
156
+
157
+ 7 workload group path:
158
+ /sys/fs/cgroup/{doris_home}/query/{workload_group_id}
159
+
160
+ 8 workload grou cpu.max file:
161
+ /sys/fs/cgroup/{doris_home}/query/{workload_group_id}/cpu.max
162
+
163
+ 9 workload grou cpu.weight file:
164
+ /sys/fs/cgroup/{doris_home}/query/{workload_group_id}/cpu.weight
165
+
166
+ 10 workload group cgroup type file:
167
+ /sys/fs/cgroup/{doris_home}/query/{workload_group_id}/cgroup.type
168
+
169
+ */
170
+ class CgroupV2CpuCtl : public CgroupCpuCtl {
171
+ public:
172
+ CgroupV2CpuCtl (uint64_t tg_id) : CgroupCpuCtl(tg_id) {}
173
+ Status init () override ;
174
+ Status modify_cg_cpu_hard_limit_no_lock (int cpu_hard_limit) override ;
175
+ Status modify_cg_cpu_soft_limit_no_lock (int cpu_shares) override ;
176
+ Status add_thread_to_cgroup () override ;
177
+
178
+ private:
179
+ std::string _cgroup_v2_query_wg_path;
180
+ std::string _cgroup_v2_query_wg_cpu_max_file;
181
+ std::string _cgroup_v2_query_wg_cpu_weight_file;
182
+ std::string _cgroup_v2_query_wg_thread_file;
183
+ std::string _cgroup_v2_query_wg_type_file;
184
+ };
185
+
115
186
} // namespace doris
0 commit comments