/* * Copyright (c) 2019, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #ifndef SHARE_VM_GC_G1_G1NUMA_HPP #define SHARE_VM_GC_G1_G1NUMA_HPP #include "runtime/globals.hpp" #include "runtime/os.hpp" // Manages NUMA node related information. // Provides a conversion between NUMA indices (sequential, starting // from zero) and NUMA ids (which may not start at zero and may not be // sequential). Indices are generally used by clients, and mapped to // ids when dealing with the OS/hardware layer. class G1NUMA : public CHeapObj { // Mapping of available numa ids to some 0-based index which can be used for // fast resource management. I.e. for every numa id provides a unique value in // the range from [0, {# of numa nodes-1}]. // For invalid numa id, return G1MemoryNodeManager::InvalidNodeIndex. // So the caller need exception handling. uint* _numa_id_to_index_map; // Length of numa_id to index map. int _len_numa_id_to_index_map; // Used to create next numa index which cycles through a range of [0, {# of numa nodes-1}). // This next numa index is used when the given numa index is invalid. volatile uint _next_numa_index; // Necessary when touching memory. size_t _page_size; // Current active numa ids. int* _numa_ids; // Total number of numa ids. uint _num_active_numa_ids; static G1NUMA* _inst; // Creates numa id and numa index mapping table of _numa_id_to_index_map. void init_numa_id_to_index_map(const int* numa_ids, uint num_numa_ids); // Touch the given memory with specific numa index. void touch_memory_whole(address aligned_address, size_t size_in_bytes, uint numa_index); // Touch the given memory with round-robin manner. void touch_memory_roundrobin(address aligned_address, size_t size_in_bytes); public: G1NUMA() : _numa_id_to_index_map(NULL), _len_numa_id_to_index_map(0), _next_numa_index(0), _page_size(0), _numa_ids(NULL), _num_active_numa_ids(0) { } ~G1NUMA(); static G1NUMA* numa() { return _inst; } static void set_numa(G1NUMA* numa) { guarantee(_inst == NULL, "Should be called once."); _inst = numa; } void touch_memory(address aligned_address, size_t size_in_bytes, uint numa_index); bool initialize(); inline bool is_valid_numa_id(int numa_id); inline bool is_valid_numa_index(uint numa_index) const; inline uint num_active_numa_ids() const; // Gets a next valid numa index. inline uint next_numa_index(); // Gets a next valid numa id. inline int next_numa_id(); // Returns numa index of the given numa id. // Returns G1MemoryNodeManager::InvalidNodeIndex if the given numa id is invalid. inline uint index_of_numa_id(int numa_id) const; // Returns numa id of the given numa index. inline int numa_id_of_index(uint numa_index) const; void set_page_size(size_t page_size); // Returns current active numa ids. const int* numa_ids() const { return _numa_ids; } // Returns numa index of the given address via system call. uint index_of_address(HeapWord* addr) const; }; #endif // SHARE_VM_GC_G1_G1NUMA_HPP