28
28
#include " runtime/os.hpp"
29
29
#include " memory/allocation.hpp"
30
30
#include " cgroupSubsystem_linux.hpp"
31
+ #include " cgroupUtil_linux.hpp"
31
32
32
33
// Cgroups version 1 specific implementation
33
34
34
35
class CgroupV1Controller : public CgroupController {
35
36
private:
36
37
/* mountinfo contents */
37
38
char * _root;
38
- char * _mount_point;
39
39
bool _read_only;
40
40
41
41
/* Constructed subsystem directory */
@@ -45,24 +45,27 @@ class CgroupV1Controller: public CgroupController {
45
45
CgroupV1Controller (char *root,
46
46
char *mountpoint,
47
47
bool ro) : _root(os::strdup(root)),
48
- _mount_point (os::strdup(mountpoint)),
49
48
_read_only (ro),
50
49
_path(nullptr ) {
50
+ _cgroup_path = nullptr ;
51
+ _mount_point = os::strdup (mountpoint);
51
52
}
52
53
// Shallow copy constructor
53
54
CgroupV1Controller (const CgroupV1Controller& o) : _root(o._root),
54
- _mount_point(o._mount_point),
55
55
_read_only(o._read_only),
56
56
_path(o._path) {
57
+ _cgroup_path = o._cgroup_path ;
58
+ _mount_point = o._mount_point ;
57
59
}
58
60
~CgroupV1Controller () {
59
61
// At least one subsystem controller exists with paths to malloc'd path
60
62
// names
61
63
}
62
64
63
- void set_subsystem_path (char *cgroup_path);
64
- char * subsystem_path () override { return _path; }
65
+ void set_subsystem_path (const char *cgroup_path);
66
+ const char * subsystem_path () override { return _path; }
65
67
bool is_read_only () override { return _read_only; }
68
+ bool needs_hierarchy_adjustment () override ;
66
69
};
67
70
68
71
class CgroupV1MemoryController final : public CgroupMemoryController {
@@ -71,8 +74,9 @@ class CgroupV1MemoryController final : public CgroupMemoryController {
71
74
CgroupV1Controller _reader;
72
75
CgroupV1Controller* reader () { return &_reader; }
73
76
public:
74
- bool is_hierarchical () { return _uses_mem_hierarchy; }
75
- void set_subsystem_path (char *cgroup_path);
77
+ void set_subsystem_path (const char *cgroup_path) override {
78
+ reader ()->set_subsystem_path (cgroup_path);
79
+ }
76
80
jlong read_memory_limit_in_bytes (julong upper_bound) override ;
77
81
jlong memory_usage_in_bytes () override ;
78
82
jlong memory_and_swap_limit_in_bytes (julong host_mem, julong host_swap) override ;
@@ -85,23 +89,22 @@ class CgroupV1MemoryController final : public CgroupMemoryController {
85
89
jlong kernel_memory_limit_in_bytes (julong host_mem);
86
90
jlong kernel_memory_max_usage_in_bytes ();
87
91
void print_version_specific_info (outputStream* st, julong host_mem) override ;
92
+ bool needs_hierarchy_adjustment () override {
93
+ return reader ()->needs_hierarchy_adjustment ();
94
+ }
88
95
bool is_read_only () override {
89
96
return reader ()->is_read_only ();
90
97
}
98
+ const char * subsystem_path () override { return reader ()->subsystem_path (); }
99
+ const char * mount_point () override { return reader ()->mount_point (); }
100
+ const char * cgroup_path () override { return reader ()->cgroup_path (); }
91
101
private:
92
- /* Some container runtimes set limits via cgroup
93
- * hierarchy. If set to true consider also memory.stat
94
- * file if everything else seems unlimited */
95
- bool _uses_mem_hierarchy;
96
- jlong uses_mem_hierarchy ();
97
- void set_hierarchical (bool value) { _uses_mem_hierarchy = value; }
98
102
jlong read_mem_swappiness ();
99
103
jlong read_mem_swap (julong host_total_memsw);
100
104
101
105
public:
102
106
CgroupV1MemoryController (const CgroupV1Controller& reader)
103
- : _reader(reader),
104
- _uses_mem_hierarchy (false ) {
107
+ : _reader(reader) {
105
108
}
106
109
107
110
};
@@ -115,12 +118,22 @@ class CgroupV1CpuController final : public CgroupCpuController {
115
118
int cpu_quota () override ;
116
119
int cpu_period () override ;
117
120
int cpu_shares () override ;
118
- void set_subsystem_path (char *cgroup_path) {
121
+ void set_subsystem_path (const char *cgroup_path) override {
119
122
reader ()->set_subsystem_path (cgroup_path);
120
123
}
121
124
bool is_read_only () override {
122
125
return reader ()->is_read_only ();
123
126
}
127
+ const char * subsystem_path () override {
128
+ return reader ()->subsystem_path ();
129
+ }
130
+ const char * mount_point () override {
131
+ return reader ()->mount_point ();
132
+ }
133
+ bool needs_hierarchy_adjustment () override {
134
+ return reader ()->needs_hierarchy_adjustment ();
135
+ }
136
+ const char * cgroup_path () override { return reader ()->cgroup_path (); }
124
137
125
138
public:
126
139
CgroupV1CpuController (const CgroupV1Controller& reader) : _reader(reader) {
@@ -130,6 +143,12 @@ class CgroupV1CpuController final : public CgroupCpuController {
130
143
class CgroupV1Subsystem : public CgroupSubsystem {
131
144
132
145
public:
146
+ CgroupV1Subsystem (CgroupV1Controller* cpuset,
147
+ CgroupV1CpuController* cpu,
148
+ CgroupV1Controller* cpuacct,
149
+ CgroupV1Controller* pids,
150
+ CgroupV1MemoryController* memory);
151
+
133
152
jlong kernel_memory_usage_in_bytes ();
134
153
jlong kernel_memory_limit_in_bytes ();
135
154
jlong kernel_memory_max_usage_in_bytes ();
@@ -155,18 +174,6 @@ class CgroupV1Subsystem: public CgroupSubsystem {
155
174
CgroupV1Controller* _cpuacct = nullptr ;
156
175
CgroupV1Controller* _pids = nullptr ;
157
176
158
- public:
159
- CgroupV1Subsystem (CgroupV1Controller* cpuset,
160
- CgroupV1CpuController* cpu,
161
- CgroupV1Controller* cpuacct,
162
- CgroupV1Controller* pids,
163
- CgroupV1MemoryController* memory) :
164
- _memory (new CachingCgroupController<CgroupMemoryController>(memory)),
165
- _cpuset (cpuset),
166
- _cpu (new CachingCgroupController<CgroupCpuController>(cpu)),
167
- _cpuacct (cpuacct),
168
- _pids (pids) {
169
- }
170
177
};
171
178
172
179
#endif // CGROUP_V1_SUBSYSTEM_LINUX_HPP
0 commit comments