mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8261242: [Linux] OSContainer::is_containerized() returns true when run outside a container
Reviewed-by: stuefe, iklam
This commit is contained in:
parent
71e3798bf6
commit
0a6ffa5795
19 changed files with 290 additions and 64 deletions
|
@ -35,6 +35,11 @@ public class CgroupMetrics implements Metrics {
|
|||
this.subsystem = Objects.requireNonNull(subsystem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContainerized() {
|
||||
return isContainerized0();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProvider() {
|
||||
return subsystem.getProvider();
|
||||
|
@ -194,6 +199,7 @@ public class CgroupMetrics implements Metrics {
|
|||
}
|
||||
|
||||
private static native boolean isUseContainerSupport();
|
||||
private static native boolean isContainerized0();
|
||||
private static native long getTotalMemorySize0();
|
||||
private static native long getTotalSwapSize0();
|
||||
|
||||
|
|
|
@ -31,6 +31,11 @@ package jdk.internal.platform;
|
|||
*/
|
||||
public interface CgroupSubsystem extends Metrics {
|
||||
|
||||
|
||||
default boolean isContainerized() {
|
||||
return false; // This default impl is never used
|
||||
}
|
||||
|
||||
/**
|
||||
* Returned for metrics of type long if the underlying implementation
|
||||
* has determined that no limit is being imposed.
|
||||
|
|
|
@ -36,6 +36,12 @@ Java_jdk_internal_platform_CgroupMetrics_isUseContainerSupport(JNIEnv *env, jcla
|
|||
return JVM_IsUseContainerSupport();
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_jdk_internal_platform_CgroupMetrics_isContainerized0(JNIEnv *env, jclass ignored)
|
||||
{
|
||||
return JVM_IsContainerized();
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_jdk_internal_platform_CgroupMetrics_getTotalMemorySize0
|
||||
(JNIEnv *env, jclass ignored)
|
||||
|
|
|
@ -71,6 +71,23 @@ public interface Metrics {
|
|||
*/
|
||||
public String getProvider();
|
||||
|
||||
/**
|
||||
* Determines whether or not the underlying system
|
||||
* has useful metrics (a.k.a. is containerized).
|
||||
*
|
||||
* @implNote
|
||||
* Note that Metrics on some systems aren't useful.
|
||||
* For example on a regular Linux system with cgroups
|
||||
* present, with no limits enforced and not running in
|
||||
* a container, Metric aren't useful. This can be used
|
||||
* in order to determine if the system is containerized.
|
||||
*
|
||||
* @return true when the JVM runs in containerized mode.
|
||||
* false otherwise.
|
||||
*
|
||||
*/
|
||||
public boolean isContainerized();
|
||||
|
||||
|
||||
/* ***************************************************************
|
||||
* CPU Accounting Subsystem
|
||||
|
|
|
@ -370,6 +370,10 @@ public final class LauncherHelper {
|
|||
final long longRetvalNotSupported = -2;
|
||||
|
||||
ostream.println(INDENT + "Provider: " + c.getProvider());
|
||||
if (!c.isContainerized()) {
|
||||
ostream.println(INDENT + "System not containerized.");
|
||||
return;
|
||||
}
|
||||
ostream.println(INDENT + "Effective CPU Count: " + c.getEffectiveCpuCount());
|
||||
ostream.println(formatCpuVal(c.getCpuPeriod(), INDENT + "CPU Period: ", longRetvalNotSupported));
|
||||
ostream.println(formatCpuVal(c.getCpuQuota(), INDENT + "CPU Quota: ", longRetvalNotSupported));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue