hotspot/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp
author iveresov
Fri, 09 May 2008 16:34:08 +0400
changeset 391 f889070a8684
parent 388 bcc631c5bbec
child 616 4f2dfc0168e2
permissions -rw-r--r--
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator. Summary: Don't move tops of the chunks in ensure_parsibility(). Handle the situation with Solaris when a machine has a locality group with no memory. Reviewed-by: apetrusenko, jcoomes, ysr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * Copyright 2006-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
# include "incls/_mutableNUMASpace.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
MutableNUMASpace::MutableNUMASpace() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  _lgrp_spaces = new (ResourceObj::C_HEAP) GrowableArray<LGRPSpace*>(0, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  _page_size = os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  _adaptation_cycles = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  _samples_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  update_layout(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
MutableNUMASpace::~MutableNUMASpace() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    delete lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  delete lgrp_spaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
void MutableNUMASpace::mangle_unused_area() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    MutableSpace *s = ls->space();
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    49
    if (!os::numa_has_static_binding()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    50
      HeapWord *top = MAX2((HeapWord*)round_down((intptr_t)s->top(), page_size()), s->bottom());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    51
      if (top < s->end()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    52
        ls->add_invalid_region(MemRegion(top, s->end()));
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    53
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    s->mangle_unused_area();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
// There may be unallocated holes in the middle chunks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// that should be filled with dead objects to ensure parseability.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
void MutableNUMASpace::ensure_parsability() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    MutableSpace *s = ls->space();
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
    65
    if (s->top() < top()) { // For all spaces preceeding the one containing top()
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      if (s->free_in_words() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
        SharedHeap::fill_region_with_object(MemRegion(s->top(), s->end()));
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
    68
        size_t area_touched_words = pointer_delta(s->end(), s->top());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
#ifndef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
        if (!ZapUnusedHeapArea) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
          area_touched_words = MIN2((size_t)align_object_size(typeArrayOopDesc::header_size(T_INT)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
                                    area_touched_words);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
#endif
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    75
        if (!os::numa_has_static_binding()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    76
          MemRegion invalid;
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    77
          HeapWord *crossing_start = (HeapWord*)round_to((intptr_t)s->top(), os::vm_page_size());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    78
          HeapWord *crossing_end = (HeapWord*)round_to((intptr_t)(s->top() + area_touched_words),
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    79
                                                       os::vm_page_size());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    80
          if (crossing_start != crossing_end) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    81
            // If object header crossed a small page boundary we mark the area
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    82
            // as invalid rounding it to a page_size().
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    83
            HeapWord *start = MAX2((HeapWord*)round_down((intptr_t)s->top(), page_size()), s->bottom());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    84
            HeapWord *end = MIN2((HeapWord*)round_to((intptr_t)(s->top() + area_touched_words), page_size()),
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    85
                                 s->end());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    86
            invalid = MemRegion(start, end);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    87
          }
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    88
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    89
          ls->add_invalid_region(invalid);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    } else {
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    93
      if (!os::numa_has_static_binding()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
        MemRegion invalid(s->top(), s->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
        ls->add_invalid_region(invalid);
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    97
#else
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    98
        if (ZapUnusedHeapArea) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    99
          MemRegion invalid(s->top(), s->end());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   100
          ls->add_invalid_region(invalid);
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   101
        } else {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   102
          return;
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   103
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
#endif
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   105
      } else {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   106
          return;
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   107
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
size_t MutableNUMASpace::used_in_words() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  size_t s = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    s += lgrp_spaces()->at(i)->space()->used_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
size_t MutableNUMASpace::free_in_words() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  size_t s = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    s += lgrp_spaces()->at(i)->space()->free_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
size_t MutableNUMASpace::tlab_capacity(Thread *thr) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  guarantee(thr != NULL, "No thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  int lgrp_id = thr->lgrp_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  assert(lgrp_id != -1, "No lgrp_id set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  if (i == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  return lgrp_spaces()->at(i)->space()->capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
size_t MutableNUMASpace::unsafe_max_tlab_alloc(Thread *thr) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  guarantee(thr != NULL, "No thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  int lgrp_id = thr->lgrp_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  assert(lgrp_id != -1, "No lgrp_id set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  if (i == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  return lgrp_spaces()->at(i)->space()->free_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
// Check if the NUMA topology has changed. Add and remove spaces if needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// The update can be forced by setting the force parameter equal to true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
bool MutableNUMASpace::update_layout(bool force) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // Check if the topology had changed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  bool changed = os::numa_topology_changed();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  if (force || changed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    // Compute lgrp intersection. Add/remove spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    int lgrp_limit = (int)os::numa_get_groups_num();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    int *lgrp_ids = NEW_C_HEAP_ARRAY(int, lgrp_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    int lgrp_num = (int)os::numa_get_leaf_groups(lgrp_ids, lgrp_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    assert(lgrp_num > 0, "There should be at least one locality group");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    // Add new spaces for the new nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    for (int i = 0; i < lgrp_num; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      bool found = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      for (int j = 0; j < lgrp_spaces()->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        if (lgrp_spaces()->at(j)->lgrp_id() == lgrp_ids[i]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
          found = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      if (!found) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
        lgrp_spaces()->append(new LGRPSpace(lgrp_ids[i]));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    // Remove spaces for the removed nodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    for (int i = 0; i < lgrp_spaces()->length();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      bool found = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      for (int j = 0; j < lgrp_num; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        if (lgrp_spaces()->at(i)->lgrp_id() == lgrp_ids[j]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
          found = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      if (!found) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
        delete lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
        lgrp_spaces()->remove_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    FREE_C_HEAP_ARRAY(int, lgrp_ids);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    if (changed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      for (JavaThread *thread = Threads::first(); thread; thread = thread->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
        thread->set_lgrp_id(-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
// Bias region towards the first-touching lgrp. Set the right page sizes.
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   206
void MutableNUMASpace::bias_region(MemRegion mr, int lgrp_id) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  HeapWord *start = (HeapWord*)round_to((intptr_t)mr.start(), page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  HeapWord *end = (HeapWord*)round_down((intptr_t)mr.end(), page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  if (end > start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    MemRegion aligned_region(start, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    assert((intptr_t)aligned_region.start()     % page_size() == 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
           (intptr_t)aligned_region.byte_size() % page_size() == 0, "Bad alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    assert(region().contains(aligned_region), "Sanity");
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   214
    // First we tell the OS which page size we want in the given range. The underlying
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   215
    // large page can be broken down if we require small pages.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    os::realign_memory((char*)aligned_region.start(), aligned_region.byte_size(), page_size());
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   217
    // Then we uncommit the pages in the range.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   218
    os::free_memory((char*)aligned_region.start(), aligned_region.byte_size());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   219
    // And make them local/first-touch biased.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   220
    os::numa_make_local((char*)aligned_region.start(), aligned_region.byte_size(), lgrp_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
// Free all pages in the region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
void MutableNUMASpace::free_region(MemRegion mr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  HeapWord *start = (HeapWord*)round_to((intptr_t)mr.start(), page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  HeapWord *end = (HeapWord*)round_down((intptr_t)mr.end(), page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  if (end > start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    MemRegion aligned_region(start, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    assert((intptr_t)aligned_region.start()     % page_size() == 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
           (intptr_t)aligned_region.byte_size() % page_size() == 0, "Bad alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    assert(region().contains(aligned_region), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    os::free_memory((char*)aligned_region.start(), aligned_region.byte_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
// Update space layout. Perform adaptation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
void MutableNUMASpace::update() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  if (update_layout(false)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    // If the topology has changed, make all chunks zero-sized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      MutableSpace *s = lgrp_spaces()->at(i)->space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      s->set_end(s->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      s->set_top(s->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    initialize(region(), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    bool should_initialize = false;
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   249
    if (!os::numa_has_static_binding()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   250
      for (int i = 0; i < lgrp_spaces()->length(); i++) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   251
        if (!lgrp_spaces()->at(i)->invalid_region().is_empty()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   252
          should_initialize = true;
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   253
          break;
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   254
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    if (should_initialize ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        (UseAdaptiveNUMAChunkSizing && adaptation_cycles() < samples_count())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      initialize(region(), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  if (NUMAStats) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
      lgrp_spaces()->at(i)->accumulate_statistics(page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  scan_pages(NUMAPageScanRate);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
// Scan pages. Free pages that have smaller size or wrong placement.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
void MutableNUMASpace::scan_pages(size_t page_count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  size_t pages_per_chunk = page_count / lgrp_spaces()->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  if (pages_per_chunk > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      ls->scan_pages(page_size(), pages_per_chunk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
// Accumulate statistics about the allocation rate of each lgrp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
void MutableNUMASpace::accumulate_statistics() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  if (UseAdaptiveNUMAChunkSizing) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      lgrp_spaces()->at(i)->sample();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    increment_samples_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  if (NUMAStats) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      lgrp_spaces()->at(i)->accumulate_statistics(page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
// Get the current size of a chunk.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
// This function computes the size of the chunk based on the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
// difference between chunk ends. This allows it to work correctly in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
// case the whole space is resized and during the process of adaptive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
// chunk resizing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
size_t MutableNUMASpace::current_chunk_size(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  HeapWord *cur_end, *prev_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  if (i == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    prev_end = bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    prev_end = lgrp_spaces()->at(i - 1)->space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  if (i == lgrp_spaces()->length() - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    cur_end = end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    cur_end = lgrp_spaces()->at(i)->space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  if (cur_end > prev_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    return pointer_delta(cur_end, prev_end, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
// Return the default chunk size by equally diving the space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
// page_size() aligned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
size_t MutableNUMASpace::default_chunk_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  return base_space_size() / lgrp_spaces()->length() * page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
// Produce a new chunk size. page_size() aligned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
size_t MutableNUMASpace::adaptive_chunk_size(int i, size_t limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  size_t pages_available = base_space_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  for (int j = 0; j < i; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    pages_available -= round_down(current_chunk_size(j), page_size()) / page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  pages_available -= lgrp_spaces()->length() - i - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  assert(pages_available > 0, "No pages left");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  float alloc_rate = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  for (int j = i; j < lgrp_spaces()->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    alloc_rate += lgrp_spaces()->at(j)->alloc_rate()->average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  size_t chunk_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  if (alloc_rate > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    chunk_size = (size_t)(ls->alloc_rate()->average() * pages_available / alloc_rate) * page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  chunk_size = MAX2(chunk_size, page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  if (limit > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    limit = round_down(limit, page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    if (chunk_size > current_chunk_size(i)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
      chunk_size = MIN2((off_t)chunk_size, (off_t)current_chunk_size(i) + (off_t)limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      chunk_size = MAX2((off_t)chunk_size, (off_t)current_chunk_size(i) - (off_t)limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  assert(chunk_size <= pages_available * page_size(), "Chunk size out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  return chunk_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
// Return the bottom_region and the top_region. Align them to page_size() boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
// |------------------new_region---------------------------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
// |----bottom_region--|---intersection---|------top_region------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
void MutableNUMASpace::select_tails(MemRegion new_region, MemRegion intersection,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
                                    MemRegion* bottom_region, MemRegion *top_region) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  // Is there bottom?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  if (new_region.start() < intersection.start()) { // Yes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    // Try to coalesce small pages into a large one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    if (UseLargePages && page_size() >= os::large_page_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      HeapWord* p = (HeapWord*)round_to((intptr_t) intersection.start(), os::large_page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      if (new_region.contains(p)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
          && pointer_delta(p, new_region.start(), sizeof(char)) >= os::large_page_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
        if (intersection.contains(p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
          intersection = MemRegion(p, intersection.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
          intersection = MemRegion(p, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    *bottom_region = MemRegion(new_region.start(), intersection.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    *bottom_region = MemRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  // Is there top?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  if (intersection.end() < new_region.end()) { // Yes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    // Try to coalesce small pages into a large one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    if (UseLargePages && page_size() >= os::large_page_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
      HeapWord* p = (HeapWord*)round_down((intptr_t) intersection.end(), os::large_page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      if (new_region.contains(p)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
          && pointer_delta(new_region.end(), p, sizeof(char)) >= os::large_page_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
        if (intersection.contains(p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
          intersection = MemRegion(intersection.start(), p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
          intersection = MemRegion(p, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    *top_region = MemRegion(intersection.end(), new_region.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    *top_region = MemRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
// Try to merge the invalid region with the bottom or top region by decreasing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
// the intersection area. Return the invalid_region aligned to the page_size()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
// boundary if it's inside the intersection. Return non-empty invalid_region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
// if it lies inside the intersection (also page-aligned).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
// |------------------new_region---------------------------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
// |----------------|-------invalid---|--------------------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
// |----bottom_region--|---intersection---|------top_region------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
void MutableNUMASpace::merge_regions(MemRegion new_region, MemRegion* intersection,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
                                     MemRegion *invalid_region) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  if (intersection->start() >= invalid_region->start() && intersection->contains(invalid_region->end())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    *intersection = MemRegion(invalid_region->end(), intersection->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    *invalid_region = MemRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    if (intersection->end() <= invalid_region->end() && intersection->contains(invalid_region->start())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      *intersection = MemRegion(intersection->start(), invalid_region->start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
      *invalid_region = MemRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
      if (intersection->equals(*invalid_region) || invalid_region->contains(*intersection)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
        *intersection = MemRegion(new_region.start(), new_region.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
        *invalid_region = MemRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
      } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
        if (intersection->contains(invalid_region)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
            // That's the only case we have to make an additional bias_region() call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
            HeapWord* start = invalid_region->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
            HeapWord* end = invalid_region->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
            if (UseLargePages && page_size() >= os::large_page_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
              HeapWord *p = (HeapWord*)round_down((intptr_t) start, os::large_page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
              if (new_region.contains(p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
                start = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
              p = (HeapWord*)round_to((intptr_t) end, os::large_page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
              if (new_region.contains(end)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
                end = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
            if (intersection->start() > start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
              *intersection = MemRegion(start, intersection->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
            if (intersection->end() < end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
              *intersection = MemRegion(intersection->start(), end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
            *invalid_region = MemRegion(start, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
void MutableNUMASpace::initialize(MemRegion mr, bool clear_space) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  assert(clear_space, "Reallocation will destory data!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  assert(lgrp_spaces()->length() > 0, "There should be at least one space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  MemRegion old_region = region(), new_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  set_bottom(mr.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  set_end(mr.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  MutableSpace::set_top(bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  // Compute chunk sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  size_t prev_page_size = page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  set_page_size(UseLargePages ? os::large_page_size() : os::vm_page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  HeapWord* rounded_bottom = (HeapWord*)round_to((intptr_t) bottom(), page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  HeapWord* rounded_end = (HeapWord*)round_down((intptr_t) end(), page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  size_t base_space_size_pages = pointer_delta(rounded_end, rounded_bottom, sizeof(char)) / page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  // Try small pages if the chunk size is too small
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  if (base_space_size_pages / lgrp_spaces()->length() == 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
      && page_size() > (size_t)os::vm_page_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    set_page_size(os::vm_page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    rounded_bottom = (HeapWord*)round_to((intptr_t) bottom(), page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    rounded_end = (HeapWord*)round_down((intptr_t) end(), page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    base_space_size_pages = pointer_delta(rounded_end, rounded_bottom, sizeof(char)) / page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  guarantee(base_space_size_pages / lgrp_spaces()->length() > 0, "Space too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  set_base_space_size(base_space_size_pages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  // Handle space resize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  MemRegion top_region, bottom_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  if (!old_region.equals(region())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    new_region = MemRegion(rounded_bottom, rounded_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    MemRegion intersection = new_region.intersection(old_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    if (intersection.start() == NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
        intersection.end() == NULL   ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
        prev_page_size > page_size()) { // If the page size got smaller we have to change
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
                                        // the page size preference for the whole space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
      intersection = MemRegion(new_region.start(), new_region.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    select_tails(new_region, intersection, &bottom_region, &top_region);
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   490
    bias_region(bottom_region, lgrp_spaces()->at(0)->lgrp_id());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   491
    bias_region(top_region, lgrp_spaces()->at(lgrp_spaces()->length() - 1)->lgrp_id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  // Check if the space layout has changed significantly?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  // This happens when the space has been resized so that either head or tail
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  // chunk became less than a page.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  bool layout_valid = UseAdaptiveNUMAChunkSizing          &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
                      current_chunk_size(0) > page_size() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
                      current_chunk_size(lgrp_spaces()->length() - 1) > page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    MutableSpace *s = ls->space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    old_region = s->region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    size_t chunk_byte_size = 0, old_chunk_byte_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    if (i < lgrp_spaces()->length() - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
      if (!UseAdaptiveNUMAChunkSizing                                ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
          (UseAdaptiveNUMAChunkSizing && NUMAChunkResizeWeight == 0) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
           samples_count() < AdaptiveSizePolicyReadyThreshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
        // No adaptation. Divide the space equally.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
        chunk_byte_size = default_chunk_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
      } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
        if (!layout_valid || NUMASpaceResizeRate == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
          // Fast adaptation. If no space resize rate is set, resize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
          // the chunks instantly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
          chunk_byte_size = adaptive_chunk_size(i, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
          // Slow adaptation. Resize the chunks moving no more than
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
          // NUMASpaceResizeRate bytes per collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
          size_t limit = NUMASpaceResizeRate /
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
                         (lgrp_spaces()->length() * (lgrp_spaces()->length() + 1) / 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
          chunk_byte_size = adaptive_chunk_size(i, MAX2(limit * (i + 1), page_size()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      assert(chunk_byte_size >= page_size(), "Chunk size too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      assert(chunk_byte_size <= capacity_in_bytes(), "Sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    if (i == 0) { // Bottom chunk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
      if (i != lgrp_spaces()->length() - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
        new_region = MemRegion(bottom(), rounded_bottom + (chunk_byte_size >> LogHeapWordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
        new_region = MemRegion(bottom(), end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
      if (i < lgrp_spaces()->length() - 1) { // Middle chunks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
        MutableSpace *ps = lgrp_spaces()->at(i - 1)->space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
        new_region = MemRegion(ps->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
                               ps->end() + (chunk_byte_size >> LogHeapWordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
      } else { // Top chunk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
        MutableSpace *ps = lgrp_spaces()->at(i - 1)->space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
        new_region = MemRegion(ps->end(), end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    guarantee(region().contains(new_region), "Region invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    // The general case:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    // |---------------------|--invalid---|--------------------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    // |------------------new_region---------------------------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
    // |----bottom_region--|---intersection---|------top_region------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
    //                     |----old_region----|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
    // The intersection part has all pages in place we don't need to migrate them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    // Pages for the top and bottom part should be freed and then reallocated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    MemRegion intersection = old_region.intersection(new_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    if (intersection.start() == NULL || intersection.end() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
      intersection = MemRegion(new_region.start(), new_region.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   563
    if (!os::numa_has_static_binding()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   564
      MemRegion invalid_region = ls->invalid_region().intersection(new_region);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   565
      // Invalid region is a range of memory that could've possibly
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   566
      // been allocated on the other node. That's relevant only on Solaris where
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   567
      // there is no static memory binding.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   568
      if (!invalid_region.is_empty()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   569
        merge_regions(new_region, &intersection, &invalid_region);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   570
        free_region(invalid_region);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   571
        ls->set_invalid_region(MemRegion());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   572
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    }
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   574
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    select_tails(new_region, intersection, &bottom_region, &top_region);
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   576
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   577
    if (!os::numa_has_static_binding()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   578
      // If that's a system with the first-touch policy then it's enough
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   579
      // to free the pages.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   580
      free_region(bottom_region);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   581
      free_region(top_region);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   582
    } else {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   583
      // In a system with static binding we have to change the bias whenever
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   584
      // we reshape the heap.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   585
      bias_region(bottom_region, ls->lgrp_id());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   586
      bias_region(top_region, ls->lgrp_id());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   587
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    // If we clear the region, we would mangle it in debug. That would cause page
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    // allocation in a different place. Hence setting the top directly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    s->initialize(new_region, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
    s->set_top(s->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    set_adaptation_cycles(samples_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
// Set the top of the whole space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
// Mark the the holes in chunks below the top() as invalid.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
void MutableNUMASpace::set_top(HeapWord* value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  bool found_top = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    MutableSpace *s = ls->space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    HeapWord *top = MAX2((HeapWord*)round_down((intptr_t)s->top(), page_size()), s->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    if (s->contains(value)) {
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   608
      if (!os::numa_has_static_binding() && top < value && top < s->end()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
        ls->add_invalid_region(MemRegion(top, value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
      s->set_top(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
      found_top = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
        if (found_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
            s->set_top(s->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
        } else {
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   617
          if (!os::numa_has_static_binding() && top < s->end()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   618
            ls->add_invalid_region(MemRegion(top, s->end()));
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   619
          }
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   620
          s->set_top(s->end());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  MutableSpace::set_top(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
void MutableNUMASpace::clear() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  MutableSpace::set_top(bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
    lgrp_spaces()->at(i)->space()->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   634
/*
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   635
   Linux supports static memory binding, therefore the most part of the
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   636
   logic dealing with the possible invalid page allocation is effectively
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   637
   disabled. Besides there is no notion of the home node in Linux. A
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   638
   thread is allowed to migrate freely. Although the scheduler is rather
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   639
   reluctant to move threads between the nodes. We check for the current
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   640
   node every allocation. And with a high probability a thread stays on
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   641
   the same node for some time allowing local access to recently allocated
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   642
   objects.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   643
 */
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   644
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
HeapWord* MutableNUMASpace::allocate(size_t size) {
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   646
  Thread* thr = Thread::current();
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   647
  int lgrp_id = thr->lgrp_id();
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   648
  if (lgrp_id == -1 || !os::numa_has_group_homing()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    lgrp_id = os::numa_get_group_id();
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   650
    thr->set_lgrp_id(lgrp_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  // It is possible that a new CPU has been hotplugged and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  // we haven't reshaped the space accordingly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  if (i == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    i = os::random() % lgrp_spaces()->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
  MutableSpace *s = lgrp_spaces()->at(i)->space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  HeapWord *p = s->allocate(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   664
  if (p != NULL) {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   665
    size_t remainder = s->free_in_words();
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   666
    if (remainder < (size_t)oopDesc::header_size() && remainder > 0) {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   667
      s->set_top(s->top() - size);
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   668
      p = NULL;
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   669
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  if (p != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    if (top() < s->top()) { // Keep _top updated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
      MutableSpace::set_top(s->top());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  }
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   676
  // Make the page allocation happen here if there is no static binding..
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   677
  if (p != NULL && !os::numa_has_static_binding()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    for (HeapWord *i = p; i < p + size; i += os::vm_page_size() >> LogHeapWordSize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
      *(int*)i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
// This version is lock-free.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
HeapWord* MutableNUMASpace::cas_allocate(size_t size) {
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   687
  Thread* thr = Thread::current();
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   688
  int lgrp_id = thr->lgrp_id();
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   689
  if (lgrp_id == -1 || !os::numa_has_group_homing()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
    lgrp_id = os::numa_get_group_id();
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   691
    thr->set_lgrp_id(lgrp_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  // It is possible that a new CPU has been hotplugged and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  // we haven't reshaped the space accordingly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  if (i == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
    i = os::random() % lgrp_spaces()->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  MutableSpace *s = lgrp_spaces()->at(i)->space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  HeapWord *p = s->cas_allocate(size);
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   702
  if (p != NULL) {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   703
    size_t remainder = pointer_delta(s->end(), p);
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   704
    if (remainder < (size_t)oopDesc::header_size() && remainder > 0) {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   705
      if (s->cas_deallocate(p, size)) {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   706
        // We were the last to allocate and created a fragment less than
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   707
        // a minimal object.
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   708
        p = NULL;
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   709
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  if (p != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
    HeapWord* cur_top, *cur_chunk_top = p + size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
    while ((cur_top = top()) < cur_chunk_top) { // Keep _top updated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
      if (Atomic::cmpxchg_ptr(cur_chunk_top, top_addr(), cur_top) == cur_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   721
  // Make the page allocation happen here if there is no static binding.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   722
  if (p != NULL && !os::numa_has_static_binding() ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
    for (HeapWord *i = p; i < p + size; i += os::vm_page_size() >> LogHeapWordSize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
      *(int*)i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
void MutableNUMASpace::print_short_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  MutableSpace::print_short_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  st->print(" (");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
    st->print("lgrp %d: ", lgrp_spaces()->at(i)->lgrp_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
    lgrp_spaces()->at(i)->space()->print_short_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
    if (i < lgrp_spaces()->length() - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
      st->print(", ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  st->print(")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
void MutableNUMASpace::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  MutableSpace::print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
    LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
    st->print("    lgrp %d", ls->lgrp_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
    ls->space()->print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
    if (NUMAStats) {
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   750
      for (int i = 0; i < lgrp_spaces()->length(); i++) {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   751
        lgrp_spaces()->at(i)->accumulate_statistics(page_size());
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   752
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
      st->print("    local/remote/unbiased/uncommitted: %dK/%dK/%dK/%dK, large/small pages: %d/%d\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
                ls->space_stats()->_local_space / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
                ls->space_stats()->_remote_space / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
                ls->space_stats()->_unbiased_space / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
                ls->space_stats()->_uncommited_space / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
                ls->space_stats()->_large_pages,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
                ls->space_stats()->_small_pages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
void MutableNUMASpace::verify(bool allow_dirty) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
 for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
    lgrp_spaces()->at(i)->space()->verify(allow_dirty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
// Scan pages and gather stats about page placement and size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
void MutableNUMASpace::LGRPSpace::accumulate_statistics(size_t page_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  clear_space_stats();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  char *start = (char*)round_to((intptr_t) space()->bottom(), page_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  char* end = (char*)round_down((intptr_t) space()->end(), page_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  if (start < end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
    for (char *p = start; p < end;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
      os::page_info info;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
      if (os::get_page_info(p, &info)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
        if (info.size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
          if (info.size > (size_t)os::vm_page_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
            space_stats()->_large_pages++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
            space_stats()->_small_pages++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
          if (info.lgrp_id == lgrp_id()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
            space_stats()->_local_space += info.size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
            space_stats()->_remote_space += info.size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
          p += info.size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
          p += os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
          space_stats()->_uncommited_space += os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  space_stats()->_unbiased_space = pointer_delta(start, space()->bottom(), sizeof(char)) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
                                   pointer_delta(space()->end(), end, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
// Scan page_count pages and verify if they have the right size and right placement.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
// If invalid pages are found they are freed in hope that subsequent reallocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
// will be more successful.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
void MutableNUMASpace::LGRPSpace::scan_pages(size_t page_size, size_t page_count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  char* range_start = (char*)round_to((intptr_t) space()->bottom(), page_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  char* range_end = (char*)round_down((intptr_t) space()->end(), page_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  if (range_start > last_page_scanned() || last_page_scanned() >= range_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
    set_last_page_scanned(range_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  char *scan_start = last_page_scanned();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
  char* scan_end = MIN2(scan_start + page_size * page_count, range_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  os::page_info page_expected, page_found;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  page_expected.size = page_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  page_expected.lgrp_id = lgrp_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
  char *s = scan_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
  while (s < scan_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
    char *e = os::scan_pages(s, (char*)scan_end, &page_expected, &page_found);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    if (e == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
    if (e != scan_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
      if ((page_expected.size != page_size || page_expected.lgrp_id != lgrp_id())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
          && page_expected.size != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
        os::free_memory(s, pointer_delta(e, s, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
      page_expected = page_found;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
    s = e;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
  set_last_page_scanned(scan_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
}