Skip to content

Commit 7dcfb7e

Browse files
committed
[GR-44245] Obsolete UseContainerCpuShares and PreferContainerQuotaForCPUCount flags.
PullRequest: graal/13857
2 parents 24a9f45 + f3f1631 commit 7dcfb7e

File tree

1 file changed

+5
-65
lines changed

1 file changed

+5
-65
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/Containers.java

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
*/
2525
package com.oracle.svm.core;
2626

27-
import static com.oracle.svm.core.Containers.Options.PreferContainerQuotaForCPUCount;
28-
import static com.oracle.svm.core.Containers.Options.UseContainerCpuShares;
2927
import static com.oracle.svm.core.Containers.Options.UseContainerSupport;
30-
import static com.oracle.svm.core.option.RuntimeOptionKey.RuntimeOptionKeyFlag.RelevantForCompilationIsolates;
3128

3229
import org.graalvm.compiler.options.Option;
3330
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
@@ -40,7 +37,6 @@
4037
import com.oracle.svm.core.feature.InternalFeature;
4138
import com.oracle.svm.core.jdk.Jvm;
4239
import com.oracle.svm.core.option.HostedOptionKey;
43-
import com.oracle.svm.core.option.RuntimeOptionKey;
4440
import com.oracle.svm.core.util.VMError;
4541

4642
/**
@@ -53,45 +49,17 @@ public class Containers {
5349
public static class Options {
5450
@Option(help = "Enable detection and runtime container configuration support.")//
5551
public static final HostedOptionKey<Boolean> UseContainerSupport = new HostedOptionKey<>(true);
56-
57-
@Option(help = "Include CPU shares in the CPU availability calculation.")//
58-
public static final HostedOptionKey<Boolean> UseContainerCpuShares = new HostedOptionKey<>(false);
59-
60-
@Option(help = "Calculate the container CPU availability based on the value of quotas (if set), when true. " +
61-
"Otherwise, use the CPU shares value, provided it is less than quota.")//
62-
public static final RuntimeOptionKey<Boolean> PreferContainerQuotaForCPUCount = new RuntimeOptionKey<>(true, RelevantForCompilationIsolates);
6352
}
6453

6554
/** Sentinel used when the value is unknown. */
6655
public static final int UNKNOWN = -1;
6756

68-
/*-
69-
* PER_CPU_SHARES has been set to 1024 because CPU shares' quota
70-
* is commonly used in cloud frameworks like Kubernetes[1],
71-
* AWS[2] and Mesos[3] in a similar way. They spawn containers with
72-
* --cpu-shares option values scaled by PER_CPU_SHARES. Thus, we do
73-
* the inverse for determining the number of possible available
74-
* CPUs to the JVM inside a container. See JDK-8216366.
75-
*
76-
* [1] https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-cpu
77-
* In particular:
78-
* When using Docker:
79-
* The spec.containers[].resources.requests.cpu is converted to its core value, which is potentially
80-
* fractional, and multiplied by 1024. The greater of this number or 2 is used as the value of the
81-
* --cpu-shares flag in the docker run command.
82-
* [2] https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html
83-
* [3] https://github.com/apache/mesos/blob/3478e344fb77d931f6122980c6e94cd3913c441d/src/docker/docker.cpp#L648
84-
* https://github.com/apache/mesos/blob/3478e344fb77d931f6122980c6e94cd3913c441d/src/slave/containerizer/mesos/isolators/cgroups/constants.hpp#L30
85-
*/
86-
private static final int PER_CPU_SHARES = 1024;
87-
8857
/**
8958
* Calculates an appropriate number of active processors for the VM to use. The calculation is
90-
* based on these three inputs:
59+
* based on these two inputs:
9160
* <ul>
9261
* <li>cpu affinity
9362
* <li>cpu quota & cpu period
94-
* <li>cpu shares
9563
* </ul>
9664
*
9765
* @return number of CPUs
@@ -105,21 +73,12 @@ public static int activeProcessorCount() {
10573
* If user specified a quota (quota != -1), calculate the number of
10674
* required CPUs by dividing quota by period.
10775
*
108-
* If shares are in effect (shares != -1), calculate the number
109-
* of CPUs required for the shares by dividing the share value
110-
* by PER_CPU_SHARES.
111-
*
11276
* All results of division are rounded up to the next whole number.
11377
*
114-
* If neither shares nor quotas have been specified, return the
78+
* If quotas have not been specified, return the
11579
* number of active processors in the system.
11680
*
117-
* If both shares and quotas have been specified, the results are
118-
* based on the flag PreferContainerQuotaForCPUCount. If true,
119-
* return the quota value. If false return the smallest value
120-
* between shares and quotas.
121-
*
122-
* If shares and/or quotas have been specified, the resulting number
81+
* If quotas have been specified, the resulting number
12382
* returned will never exceed the number of active processors.
12483
*/
12584
int cpuCount = Jvm.JVM_ActiveProcessorCount();
@@ -131,33 +90,14 @@ public static int activeProcessorCount() {
13190
long quota = info.getCpuQuota();
13291
long period = info.getCpuPeriod();
13392

134-
/*-
135-
* It's not a good idea to use CPU shares to limit the number
136-
* of CPUs used by the VM. See JDK-8281181.
137-
*/
138-
long shares = UseContainerCpuShares.getValue() ? info.getCpuShares() : -1;
139-
14093
int quotaCount = 0;
14194
if (quota > -1 && period > 0) {
14295
quotaCount = (int) Math.ceil(((double) quota) / period);
14396
}
14497

145-
int shareCount = 0;
146-
if (shares > -1) {
147-
shareCount = (int) Math.ceil(((double) shares) / PER_CPU_SHARES);
148-
}
149-
150-
if (quotaCount != 0 && shareCount != 0) {
151-
/* Both shares and quotas are specified. */
152-
if (PreferContainerQuotaForCPUCount.getValue()) {
153-
limitCount = quotaCount;
154-
} else {
155-
limitCount = Math.min(quotaCount, shareCount);
156-
}
157-
} else if (quotaCount != 0) {
98+
/* Use quotas. */
99+
if (quotaCount != 0) {
158100
limitCount = quotaCount;
159-
} else if (shareCount != 0) {
160-
limitCount = shareCount;
161101
}
162102
}
163103
}

0 commit comments

Comments
 (0)