Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8264482: container info misleads on non-container environment #3280

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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
@@ -249,7 +249,7 @@ class CgroupSubsystem: public CHeapObj<mtInternal> {
virtual char * cpu_cpuset_cpus() = 0;
virtual char * cpu_cpuset_memory_nodes() = 0;
virtual jlong read_memory_limit_in_bytes() = 0;
virtual const char * container_type() = 0;
virtual const char * resource_controller_type() = 0;
virtual CachingCgroupController* memory_controller() = 0;
virtual CachingCgroupController* cpu_controller() = 0;
};
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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
@@ -87,7 +87,7 @@ class CgroupV1Subsystem: public CgroupSubsystem {

int cpu_shares();

const char * container_type() {
const char * resource_controller_type() {
return "cgroupv1";
}
CachingCgroupController * memory_controller() { return _memory; }
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Red Hat Inc.
* Copyright (c) 2020, 2021, Red Hat Inc.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -79,7 +79,7 @@ class CgroupV2Subsystem: public CgroupSubsystem {
jlong memory_max_usage_in_bytes();
char * cpu_cpuset_cpus();
char * cpu_cpuset_memory_nodes();
const char * container_type() {
const char * resource_controller_type() {
return "cgroupv2";
}
CachingCgroupController * memory_controller() { return _memory; }
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* 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
@@ -70,9 +70,9 @@ void OSContainer::init() {

}

const char * OSContainer::container_type() {
const char * OSContainer::resource_controller_type() {
assert(cgroup_subsystem != NULL, "cgroup subsystem not available");
return cgroup_subsystem->container_type();
return cgroup_subsystem->resource_controller_type();
}

jlong OSContainer::memory_limit_in_bytes() {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* 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
@@ -44,7 +44,7 @@ class OSContainer: AllStatic {
public:
static void init();
static inline bool is_containerized();
static const char * container_type();
static const char * resource_controller_type();

static jlong memory_limit_in_bytes();
static jlong memory_and_swap_limit_in_bytes();
@@ -197,15 +197,18 @@ julong os::Linux::available_memory() {
if (OSContainer::is_containerized()) {
jlong mem_limit, mem_usage;
if ((mem_limit = OSContainer::memory_limit_in_bytes()) < 1) {
log_debug(os, container)("container memory limit %s: " JLONG_FORMAT ", using host value",
log_debug(os, container)("%s memory limit %s: " JLONG_FORMAT ", using host value",
OSContainer::resource_controller_type(),
mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit);
}
if (mem_limit > 0 && (mem_usage = OSContainer::memory_usage_in_bytes()) < 1) {
log_debug(os, container)("container memory usage failed: " JLONG_FORMAT ", using host value", mem_usage);
log_debug(os, container)("%s memory usage failed: " JLONG_FORMAT ", using host value",
OSContainer::resource_controller_type(), mem_usage);
}
if (mem_limit > 0 && mem_usage > 0 ) {
avail_mem = mem_limit > mem_usage ? (julong)mem_limit - (julong)mem_usage : 0;
log_trace(os)("available container memory: " JULONG_FORMAT, avail_mem);
log_trace(os)("available %s memory: " JULONG_FORMAT,
OSContainer::resource_controller_type(), avail_mem);
return avail_mem;
}
}
@@ -221,10 +224,12 @@ julong os::physical_memory() {
if (OSContainer::is_containerized()) {
jlong mem_limit;
if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) {
log_trace(os)("total container memory: " JLONG_FORMAT, mem_limit);
log_trace(os)("total %s memory: " JLONG_FORMAT,
OSContainer::resource_controller_type(), mem_limit);
return mem_limit;
}
log_debug(os, container)("container memory limit %s: " JLONG_FORMAT ", using host value",
log_debug(os, container)("%s memory limit %s: " JLONG_FORMAT ", using host value",
OSContainer::resource_controller_type(),
mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit);
}

@@ -2219,10 +2224,7 @@ bool os::Linux::print_container_info(outputStream* st) {
return false;
}

st->print_cr("container (cgroup) information:");

const char *p_ct = OSContainer::container_type();
st->print_cr("container_type: %s", p_ct != NULL ? p_ct : "not supported");
st->print_cr("%s information:", OSContainer::resource_controller_type());

char *p = OSContainer::cpu_cpuset_cpus();
st->print_cr("cpu_cpuset_cpus: %s", p != NULL ? p : "not supported");
ProTip! Use n and p to navigate between commits in a pull request.