Skip to content

Commit 80ef9d5

Browse files
committedNov 20, 2019
8234361: ZGC: Move heuristics code in ZWorker to ZHeuristics
Reviewed-by: eosterlund, stefank
1 parent 544ce96 commit 80ef9d5

File tree

5 files changed

+42
-43
lines changed

5 files changed

+42
-43
lines changed
 

‎src/hotspot/share/gc/z/zArguments.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "gc/z/zAddressSpaceLimit.hpp"
2626
#include "gc/z/zArguments.hpp"
2727
#include "gc/z/zCollectedHeap.hpp"
28-
#include "gc/z/zWorkers.hpp"
28+
#include "gc/z/zHeuristics.hpp"
2929
#include "gc/shared/gcArguments.hpp"
3030
#include "runtime/globals.hpp"
3131
#include "runtime/globals_extension.hpp"
@@ -59,7 +59,7 @@ void ZArguments::initialize() {
5959

6060
// Select number of parallel threads
6161
if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
62-
FLAG_SET_DEFAULT(ParallelGCThreads, ZWorkers::calculate_nparallel());
62+
FLAG_SET_DEFAULT(ParallelGCThreads, ZHeuristics::nparallel_workers());
6363
}
6464

6565
if (ParallelGCThreads == 0) {
@@ -68,7 +68,7 @@ void ZArguments::initialize() {
6868

6969
// Select number of concurrent threads
7070
if (FLAG_IS_DEFAULT(ConcGCThreads)) {
71-
FLAG_SET_DEFAULT(ConcGCThreads, ZWorkers::calculate_nconcurrent());
71+
FLAG_SET_DEFAULT(ConcGCThreads, ZHeuristics::nconcurrent_workers());
7272
}
7373

7474
if (ConcGCThreads == 0) {

‎src/hotspot/share/gc/z/zHeuristics.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,39 @@ bool ZHeuristics::use_per_cpu_shared_small_pages() {
6262
const size_t per_cpu_share = (MaxHeapSize * 0.03125) / ZCPU::count();
6363
return per_cpu_share >= ZPageSizeSmall;
6464
}
65+
66+
static uint nworkers_based_on_ncpus(double cpu_share_in_percent) {
67+
return ceil(os::initial_active_processor_count() * cpu_share_in_percent / 100.0);
68+
}
69+
70+
static uint nworkers_based_on_heap_size(double reserve_share_in_percent) {
71+
const int nworkers = (MaxHeapSize * (reserve_share_in_percent / 100.0)) / ZPageSizeSmall;
72+
return MAX2(nworkers, 1);
73+
}
74+
75+
static uint nworkers(double cpu_share_in_percent) {
76+
// Cap number of workers so that we don't use more than 2% of the max heap
77+
// for the small page reserve. This is useful when using small heaps on
78+
// large machines.
79+
return MIN2(nworkers_based_on_ncpus(cpu_share_in_percent),
80+
nworkers_based_on_heap_size(2.0));
81+
}
82+
83+
uint ZHeuristics::nparallel_workers() {
84+
// Use 60% of the CPUs, rounded up. We would like to use as many threads as
85+
// possible to increase parallelism. However, using a thread count that is
86+
// close to the number of processors tends to lead to over-provisioning and
87+
// scheduling latency issues. Using 60% of the active processors appears to
88+
// be a fairly good balance.
89+
return nworkers(60.0);
90+
}
91+
92+
uint ZHeuristics::nconcurrent_workers() {
93+
// Use 12.5% of the CPUs, rounded up. The number of concurrent threads we
94+
// would like to use heavily depends on the type of workload we are running.
95+
// Using too many threads will have a negative impact on the application
96+
// throughput, while using too few threads will prolong the GC-cycle and
97+
// we then risk being out-run by the application. Using 12.5% of the active
98+
// processors appears to be a fairly good balance.
99+
return nworkers(12.5);
100+
}

‎src/hotspot/share/gc/z/zHeuristics.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class ZHeuristics : public AllStatic {
3131
static void set_medium_page_size();
3232

3333
static bool use_per_cpu_shared_small_pages();
34+
35+
static uint nparallel_workers();
36+
static uint nconcurrent_workers();
3437
};
3538

3639
#endif // SHARE_GC_Z_ZHEURISTICS_HPP

‎src/hotspot/share/gc/z/zWorkers.cpp

-37
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,9 @@
2626
#include "gc/z/zTask.hpp"
2727
#include "gc/z/zThread.hpp"
2828
#include "gc/z/zWorkers.inline.hpp"
29-
#include "runtime/os.hpp"
3029
#include "runtime/mutexLocker.hpp"
3130
#include "runtime/safepoint.hpp"
3231

33-
static uint calculate_nworkers_based_on_ncpus(double cpu_share_in_percent) {
34-
return ceil(os::initial_active_processor_count() * cpu_share_in_percent / 100.0);
35-
}
36-
37-
static uint calculate_nworkers_based_on_heap_size(double reserve_share_in_percent) {
38-
const int nworkers = (MaxHeapSize * (reserve_share_in_percent / 100.0)) / ZPageSizeSmall;
39-
return MAX2(nworkers, 1);
40-
}
41-
42-
static uint calculate_nworkers(double cpu_share_in_percent) {
43-
// Cap number of workers so that we don't use more than 2% of the max heap
44-
// for the small page reserve. This is useful when using small heaps on
45-
// large machines.
46-
return MIN2(calculate_nworkers_based_on_ncpus(cpu_share_in_percent),
47-
calculate_nworkers_based_on_heap_size(2.0));
48-
}
49-
50-
uint ZWorkers::calculate_nparallel() {
51-
// Use 60% of the CPUs, rounded up. We would like to use as many threads as
52-
// possible to increase parallelism. However, using a thread count that is
53-
// close to the number of processors tends to lead to over-provisioning and
54-
// scheduling latency issues. Using 60% of the active processors appears to
55-
// be a fairly good balance.
56-
return calculate_nworkers(60.0);
57-
}
58-
59-
uint ZWorkers::calculate_nconcurrent() {
60-
// Use 12.5% of the CPUs, rounded up. The number of concurrent threads we
61-
// would like to use heavily depends on the type of workload we are running.
62-
// Using too many threads will have a negative impact on the application
63-
// throughput, while using too few threads will prolong the GC-cycle and
64-
// we then risk being out-run by the application. Using 12.5% of the active
65-
// processors appears to be a fairly good balance.
66-
return calculate_nworkers(12.5);
67-
}
68-
6932
class ZWorkersInitializeTask : public ZTask {
7033
private:
7134
const uint _nworkers;

‎src/hotspot/share/gc/z/zWorkers.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ class ZWorkers {
3737
void run(ZTask* task, uint nworkers);
3838

3939
public:
40-
static uint calculate_nparallel();
41-
static uint calculate_nconcurrent();
42-
4340
ZWorkers();
4441

4542
uint nparallel() const;

0 commit comments

Comments
 (0)
Please sign in to comment.