mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8266490: Extend the OSContainer API to support the pids controller of cgroups
Reviewed-by: sgehwolf, lucy
This commit is contained in:
parent
2384e12888
commit
089e83bf1b
22 changed files with 527 additions and 79 deletions
|
@ -149,6 +149,11 @@ public class CgroupMetrics implements Metrics {
|
|||
return subsystem.getMemorySoftLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPidsMax() {
|
||||
return subsystem.getPidsMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBlkIOServiceCount() {
|
||||
return subsystem.getBlkIOServiceCount();
|
||||
|
|
|
@ -36,5 +36,13 @@ public interface CgroupSubsystem extends Metrics {
|
|||
* has determined that no limit is being imposed.
|
||||
*/
|
||||
public static final long LONG_RETVAL_UNLIMITED = -1;
|
||||
public static final String MAX_VAL = "max";
|
||||
|
||||
public static long limitFromString(String strVal) {
|
||||
if (strVal == null || MAX_VAL.equals(strVal)) {
|
||||
return CgroupSubsystem.LONG_RETVAL_UNLIMITED;
|
||||
}
|
||||
return Long.parseLong(strVal);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ public class CgroupSubsystemFactory {
|
|||
private static final String CPUSET_CTRL = "cpuset";
|
||||
private static final String BLKIO_CTRL = "blkio";
|
||||
private static final String MEMORY_CTRL = "memory";
|
||||
private static final String PIDS_CTRL = "pids";
|
||||
|
||||
/*
|
||||
* From https://www.kernel.org/doc/Documentation/filesystems/proc.txt
|
||||
|
@ -149,6 +150,7 @@ public class CgroupSubsystemFactory {
|
|||
case CPUSET_CTRL: infos.put(CPUSET_CTRL, info); break;
|
||||
case MEMORY_CTRL: infos.put(MEMORY_CTRL, info); break;
|
||||
case BLKIO_CTRL: infos.put(BLKIO_CTRL, info); break;
|
||||
case PIDS_CTRL: infos.put(PIDS_CTRL, info); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,6 +253,7 @@ public class CgroupSubsystemFactory {
|
|||
case CPUACCT_CTRL:
|
||||
case CPU_CTRL:
|
||||
case BLKIO_CTRL:
|
||||
case PIDS_CTRL:
|
||||
CgroupInfo info = infos.get(cName);
|
||||
info.setCgroupPath(cgroupPath);
|
||||
break;
|
||||
|
@ -302,6 +305,7 @@ public class CgroupSubsystemFactory {
|
|||
case MEMORY_CTRL: // fall-through
|
||||
case CPU_CTRL:
|
||||
case CPUACCT_CTRL:
|
||||
case PIDS_CTRL:
|
||||
case BLKIO_CTRL: {
|
||||
CgroupInfo info = infos.get(controllerName);
|
||||
assert info.getMountPoint() == null;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 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
|
||||
|
@ -38,6 +38,7 @@ public class CgroupV1Subsystem implements CgroupSubsystem, CgroupV1Metrics {
|
|||
private CgroupV1SubsystemController cpuacct;
|
||||
private CgroupV1SubsystemController cpuset;
|
||||
private CgroupV1SubsystemController blkio;
|
||||
private CgroupV1SubsystemController pids;
|
||||
|
||||
private static volatile CgroupV1Subsystem INSTANCE;
|
||||
|
||||
|
@ -126,6 +127,15 @@ public class CgroupV1Subsystem implements CgroupSubsystem, CgroupV1Metrics {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "pids": {
|
||||
if (info.getMountRoot() != null && info.getMountPoint() != null) {
|
||||
CgroupV1SubsystemController controller = new CgroupV1SubsystemController(info.getMountRoot(), info.getMountPoint());
|
||||
controller.setPath(info.getCgroupPath());
|
||||
subsystem.setPidsController(controller);
|
||||
anyActiveControllers = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new AssertionError("Unrecognized controller in infos: " + info.getName());
|
||||
}
|
||||
|
@ -170,6 +180,10 @@ public class CgroupV1Subsystem implements CgroupSubsystem, CgroupV1Metrics {
|
|||
this.blkio = blkio;
|
||||
}
|
||||
|
||||
private void setPidsController(CgroupV1SubsystemController pids) {
|
||||
this.pids = pids;
|
||||
}
|
||||
|
||||
private static long getLongValue(CgroupSubsystemController controller,
|
||||
String parm) {
|
||||
return CgroupSubsystemController.getLongValue(controller,
|
||||
|
@ -394,6 +408,13 @@ public class CgroupV1Subsystem implements CgroupSubsystem, CgroupV1Metrics {
|
|||
return CgroupV1SubsystemController.longValOrUnlimited(getLongValue(memory, "memory.soft_limit_in_bytes"));
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
* pids subsystem
|
||||
****************************************************************/
|
||||
public long getPidsMax() {
|
||||
String pidsMaxStr = CgroupSubsystemController.getStringValue(pids, "pids.max");
|
||||
return CgroupSubsystem.limitFromString(pidsMaxStr);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
* BlKIO Subsystem
|
||||
|
|
|
@ -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
|
||||
|
@ -45,7 +45,6 @@ public class CgroupV2Subsystem implements CgroupSubsystem {
|
|||
private final CgroupSubsystemController unified;
|
||||
private static final String PROVIDER_NAME = "cgroupv2";
|
||||
private static final int PER_CPU_SHARES = 1024;
|
||||
private static final String MAX_VAL = "max";
|
||||
private static final Object EMPTY_STR = "";
|
||||
private static final long NO_SWAP = 0;
|
||||
|
||||
|
@ -149,14 +148,7 @@ public class CgroupV2Subsystem implements CgroupSubsystem {
|
|||
return CgroupSubsystem.LONG_RETVAL_UNLIMITED;
|
||||
}
|
||||
String quota = tokens[tokenIdx];
|
||||
return limitFromString(quota);
|
||||
}
|
||||
|
||||
private long limitFromString(String strVal) {
|
||||
if (strVal == null || MAX_VAL.equals(strVal)) {
|
||||
return CgroupSubsystem.LONG_RETVAL_UNLIMITED;
|
||||
}
|
||||
return Long.parseLong(strVal);
|
||||
return CgroupSubsystem.limitFromString(quota);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -251,7 +243,7 @@ public class CgroupV2Subsystem implements CgroupSubsystem {
|
|||
@Override
|
||||
public long getMemoryLimit() {
|
||||
String strVal = CgroupSubsystemController.getStringValue(unified, "memory.max");
|
||||
return limitFromString(strVal);
|
||||
return CgroupSubsystem.limitFromString(strVal);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -279,7 +271,7 @@ public class CgroupV2Subsystem implements CgroupSubsystem {
|
|||
if (strVal == null) {
|
||||
return getMemoryLimit();
|
||||
}
|
||||
long swapLimit = limitFromString(strVal);
|
||||
long swapLimit = CgroupSubsystem.limitFromString(strVal);
|
||||
if (swapLimit >= 0) {
|
||||
long memoryLimit = getMemoryLimit();
|
||||
assert memoryLimit >= 0;
|
||||
|
@ -310,7 +302,13 @@ public class CgroupV2Subsystem implements CgroupSubsystem {
|
|||
@Override
|
||||
public long getMemorySoftLimit() {
|
||||
String softLimitStr = CgroupSubsystemController.getStringValue(unified, "memory.low");
|
||||
return limitFromString(softLimitStr);
|
||||
return CgroupSubsystem.limitFromString(softLimitStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPidsMax() {
|
||||
String pidsMaxStr = CgroupSubsystemController.getStringValue(unified, "pids.max");
|
||||
return CgroupSubsystem.limitFromString(pidsMaxStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue