Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
8231111: Cgroups v2: Rework Metrics in java.base so as to recognize u…
…nified hierarchy 8275713: TestDockerMemoryMetrics test fails on recent runc 8228585: jdk/internal/platform/cgroup/TestCgroupMetrics.java - NumberFormatException because of large long values (memory limit_in_bytes) Reviewed-by: sgehwolf, andrew Backport-of: 4def210a22faaec6b47912dd314e6365ea48d28f
- Loading branch information
Jonathan Dowland
committed
Dec 5, 2022
1 parent
5510145
commit c9007cd
Showing
31 changed files
with
3,328 additions
and
1,289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
jdk/src/linux/classes/jdk/internal/platform/CgroupInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */); | ||
} | ||
|
||
} |
172 changes: 172 additions & 0 deletions
172
jdk/src/linux/classes/jdk/internal/platform/CgroupMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/* | ||
* 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() { | ||
if (!isUseContainerSupport()) { | ||
// Return null on -XX:-UseContainerSupport | ||
return null; | ||
} | ||
return CgroupSubsystemFactory.create(); | ||
} | ||
|
||
private static native boolean isUseContainerSupport(); | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
jdk/src/linux/classes/jdk/internal/platform/CgroupSubsystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
Oops, something went wrong.
c9007cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues