Skip to content
Permalink
Browse files

8231111: Cgroups v2: Rework Metrics in java.base so as to recognize u…

…nified hierarchy

Reviewed-by: bobv, mchung
  • Loading branch information
jerboaa committed Dec 16, 2019
1 parent 8827df9 commit 4def210a22faaec6b47912dd314e6365ea48d28f
Showing with 3,284 additions and 1,279 deletions.
  1. +70 −0 src/java.base/linux/classes/jdk/internal/platform/CgroupInfo.java
  2. +166 −0 src/java.base/linux/classes/jdk/internal/platform/CgroupMetrics.java
  3. +40 −0 src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystem.java
  4. +253 −0 src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemController.java
  5. +101 −0 src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemFactory.java
  6. +83 −0 src/java.base/linux/classes/jdk/internal/platform/CgroupUtil.java
  7. +168 −0 src/java.base/linux/classes/jdk/internal/platform/CgroupV1Metrics.java
  8. +106 −0 src/java.base/linux/classes/jdk/internal/platform/CgroupV1MetricsImpl.java
  9. +44 −0 src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1MemorySubSystemController.java
  10. +118 −147 src/java.base/linux/classes/jdk/internal/platform/cgroupv1/{Metrics.java → CgroupV1Subsystem.java}
  11. +118 −0 src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1SubsystemController.java
  12. +0 −283 src/java.base/linux/classes/jdk/internal/platform/cgroupv1/SubSystem.java
  13. +363 −0 src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java
  14. +58 −0 src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2SubsystemController.java
  15. +52 −174 src/java.base/share/classes/jdk/internal/platform/Metrics.java
  16. +79 −59 src/java.base/share/classes/sun/launcher/LauncherHelper.java
  17. +1 −1 src/jdk.management/unix/classes/com/sun/management/internal/OperatingSystemImpl.java
  18. +1 −8 test/jdk/jdk/internal/platform/cgroup/TestCgroupMetrics.java
  19. +218 −0 test/jdk/jdk/internal/platform/cgroup/TestCgroupSubsystemController.java
  20. +5 −0 test/jdk/jdk/internal/platform/docker/MetricsCpuTester.java
  21. +35 −11 test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java
  22. +3 −3 test/jdk/jdk/internal/platform/docker/TestDockerCpuMetrics.java
  23. +21 −6 test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetrics.java
  24. +2 −2 test/lib/jdk/test/lib/containers/cgroup/CPUSetsReader.java
  25. +111 −0 test/lib/jdk/test/lib/containers/cgroup/CgroupMetricsTester.java
  26. +34 −585 test/lib/jdk/test/lib/containers/cgroup/MetricsTester.java
  27. +566 −0 test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java
  28. +468 −0 test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2020, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/

package jdk.internal.platform;

/**
* Data structure to hold info from /proc/self/cgroup
*
* man 7 cgroups
*
* @see CgroupSubsystemFactory
*/
class CgroupInfo {

private final String name;
private final int hierarchyId;
private final boolean enabled;

private CgroupInfo(String name, int hierarchyId, boolean enabled) {
this.name = name;
this.hierarchyId = hierarchyId;
this.enabled = enabled;
}

String getName() {
return name;
}

int getHierarchyId() {
return hierarchyId;
}

boolean isEnabled() {
return enabled;
}

static CgroupInfo fromCgroupsLine(String line) {
String[] tokens = line.split("\\s+");
if (tokens.length != 4) {
return null;
}
// discard 3'rd field, num_cgroups
return new CgroupInfo(tokens[0] /* name */,
Integer.parseInt(tokens[1]) /* hierarchyId */,
(Integer.parseInt(tokens[3]) == 1) /* enabled */);
}

}
@@ -0,0 +1,166 @@
/*
* Copyright (c) 2020, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/

package jdk.internal.platform;

import java.util.Objects;

public class CgroupMetrics implements Metrics {

private final CgroupSubsystem subsystem;

CgroupMetrics(CgroupSubsystem subsystem) {
this.subsystem = Objects.requireNonNull(subsystem);
}

@Override
public String getProvider() {
return subsystem.getProvider();
}

@Override
public long getCpuUsage() {
return subsystem.getCpuUsage();
}

@Override
public long[] getPerCpuUsage() {
return subsystem.getPerCpuUsage();
}

@Override
public long getCpuUserUsage() {
return subsystem.getCpuUserUsage();
}

@Override
public long getCpuSystemUsage() {
return subsystem.getCpuSystemUsage();
}

@Override
public long getCpuPeriod() {
return subsystem.getCpuPeriod();
}

@Override
public long getCpuQuota() {
return subsystem.getCpuQuota();
}

@Override
public long getCpuShares() {
return subsystem.getCpuShares();
}

@Override
public long getCpuNumPeriods() {
return subsystem.getCpuNumPeriods();
}

@Override
public long getCpuNumThrottled() {
return subsystem.getCpuNumThrottled();
}

@Override
public long getCpuThrottledTime() {
return subsystem.getCpuThrottledTime();
}

@Override
public long getEffectiveCpuCount() {
return subsystem.getEffectiveCpuCount();
}

@Override
public int[] getCpuSetCpus() {
return subsystem.getCpuSetCpus();
}

@Override
public int[] getEffectiveCpuSetCpus() {
return subsystem.getEffectiveCpuSetCpus();
}

@Override
public int[] getCpuSetMems() {
return subsystem.getCpuSetMems();
}

@Override
public int[] getEffectiveCpuSetMems() {
return subsystem.getEffectiveCpuSetMems();
}

public long getMemoryFailCount() {
return subsystem.getMemoryFailCount();
}

@Override
public long getMemoryLimit() {
return subsystem.getMemoryLimit();
}

@Override
public long getMemoryUsage() {
return subsystem.getMemoryUsage();
}

@Override
public long getTcpMemoryUsage() {
return subsystem.getTcpMemoryUsage();
}

@Override
public long getMemoryAndSwapLimit() {
return subsystem.getMemoryAndSwapLimit();
}

@Override
public long getMemoryAndSwapUsage() {
return subsystem.getMemoryAndSwapUsage();
}

@Override
public long getMemorySoftLimit() {
return subsystem.getMemorySoftLimit();
}

@Override
public long getBlkIOServiceCount() {
return subsystem.getBlkIOServiceCount();
}

@Override
public long getBlkIOServiced() {
return subsystem.getBlkIOServiced();
}

public static Metrics getInstance() {
return CgroupSubsystemFactory.create();
}

}
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2020, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/

package jdk.internal.platform;

/**
* Marker interface for cgroup-based metrics
*
*/
public interface CgroupSubsystem extends Metrics {

/**
* Returned for metrics of type long if the underlying implementation
* has determined that no limit is being imposed.
*/
public static final long LONG_RETVAL_UNLIMITED = -1;

}

0 comments on commit 4def210

Please sign in to comment.