forked from openjdk/jdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosContainer_linux.cpp
More file actions
141 lines (117 loc) · 4.55 KB
/
Copy pathosContainer_linux.cpp
File metadata and controls
141 lines (117 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include <string.h>
#include <math.h>
#include <errno.h>
#include "runtime/globals.hpp"
#include "runtime/os.hpp"
#include "logging/log.hpp"
#include "osContainer_linux.hpp"
#include "cgroupSubsystem_linux.hpp"
bool OSContainer::_is_initialized = false;
bool OSContainer::_is_containerized = false;
CgroupSubsystem* cgroup_subsystem;
/* init
*
* Initialize the container support and determine if
* we are running under cgroup control.
*/
void OSContainer::init() {
jlong mem_limit;
assert(!_is_initialized, "Initializing OSContainer more than once");
_is_initialized = true;
_is_containerized = false;
log_trace(os, container)("OSContainer::init: Initializing Container Support");
if (!UseContainerSupport) {
log_trace(os, container)("Container Support not enabled");
return;
}
cgroup_subsystem = CgroupSubsystemFactory::create();
if (cgroup_subsystem == NULL) {
return; // Required subsystem files not found or other error
}
// We need to update the amount of physical memory now that
// cgroup subsystem files have been processed.
if ((mem_limit = cgroup_subsystem->memory_limit_in_bytes()) > 0) {
os::Linux::set_physical_memory(mem_limit);
log_info(os, container)("Memory Limit is: " JLONG_FORMAT, mem_limit);
}
_is_containerized = true;
}
const char * OSContainer::container_type() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->container_type();
}
jlong OSContainer::memory_limit_in_bytes() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->memory_limit_in_bytes();
}
jlong OSContainer::memory_and_swap_limit_in_bytes() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->memory_and_swap_limit_in_bytes();
}
jlong OSContainer::memory_soft_limit_in_bytes() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->memory_soft_limit_in_bytes();
}
jlong OSContainer::memory_usage_in_bytes() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->memory_usage_in_bytes();
}
jlong OSContainer::memory_max_usage_in_bytes() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->memory_max_usage_in_bytes();
}
char * OSContainer::cpu_cpuset_cpus() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->cpu_cpuset_cpus();
}
char * OSContainer::cpu_cpuset_memory_nodes() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->cpu_cpuset_memory_nodes();
}
int OSContainer::active_processor_count() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->active_processor_count();
}
int OSContainer::cpu_quota() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->cpu_quota();
}
int OSContainer::cpu_period() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->cpu_period();
}
int OSContainer::cpu_shares() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->cpu_shares();
}
jlong OSContainer::pids_max() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->pids_max();
}
jlong OSContainer::pids_current() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->pids_current();
}