annotate src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp @ 373:06df86c2ec37

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