From 7ca249ae82c6b6c60c524781806f9d12ef3f8f98 Mon Sep 17 00:00:00 2001 Date: Mon, 16 Mar 2020 16:24:43 +0800 Subject: [PATCH] 8209894: ZGC: Cap number of GC workers based on heap size Summary: : LLT: jdk11u/test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/disableCollection/disablecollection002/TestDescription.java Bug url: https://bugs.openjdk.java.net/browse/JDK-8209894 --- src/hotspot/share/gc/z/zWorkers.cpp | 23 ++++++++++++++++++----- src/hotspot/share/gc/z/zWorkers.hpp | 4 +--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/hotspot/share/gc/z/zWorkers.cpp b/src/hotspot/share/gc/z/zWorkers.cpp index 0686ec7af..6a0c2561d 100644 --- a/src/hotspot/share/gc/z/zWorkers.cpp +++ b/src/hotspot/share/gc/z/zWorkers.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, 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 @@ -22,14 +22,27 @@ */ #include "precompiled.hpp" +#include "gc/z/zGlobals.hpp" #include "gc/z/zTask.hpp" #include "gc/z/zWorkers.inline.hpp" #include "runtime/os.hpp" #include "runtime/mutexLocker.hpp" #include "runtime/safepoint.hpp" -uint ZWorkers::calculate_ncpus(double share_in_percent) { - return ceil(os::initial_active_processor_count() * share_in_percent / 100.0); +static uint calculate_nworkers_based_on_ncpus(double cpu_share_in_percent) { + return ceil(os::initial_active_processor_count() * cpu_share_in_percent / 100.0); +} + +static uint calculate_nworkers_based_on_heap_size(double reserve_share_in_percent) { + const int nworkers = ((MaxHeapSize * (reserve_share_in_percent / 100.0)) - ZPageSizeMedium) / ZPageSizeSmall; + return MAX2(nworkers, 1); +} + +static uint calculate_nworkers(double cpu_share_in_percent) { + // Cap number of workers so that we never use more than 10% of the max heap + // for the reserve. This is useful when using small heaps on large machines. + return MIN2(calculate_nworkers_based_on_ncpus(cpu_share_in_percent), + calculate_nworkers_based_on_heap_size(10.0)); } uint ZWorkers::calculate_nparallel() { @@ -38,7 +51,7 @@ uint ZWorkers::calculate_nparallel() { // close to the number of processors tends to lead to over-provisioning and // scheduling latency issues. Using 60% of the active processors appears to // be a fairly good balance. - return calculate_ncpus(60.0); + return calculate_nworkers(60.0); } uint ZWorkers::calculate_nconcurrent() { @@ -48,7 +61,7 @@ uint ZWorkers::calculate_nconcurrent() { // throughput, while using too few threads will prolong the GC-cycle and // we then risk being out-run by the application. Using 12.5% of the active // processors appears to be a fairly good balance. - return calculate_ncpus(12.5); + return calculate_nworkers(12.5); } class ZWorkersWarmupTask : public ZTask { diff --git a/src/hotspot/share/gc/z/zWorkers.hpp b/src/hotspot/share/gc/z/zWorkers.hpp index 36a3c61fd..6ce09c447 100644 --- a/src/hotspot/share/gc/z/zWorkers.hpp +++ b/src/hotspot/share/gc/z/zWorkers.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, 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 @@ -34,8 +34,6 @@ private: bool _boost; WorkGang _workers; - static uint calculate_ncpus(double share_in_percent); - void run(ZTask* task, uint nworkers); public: -- 2.12.3