# HG changeset patch # User pliden # Date 1574242666 -3600 # Node ID 82b2ba888190c9ff7da37d9276cf86edf5c17681 # Parent 3b998574be4b61e87dbaa10612cf09c41531c1a3 8234361: ZGC: Move heuristics code in ZWorker to ZHeuristics Reviewed-by: eosterlund, stefank diff -r 3b998574be4b -r 82b2ba888190 src/hotspot/share/gc/z/zArguments.cpp --- a/src/hotspot/share/gc/z/zArguments.cpp Wed Nov 20 10:37:46 2019 +0100 +++ b/src/hotspot/share/gc/z/zArguments.cpp Wed Nov 20 10:37:46 2019 +0100 @@ -25,7 +25,7 @@ #include "gc/z/zAddressSpaceLimit.hpp" #include "gc/z/zArguments.hpp" #include "gc/z/zCollectedHeap.hpp" -#include "gc/z/zWorkers.hpp" +#include "gc/z/zHeuristics.hpp" #include "gc/shared/gcArguments.hpp" #include "runtime/globals.hpp" #include "runtime/globals_extension.hpp" @@ -59,7 +59,7 @@ // Select number of parallel threads if (FLAG_IS_DEFAULT(ParallelGCThreads)) { - FLAG_SET_DEFAULT(ParallelGCThreads, ZWorkers::calculate_nparallel()); + FLAG_SET_DEFAULT(ParallelGCThreads, ZHeuristics::nparallel_workers()); } if (ParallelGCThreads == 0) { @@ -68,7 +68,7 @@ // Select number of concurrent threads if (FLAG_IS_DEFAULT(ConcGCThreads)) { - FLAG_SET_DEFAULT(ConcGCThreads, ZWorkers::calculate_nconcurrent()); + FLAG_SET_DEFAULT(ConcGCThreads, ZHeuristics::nconcurrent_workers()); } if (ConcGCThreads == 0) { diff -r 3b998574be4b -r 82b2ba888190 src/hotspot/share/gc/z/zHeuristics.cpp --- a/src/hotspot/share/gc/z/zHeuristics.cpp Wed Nov 20 10:37:46 2019 +0100 +++ b/src/hotspot/share/gc/z/zHeuristics.cpp Wed Nov 20 10:37:46 2019 +0100 @@ -62,3 +62,39 @@ const size_t per_cpu_share = (MaxHeapSize * 0.03125) / ZCPU::count(); return per_cpu_share >= ZPageSizeSmall; } + +static uint nworkers_based_on_ncpus(double cpu_share_in_percent) { + return ceil(os::initial_active_processor_count() * cpu_share_in_percent / 100.0); +} + +static uint nworkers_based_on_heap_size(double reserve_share_in_percent) { + const int nworkers = (MaxHeapSize * (reserve_share_in_percent / 100.0)) / ZPageSizeSmall; + return MAX2(nworkers, 1); +} + +static uint nworkers(double cpu_share_in_percent) { + // Cap number of workers so that we don't use more than 2% of the max heap + // for the small page reserve. This is useful when using small heaps on + // large machines. + return MIN2(nworkers_based_on_ncpus(cpu_share_in_percent), + nworkers_based_on_heap_size(2.0)); +} + +uint ZHeuristics::nparallel_workers() { + // Use 60% of the CPUs, rounded up. We would like to use as many threads as + // possible to increase parallelism. However, using a thread count that is + // 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 nworkers(60.0); +} + +uint ZHeuristics::nconcurrent_workers() { + // Use 12.5% of the CPUs, rounded up. The number of concurrent threads we + // would like to use heavily depends on the type of workload we are running. + // Using too many threads will have a negative impact on the application + // 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 nworkers(12.5); +} diff -r 3b998574be4b -r 82b2ba888190 src/hotspot/share/gc/z/zHeuristics.hpp --- a/src/hotspot/share/gc/z/zHeuristics.hpp Wed Nov 20 10:37:46 2019 +0100 +++ b/src/hotspot/share/gc/z/zHeuristics.hpp Wed Nov 20 10:37:46 2019 +0100 @@ -31,6 +31,9 @@ static void set_medium_page_size(); static bool use_per_cpu_shared_small_pages(); + + static uint nparallel_workers(); + static uint nconcurrent_workers(); }; #endif // SHARE_GC_Z_ZHEURISTICS_HPP diff -r 3b998574be4b -r 82b2ba888190 src/hotspot/share/gc/z/zWorkers.cpp --- a/src/hotspot/share/gc/z/zWorkers.cpp Wed Nov 20 10:37:46 2019 +0100 +++ b/src/hotspot/share/gc/z/zWorkers.cpp Wed Nov 20 10:37:46 2019 +0100 @@ -26,46 +26,9 @@ #include "gc/z/zTask.hpp" #include "gc/z/zThread.hpp" #include "gc/z/zWorkers.inline.hpp" -#include "runtime/os.hpp" #include "runtime/mutexLocker.hpp" #include "runtime/safepoint.hpp" -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)) / ZPageSizeSmall; - return MAX2(nworkers, 1); -} - -static uint calculate_nworkers(double cpu_share_in_percent) { - // Cap number of workers so that we don't use more than 2% of the max heap - // for the small page 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(2.0)); -} - -uint ZWorkers::calculate_nparallel() { - // Use 60% of the CPUs, rounded up. We would like to use as many threads as - // possible to increase parallelism. However, using a thread count that is - // 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_nworkers(60.0); -} - -uint ZWorkers::calculate_nconcurrent() { - // Use 12.5% of the CPUs, rounded up. The number of concurrent threads we - // would like to use heavily depends on the type of workload we are running. - // Using too many threads will have a negative impact on the application - // 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_nworkers(12.5); -} - class ZWorkersInitializeTask : public ZTask { private: const uint _nworkers; diff -r 3b998574be4b -r 82b2ba888190 src/hotspot/share/gc/z/zWorkers.hpp --- a/src/hotspot/share/gc/z/zWorkers.hpp Wed Nov 20 10:37:46 2019 +0100 +++ b/src/hotspot/share/gc/z/zWorkers.hpp Wed Nov 20 10:37:46 2019 +0100 @@ -37,9 +37,6 @@ void run(ZTask* task, uint nworkers); public: - static uint calculate_nparallel(); - static uint calculate_nconcurrent(); - ZWorkers(); uint nparallel() const;