Skip to content

Commit 346d749

Browse files
committed
8313083: Print 'rss' and 'cache' as part of the container information
Reviewed-by: mdoerr Backport-of: c96cbe481c86800b76e220374b24b6671984adb7
1 parent ad137d1 commit 346d749

File tree

9 files changed

+69
-1
lines changed

9 files changed

+69
-1
lines changed

src/hotspot/os/linux/cgroupSubsystem_linux.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ class CgroupSubsystem: public CHeapObj<mtInternal> {
208208
virtual jlong memory_and_swap_limit_in_bytes() = 0;
209209
virtual jlong memory_soft_limit_in_bytes() = 0;
210210
virtual jlong memory_max_usage_in_bytes() = 0;
211+
virtual jlong rss_usage_in_bytes() = 0;
212+
virtual jlong cache_usage_in_bytes() = 0;
211213

212214
virtual char * cpu_cpuset_cpus() = 0;
213215
virtual char * cpu_cpuset_memory_nodes() = 0;

src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,30 @@ jlong CgroupV1Subsystem::memory_max_usage_in_bytes() {
232232
return (jlong)memmaxusage;
233233
}
234234

235+
jlong CgroupV1Subsystem::rss_usage_in_bytes() {
236+
julong rss;
237+
bool is_ok = _memory->controller()->read_numerical_key_value("/memory.stat",
238+
"rss",
239+
&rss);
240+
if (!is_ok) {
241+
return OSCONTAINER_ERROR;
242+
}
243+
log_trace(os, container)("RSS usage is: " JULONG_FORMAT, rss);
244+
return (jlong)rss;
245+
}
246+
247+
jlong CgroupV1Subsystem::cache_usage_in_bytes() {
248+
julong cache;
249+
bool is_ok = _memory->controller()->read_numerical_key_value("/memory.stat",
250+
"cache",
251+
&cache);
252+
if (!is_ok) {
253+
return OSCONTAINER_ERROR;
254+
}
255+
log_trace(os, container)("Cache usage is: " JULONG_FORMAT, cache);
256+
return (jlong)cache;
257+
}
258+
235259
jlong CgroupV1Subsystem::kernel_memory_usage_in_bytes() {
236260
julong kmem_usage;
237261
CONTAINER_READ_NUMBER_CHECKED(_memory->controller(), "/memory.kmem.usage_in_bytes", "Kernel Memory Usage", kmem_usage);

src/hotspot/os/linux/cgroupV1Subsystem_linux.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class CgroupV1Subsystem: public CgroupSubsystem {
7979
jlong memory_soft_limit_in_bytes();
8080
jlong memory_usage_in_bytes();
8181
jlong memory_max_usage_in_bytes();
82+
jlong rss_usage_in_bytes();
83+
jlong cache_usage_in_bytes();
8284

8385
jlong kernel_memory_usage_in_bytes();
8486
jlong kernel_memory_limit_in_bytes();

src/hotspot/os/linux/cgroupV2Subsystem_linux.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,28 @@ jlong CgroupV2Subsystem::memory_max_usage_in_bytes() {
145145
return OSCONTAINER_ERROR; // not supported
146146
}
147147

148+
jlong CgroupV2Subsystem::rss_usage_in_bytes() {
149+
julong rss;
150+
bool is_ok = _memory->controller()->
151+
read_numerical_key_value("/memory.stat", "anon", &rss);
152+
if (!is_ok) {
153+
return OSCONTAINER_ERROR;
154+
}
155+
log_trace(os, container)("RSS usage is: " JULONG_FORMAT, rss);
156+
return (jlong)rss;
157+
}
158+
159+
jlong CgroupV2Subsystem::cache_usage_in_bytes() {
160+
julong cache;
161+
bool is_ok = _memory->controller()->
162+
read_numerical_key_value("/memory.stat", "file", &cache);
163+
if (!is_ok) {
164+
return OSCONTAINER_ERROR;
165+
}
166+
log_trace(os, container)("Cache usage is: " JULONG_FORMAT, cache);
167+
return (jlong)cache;
168+
}
169+
148170
// Note that for cgroups v2 the actual limits set for swap and
149171
// memory live in two different files, memory.swap.max and memory.max
150172
// respectively. In order to properly report a cgroup v1 like

src/hotspot/os/linux/cgroupV2Subsystem_linux.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class CgroupV2Subsystem: public CgroupSubsystem {
7474
jlong memory_soft_limit_in_bytes();
7575
jlong memory_usage_in_bytes();
7676
jlong memory_max_usage_in_bytes();
77+
jlong rss_usage_in_bytes();
78+
jlong cache_usage_in_bytes();
7779

7880
char * cpu_cpuset_cpus();
7981
char * cpu_cpuset_memory_nodes();

src/hotspot/os/linux/osContainer_linux.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ jlong OSContainer::memory_max_usage_in_bytes() {
9292
return cgroup_subsystem->memory_max_usage_in_bytes();
9393
}
9494

95+
jlong OSContainer::rss_usage_in_bytes() {
96+
assert(cgroup_subsystem != nullptr, "cgroup subsystem not available");
97+
return cgroup_subsystem->rss_usage_in_bytes();
98+
}
99+
100+
jlong OSContainer::cache_usage_in_bytes() {
101+
assert(cgroup_subsystem != nullptr, "cgroup subsystem not available");
102+
return cgroup_subsystem->cache_usage_in_bytes();
103+
}
104+
95105
void OSContainer::print_version_specific_info(outputStream* st) {
96106
assert(cgroup_subsystem != nullptr, "cgroup subsystem not available");
97107
cgroup_subsystem->print_version_specific_info(st);

src/hotspot/os/linux/osContainer_linux.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class OSContainer: AllStatic {
5555
static jlong memory_soft_limit_in_bytes();
5656
static jlong memory_usage_in_bytes();
5757
static jlong memory_max_usage_in_bytes();
58+
static jlong rss_usage_in_bytes();
59+
static jlong cache_usage_in_bytes();
5860

5961
static int active_processor_count();
6062

src/hotspot/os/linux/os_linux.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,8 @@ bool os::Linux::print_container_info(outputStream* st) {
23802380
OSContainer::print_container_helper(st, OSContainer::memory_soft_limit_in_bytes(), "memory_soft_limit_in_bytes");
23812381
OSContainer::print_container_helper(st, OSContainer::memory_usage_in_bytes(), "memory_usage_in_bytes");
23822382
OSContainer::print_container_helper(st, OSContainer::memory_max_usage_in_bytes(), "memory_max_usage_in_bytes");
2383+
OSContainer::print_container_helper(st, OSContainer::rss_usage_in_bytes(), "rss_usage_in_bytes");
2384+
OSContainer::print_container_helper(st, OSContainer::cache_usage_in_bytes(), "cache_usage_in_bytes");
23832385

23842386
OSContainer::print_version_specific_info(st);
23852387

test/hotspot/jtreg/containers/docker/TestMisc.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ private static void checkContainerInfo(OutputAnalyzer out) throws Exception {
117117
"Maximum Memory Usage",
118118
"memory_max_usage_in_bytes",
119119
"maximum number of tasks",
120-
"current number of tasks"
120+
"current number of tasks",
121+
"rss_usage_in_bytes",
122+
"cache_usage_in_bytes"
121123
};
122124

123125
for (String s : expectedToContain) {

0 commit comments

Comments
 (0)