9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 #include "precompiled.hpp" 25 #include "gc/z/zGlobals.hpp" 26 #include "gc/z/zTask.hpp" 27 #include "gc/z/zThread.hpp" 28 #include "gc/z/zWorkers.inline.hpp" 29 #include "runtime/os.hpp" 30 #include "runtime/mutexLocker.hpp" 31 #include "runtime/safepoint.hpp" 32 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 69 class ZWorkersInitializeTask : public ZTask { 70 private: 71 const uint _nworkers; 72 uint _started; 73 Monitor _monitor; 74 75 public: 76 ZWorkersInitializeTask(uint nworkers) : 77 ZTask("ZWorkersInitializeTask"), 78 _nworkers(nworkers), 79 _started(0), 80 _monitor(Monitor::leaf, 81 "ZWorkersInitialize", 82 false /* allow_vm_block */, 83 Monitor::_safepoint_check_never) {} 84 85 virtual void work() { 86 // Register as worker 87 ZThread::set_worker(); | 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 #include "precompiled.hpp" 25 #include "gc/z/zGlobals.hpp" 26 #include "gc/z/zTask.hpp" 27 #include "gc/z/zThread.hpp" 28 #include "gc/z/zWorkers.inline.hpp" 29 #include "runtime/mutexLocker.hpp" 30 #include "runtime/safepoint.hpp" 31 32 class ZWorkersInitializeTask : public ZTask { 33 private: 34 const uint _nworkers; 35 uint _started; 36 Monitor _monitor; 37 38 public: 39 ZWorkersInitializeTask(uint nworkers) : 40 ZTask("ZWorkersInitializeTask"), 41 _nworkers(nworkers), 42 _started(0), 43 _monitor(Monitor::leaf, 44 "ZWorkersInitialize", 45 false /* allow_vm_block */, 46 Monitor::_safepoint_check_never) {} 47 48 virtual void work() { 49 // Register as worker 50 ZThread::set_worker(); |