src/hotspot/share/gc/g1/g1NUMA.cpp
author sangheki
Wed, 13 Nov 2019 10:49:12 -0800
changeset 59060 fce1fa1bdc91
child 59062 6530de931b8e
permissions -rw-r--r--
8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3) Reviewed-by: kbarrett, sjohanss, tschatzl, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
     1
/*
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
     4
 *
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
     8
 *
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    13
 * accompanied this code).
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    14
 *
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    18
 *
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    21
 * questions.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    22
 *
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    23
 */
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    24
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    25
#include "precompiled.hpp"
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    26
#include "gc/g1/g1NUMA.hpp"
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    27
#include "gc/g1/heapRegion.hpp"
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    28
#include "logging/log.hpp"
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    29
#include "runtime/globals.hpp"
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    30
#include "runtime/os.hpp"
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    31
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    32
G1NUMA* G1NUMA::_inst = NULL;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    33
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    34
size_t G1NUMA::region_size() const {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    35
  assert(_region_size > 0, "Heap region size is not yet set");
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    36
  return _region_size;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    37
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    38
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    39
size_t G1NUMA::page_size() const {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    40
  assert(_page_size > 0, "Page size not is yet set");
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    41
  return _page_size;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    42
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    43
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    44
bool G1NUMA::is_enabled() const { return num_active_nodes() > 1; }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    45
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    46
G1NUMA* G1NUMA::create() {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    47
  guarantee(_inst == NULL, "Should be called once.");
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    48
  _inst = new G1NUMA();
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    49
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    50
  // NUMA only supported on Linux.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    51
#ifdef LINUX
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    52
  _inst->initialize(UseNUMA);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    53
#else
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    54
  _inst->initialize(false);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    55
#endif /* LINUX */
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    56
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    57
  return _inst;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    58
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    59
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    60
  // Returns memory node ids
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    61
const int* G1NUMA::node_ids() const {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    62
  return _node_ids;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    63
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    64
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    65
uint G1NUMA::index_of_node_id(int node_id) const {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    66
  assert(node_id >= 0, "invalid node id %d", node_id);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    67
  assert(node_id < _len_node_id_to_index_map, "invalid node id %d", node_id);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    68
  uint node_index = _node_id_to_index_map[node_id];
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    69
  assert(node_index != G1NUMA::UnknownNodeIndex,
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    70
         "invalid node id %d", node_id);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    71
  return node_index;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    72
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    73
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    74
G1NUMA::G1NUMA() :
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    75
  _node_id_to_index_map(NULL), _len_node_id_to_index_map(0),
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    76
  _node_ids(NULL), _num_active_node_ids(0),
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    77
  _region_size(0), _page_size(0) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    78
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    79
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    80
void G1NUMA::initialize_without_numa() {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    81
  // If NUMA is not enabled or supported, initialize as having a singel node.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    82
  _num_active_node_ids = 1;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    83
  _node_ids = NEW_C_HEAP_ARRAY(int, _num_active_node_ids, mtGC);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    84
  _node_ids[0] = 0;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    85
  // Map index 0 to node 0
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    86
  _len_node_id_to_index_map = 1;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    87
  _node_id_to_index_map = NEW_C_HEAP_ARRAY(uint, _len_node_id_to_index_map, mtGC);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    88
  _node_id_to_index_map[0] = 0;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    89
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    90
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    91
void G1NUMA::initialize(bool use_numa) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    92
  if (!use_numa) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    93
    initialize_without_numa();
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    94
    return;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    95
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    96
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    97
  assert(UseNUMA, "Invariant");
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    98
  size_t num_node_ids = os::numa_get_groups_num();
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
    99
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   100
  // Create an array of active node ids.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   101
  _node_ids = NEW_C_HEAP_ARRAY(int, num_node_ids, mtGC);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   102
  _num_active_node_ids = (uint)os::numa_get_leaf_groups(_node_ids, num_node_ids);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   103
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   104
  int max_node_id = 0;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   105
  for (uint i = 0; i < _num_active_node_ids; i++) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   106
    max_node_id = MAX2(max_node_id, _node_ids[i]);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   107
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   108
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   109
  // Create a mapping between node_id and index.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   110
  _len_node_id_to_index_map = max_node_id + 1;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   111
  _node_id_to_index_map = NEW_C_HEAP_ARRAY(uint, _len_node_id_to_index_map, mtGC);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   112
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   113
  // Set all indices with unknown node id.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   114
  for (int i = 0; i < _len_node_id_to_index_map; i++) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   115
    _node_id_to_index_map[i] = G1NUMA::UnknownNodeIndex;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   116
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   117
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   118
  // Set the indices for the actually retrieved node ids.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   119
  for (uint i = 0; i < _num_active_node_ids; i++) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   120
    _node_id_to_index_map[_node_ids[i]] = i;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   121
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   122
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   123
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   124
G1NUMA::~G1NUMA() {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   125
  FREE_C_HEAP_ARRAY(int, _node_id_to_index_map);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   126
  FREE_C_HEAP_ARRAY(int, _node_ids);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   127
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   128
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   129
void G1NUMA::set_region_info(size_t region_size, size_t page_size) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   130
  _region_size = region_size;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   131
  _page_size = page_size;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   132
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   133
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   134
uint G1NUMA::num_active_nodes() const {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   135
  assert(_num_active_node_ids > 0, "just checking");
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   136
  return _num_active_node_ids;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   137
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   138
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   139
uint G1NUMA::index_of_current_thread() const {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   140
  if (!is_enabled()) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   141
    return 0;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   142
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   143
  return index_of_node_id(os::numa_get_group_id());
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   144
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   145
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   146
uint G1NUMA::preferred_node_index_for_index(uint region_index) const {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   147
  if (region_size() >= page_size()) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   148
    // Simple case, pages are smaller than the region so we
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   149
    // can just alternate over the nodes.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   150
    return region_index % _num_active_node_ids;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   151
  } else {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   152
    // Multiple regions in one page, so we need to make sure the
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   153
    // regions within a page is preferred on the same node.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   154
    size_t regions_per_page = page_size() / region_size();
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   155
    return (region_index / regions_per_page) % _num_active_node_ids;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   156
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   157
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   158
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   159
int G1NUMA::numa_id(int index) const {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   160
  assert(index < _len_node_id_to_index_map, "Index %d out of range: [0,%d)",
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   161
         index, _len_node_id_to_index_map);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   162
  return _node_ids[index];
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   163
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   164
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   165
uint G1NUMA::index_of_address(HeapWord *address) const {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   166
  int numa_id = os::numa_get_group_id_for_address((const void*)address);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   167
  if (numa_id == -1) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   168
    return UnknownNodeIndex;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   169
  } else {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   170
    return index_of_node_id(numa_id);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   171
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   172
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   173
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   174
uint G1NUMA::index_for_region(HeapRegion* hr) const {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   175
  if (!is_enabled()) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   176
    return 0;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   177
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   178
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   179
  if (AlwaysPreTouch) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   180
    // If we already pretouched, we can check actual node index here.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   181
    // However, if node index is still unknown, use preferred node index.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   182
    uint node_index = index_of_address(hr->bottom());
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   183
    if (node_index != UnknownNodeIndex) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   184
      return node_index;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   185
    }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   186
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   187
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   188
  return preferred_node_index_for_index(hr->hrm_index());
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   189
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   190
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   191
// Request to spread the given memory evenly across the available NUMA
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   192
// nodes. Which node to request for a given address is given by the
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   193
// region size and the page size. Below are two examples on 4 NUMA nodes system:
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   194
//   1. G1HeapRegionSize(_region_size) is larger than or equal to page size.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   195
//      * Page #:       |-0--||-1--||-2--||-3--||-4--||-5--||-6--||-7--||-8--||-9--||-10-||-11-||-12-||-13-||-14-||-15-|
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   196
//      * HeapRegion #: |----#0----||----#1----||----#2----||----#3----||----#4----||----#5----||----#6----||----#7----|
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   197
//      * NUMA node #:  |----#0----||----#1----||----#2----||----#3----||----#0----||----#1----||----#2----||----#3----|
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   198
//   2. G1HeapRegionSize(_region_size) is smaller than page size.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   199
//      Memory will be touched one page at a time because G1RegionToSpaceMapper commits
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   200
//      pages one by one.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   201
//      * Page #:       |-----0----||-----1----||-----2----||-----3----||-----4----||-----5----||-----6----||-----7----|
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   202
//      * HeapRegion #: |-#0-||-#1-||-#2-||-#3-||-#4-||-#5-||-#6-||-#7-||-#8-||-#9-||#10-||#11-||#12-||#13-||#14-||#15-|
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   203
//      * NUMA node #:  |----#0----||----#1----||----#2----||----#3----||----#0----||----#1----||----#2----||----#3----|
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   204
void G1NUMA::request_memory_on_node(void* aligned_address, size_t size_in_bytes, uint region_index) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   205
  if (!is_enabled()) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   206
    return;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   207
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   208
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   209
  if (size_in_bytes == 0) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   210
    return;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   211
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   212
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   213
  uint node_index = preferred_node_index_for_index(region_index);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   214
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   215
  assert(is_aligned(aligned_address, page_size()), "Given address (" PTR_FORMAT ") should be aligned.", p2i(aligned_address));
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   216
  assert(is_aligned(size_in_bytes, page_size()), "Given size (" SIZE_FORMAT ") should be aligned.", size_in_bytes);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   217
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   218
  log_debug(gc, heap, numa)("Request memory [" PTR_FORMAT ", " PTR_FORMAT ") to be numa id (%d).",
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   219
                            p2i(aligned_address), p2i((char*)aligned_address + size_in_bytes), _node_ids[node_index]);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   220
  os::numa_make_local((char*)aligned_address, size_in_bytes, _node_ids[node_index]);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   221
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   222
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   223
uint G1NUMA::max_search_depth() const {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   224
  // Multiple of 3 is just random number to limit iterations.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   225
  // There would be some cases that 1 page may be consisted of multiple HeapRegions.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   226
  return 3 * MAX2((uint)(page_size() / region_size()), (uint)1) * num_active_nodes();
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents:
diff changeset
   227
}