[8u] RFR (S) 8227018: CompletableFuture should not call Runtime.availableProcessors on fast path
Bob Vandette
bob.vandette at oracle.com
Mon Jul 1 15:20:16 UTC 2019
This quick patch reduces the performance difference to noise.
This assumes that none of the cpu resource limits change.
Bob.
diff -r e64383344f14 src/hotspot/os/linux/osContainer_linux.cpp
--- a/src/hotspot/os/linux/osContainer_linux.cpp Wed Jun 26 13:18:38 2019 -0400
+++ b/src/hotspot/os/linux/osContainer_linux.cpp Mon Jul 01 15:13:56 2019 +0000
@@ -581,22 +581,36 @@
* return:
* number of CPUs
*/
+static bool cpu_limits_initialized = false;
+static int quota_cache;
+static int period_cache;
+static int share_cache;
+static int last_processor_count;
+static int last_active_cpu_count;
+
int OSContainer::active_processor_count() {
int quota_count = 0, share_count = 0;
- int cpu_count, limit_count;
+ int limit_count;
int result;
- cpu_count = limit_count = os::Linux::active_processor_count();
- int quota = cpu_quota();
- int period = cpu_period();
- int share = cpu_shares();
+ if (cpu_limits_initialized) {
+ int cpu_count = os::Linux::active_processor_count();
+ if (cpu_count == last_active_cpu_count) {
+ return last_processor_count;
+ }
+ }
- if (quota > -1 && period > 0) {
- quota_count = ceilf((float)quota / (float)period);
+ last_active_cpu_count = limit_count = os::Linux::active_processor_count();
+ int quota_cache = cpu_quota();
+ int period_cache = cpu_period();
+ int share_cache = cpu_shares();
+
+ if (quota_cache > -1 && period_cache > 0) {
+ quota_count = ceilf((float)quota_cache / (float)period_cache);
log_trace(os, container)("CPU Quota count based on quota/period: %d", quota_count);
}
- if (share > -1) {
- share_count = ceilf((float)share / (float)PER_CPU_SHARES);
+ if (share_cache > -1) {
+ share_count = ceilf((float)share_cache / (float)PER_CPU_SHARES);
log_trace(os, container)("CPU Share count based on shares: %d", share_count);
}
@@ -616,8 +630,11 @@
limit_count = share_count;
}
- result = MIN2(cpu_count, limit_count);
+ result = MIN2(last_active_cpu_count, limit_count);
log_trace(os, container)("OSContainer::active_processor_count: %d", result);
+
+ last_processor_count = result;
+ cpu_limits_initialized = true;
return result;
}
> On Jul 1, 2019, at 11:08 AM, Aleksey Shipilev <shade at redhat.com> wrote:
>
> RFE:
> https://bugs.openjdk.java.net/browse/JDK-8227018
>
> 8u webrev:
> http://cr.openjdk.java.net/~shade/8227018/webrev.01/
>
> In 8u, CompletableFuture calls Runtime.availableProcessors during spin in waitingGet. Unfortunately,
> that falls victim to JDK-8227006, which makes it too costly. This is fixed in 9 with JDK-8134851,
> but that patch is too large and intrusive to backport to 8u. Therefore, we should consider
> backporting the small part of that patch that deals with availableProcessors handling.
>
> Testing: "tier1"-like testing
>
> --
> Thanks,
> -Aleksey
>
More information about the jdk8u-dev
mailing list