Skip to content

Commit 37ec796

Browse files
committed
8351500: G1: NUMA migrations cause crashes in region allocation
Reviewed-by: rkennke, sjohanss, tschatzl
1 parent 4e51a8c commit 37ec796

File tree

5 files changed

+42
-36
lines changed

5 files changed

+42
-36
lines changed

src/hotspot/share/gc/g1/g1Allocator.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,24 +212,24 @@ size_t G1Allocator::used_in_alloc_regions() {
212212

213213

214214
HeapWord* G1Allocator::par_allocate_during_gc(G1HeapRegionAttr dest,
215-
size_t word_size,
216-
uint node_index) {
215+
uint node_index,
216+
size_t word_size) {
217217
size_t temp = 0;
218-
HeapWord* result = par_allocate_during_gc(dest, word_size, word_size, &temp, node_index);
218+
HeapWord* result = par_allocate_during_gc(dest, node_index, word_size, word_size, &temp);
219219
assert(result == nullptr || temp == word_size,
220220
"Requested %zu words, but got %zu at " PTR_FORMAT,
221221
word_size, temp, p2i(result));
222222
return result;
223223
}
224224

225225
HeapWord* G1Allocator::par_allocate_during_gc(G1HeapRegionAttr dest,
226+
uint node_index,
226227
size_t min_word_size,
227228
size_t desired_word_size,
228-
size_t* actual_word_size,
229-
uint node_index) {
229+
size_t* actual_word_size) {
230230
switch (dest.type()) {
231231
case G1HeapRegionAttr::Young:
232-
return survivor_attempt_allocation(min_word_size, desired_word_size, actual_word_size, node_index);
232+
return survivor_attempt_allocation(node_index, min_word_size, desired_word_size, actual_word_size);
233233
case G1HeapRegionAttr::Old:
234234
return old_attempt_allocation(min_word_size, desired_word_size, actual_word_size);
235235
default:
@@ -238,10 +238,10 @@ HeapWord* G1Allocator::par_allocate_during_gc(G1HeapRegionAttr dest,
238238
}
239239
}
240240

241-
HeapWord* G1Allocator::survivor_attempt_allocation(size_t min_word_size,
241+
HeapWord* G1Allocator::survivor_attempt_allocation(uint node_index,
242+
size_t min_word_size,
242243
size_t desired_word_size,
243-
size_t* actual_word_size,
244-
uint node_index) {
244+
size_t* actual_word_size) {
245245
assert(!_g1h->is_humongous(desired_word_size),
246246
"we should not be seeing humongous-size allocations in this path");
247247

@@ -397,10 +397,10 @@ HeapWord* G1PLABAllocator::allocate_direct_or_new_plab(G1HeapRegionAttr dest,
397397

398398
size_t actual_plab_size = 0;
399399
HeapWord* buf = _allocator->par_allocate_during_gc(dest,
400+
node_index,
400401
required_in_plab,
401402
plab_word_size,
402-
&actual_plab_size,
403-
node_index);
403+
&actual_plab_size);
404404

405405
assert(buf == nullptr || ((actual_plab_size >= required_in_plab) && (actual_plab_size <= plab_word_size)),
406406
"Requested at minimum %zu, desired %zu words, but got %zu at " PTR_FORMAT,
@@ -419,7 +419,7 @@ HeapWord* G1PLABAllocator::allocate_direct_or_new_plab(G1HeapRegionAttr dest,
419419
*plab_refill_failed = true;
420420
}
421421
// Try direct allocation.
422-
HeapWord* result = _allocator->par_allocate_during_gc(dest, word_sz, node_index);
422+
HeapWord* result = _allocator->par_allocate_during_gc(dest, node_index, word_sz);
423423
if (result != nullptr) {
424424
plab_data->_direct_allocated += word_sz;
425425
plab_data->_num_direct_allocations++;

src/hotspot/share/gc/g1/g1Allocator.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,16 @@ class G1Allocator : public CHeapObj<mtGC> {
7878
inline OldGCAllocRegion* old_gc_alloc_region();
7979

8080
// Allocation attempt during GC for a survivor object / PLAB.
81-
HeapWord* survivor_attempt_allocation(size_t min_word_size,
81+
HeapWord* survivor_attempt_allocation(uint node_index,
82+
size_t min_word_size,
8283
size_t desired_word_size,
83-
size_t* actual_word_size,
84-
uint node_index);
84+
size_t* actual_word_size);
8585

8686
// Allocation attempt during GC for an old object / PLAB.
8787
HeapWord* old_attempt_allocation(size_t min_word_size,
8888
size_t desired_word_size,
8989
size_t* actual_word_size);
9090

91-
// Node index of current thread.
92-
inline uint current_node_index() const;
93-
9491
public:
9592
G1Allocator(G1CollectedHeap* heap);
9693
~G1Allocator();
@@ -110,16 +107,20 @@ class G1Allocator : public CHeapObj<mtGC> {
110107
void abandon_gc_alloc_regions();
111108
bool is_retained_old_region(G1HeapRegion* hr);
112109

110+
// Node index of current thread.
111+
inline uint current_node_index() const;
112+
113113
// Allocate blocks of memory during mutator time.
114114

115115
// Attempt allocation in the current alloc region.
116-
inline HeapWord* attempt_allocation(size_t min_word_size,
116+
inline HeapWord* attempt_allocation(uint node_index,
117+
size_t min_word_size,
117118
size_t desired_word_size,
118119
size_t* actual_word_size);
119120

120121
// This is to be called when holding an appropriate lock. It first tries in the
121122
// current allocation region, and then attempts an allocation using a new region.
122-
inline HeapWord* attempt_allocation_locked(size_t word_size);
123+
inline HeapWord* attempt_allocation_locked(uint node_index, size_t word_size);
123124

124125
size_t unsafe_max_tlab_alloc();
125126
size_t used_in_alloc_regions();
@@ -129,14 +130,15 @@ class G1Allocator : public CHeapObj<mtGC> {
129130
// heap, and then allocate a block of the given size. The block
130131
// may not be a humongous - it must fit into a single heap region.
131132
HeapWord* par_allocate_during_gc(G1HeapRegionAttr dest,
132-
size_t word_size,
133-
uint node_index);
133+
uint node_index,
134+
size_t word_size
135+
);
134136

135137
HeapWord* par_allocate_during_gc(G1HeapRegionAttr dest,
138+
uint node_index,
136139
size_t min_word_size,
137140
size_t desired_word_size,
138-
size_t* actual_word_size,
139-
uint node_index);
141+
size_t* actual_word_size);
140142
};
141143

142144
// Manages the PLABs used during garbage collection. Interface for allocation from PLABs.

src/hotspot/share/gc/g1/g1Allocator.inline.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ inline OldGCAllocRegion* G1Allocator::old_gc_alloc_region() {
4949
return &_old_gc_alloc_region;
5050
}
5151

52-
inline HeapWord* G1Allocator::attempt_allocation(size_t min_word_size,
52+
inline HeapWord* G1Allocator::attempt_allocation(uint node_index,
53+
size_t min_word_size,
5354
size_t desired_word_size,
5455
size_t* actual_word_size) {
55-
uint node_index = current_node_index();
56-
5756
HeapWord* result = mutator_alloc_region(node_index)->attempt_retained_allocation(min_word_size, desired_word_size, actual_word_size);
5857
if (result != nullptr) {
5958
return result;
@@ -62,8 +61,7 @@ inline HeapWord* G1Allocator::attempt_allocation(size_t min_word_size,
6261
return mutator_alloc_region(node_index)->attempt_allocation(min_word_size, desired_word_size, actual_word_size);
6362
}
6463

65-
inline HeapWord* G1Allocator::attempt_allocation_locked(size_t word_size) {
66-
uint node_index = current_node_index();
64+
inline HeapWord* G1Allocator::attempt_allocation_locked(uint node_index, size_t word_size) {
6765
HeapWord* result = mutator_alloc_region(node_index)->attempt_allocation_locked(word_size);
6866

6967
assert(result != nullptr || mutator_alloc_region(node_index)->get() == nullptr,

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ G1CollectedHeap::mem_allocate(size_t word_size,
402402
return attempt_allocation(word_size, word_size, &dummy);
403403
}
404404

405-
HeapWord* G1CollectedHeap::attempt_allocation_slow(size_t word_size) {
405+
HeapWord* G1CollectedHeap::attempt_allocation_slow(uint node_index, size_t word_size) {
406406
ResourceMark rm; // For retrieving the thread names in log messages.
407407

408408
// Make sure you read the note in attempt_allocation_humongous().
@@ -426,7 +426,7 @@ HeapWord* G1CollectedHeap::attempt_allocation_slow(size_t word_size) {
426426

427427
// Now that we have the lock, we first retry the allocation in case another
428428
// thread changed the region while we were waiting to acquire the lock.
429-
result = _allocator->attempt_allocation_locked(word_size);
429+
result = _allocator->attempt_allocation_locked(node_index, word_size);
430430
if (result != nullptr) {
431431
return result;
432432
}
@@ -453,7 +453,7 @@ HeapWord* G1CollectedHeap::attempt_allocation_slow(size_t word_size) {
453453
// here and the follow-on attempt will be at the start of the next loop
454454
// iteration (after taking the Heap_lock).
455455
size_t dummy = 0;
456-
result = _allocator->attempt_allocation(word_size, word_size, &dummy);
456+
result = _allocator->attempt_allocation(node_index, word_size, word_size, &dummy);
457457
if (result != nullptr) {
458458
return result;
459459
}
@@ -587,11 +587,14 @@ inline HeapWord* G1CollectedHeap::attempt_allocation(size_t min_word_size,
587587
assert(!is_humongous(desired_word_size), "attempt_allocation() should not "
588588
"be called for humongous allocation requests");
589589

590-
HeapWord* result = _allocator->attempt_allocation(min_word_size, desired_word_size, actual_word_size);
590+
// Fix NUMA node association for the duration of this allocation
591+
const uint node_index = _allocator->current_node_index();
592+
593+
HeapWord* result = _allocator->attempt_allocation(node_index, min_word_size, desired_word_size, actual_word_size);
591594

592595
if (result == nullptr) {
593596
*actual_word_size = desired_word_size;
594-
result = attempt_allocation_slow(desired_word_size);
597+
result = attempt_allocation_slow(node_index, desired_word_size);
595598
}
596599

597600
assert_heap_not_locked();
@@ -698,8 +701,11 @@ HeapWord* G1CollectedHeap::attempt_allocation_at_safepoint(size_t word_size,
698701
assert(!_allocator->has_mutator_alloc_region() || !expect_null_mutator_alloc_region,
699702
"the current alloc region was unexpectedly found to be non-null");
700703

704+
// Fix NUMA node association for the duration of this allocation
705+
const uint node_index = _allocator->current_node_index();
706+
701707
if (!is_humongous(word_size)) {
702-
return _allocator->attempt_allocation_locked(word_size);
708+
return _allocator->attempt_allocation_locked(node_index, word_size);
703709
} else {
704710
HeapWord* result = humongous_obj_allocate(word_size);
705711
if (result != nullptr && policy()->need_to_start_conc_mark("STW humongous allocation")) {

src/hotspot/share/gc/g1/g1CollectedHeap.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ class G1CollectedHeap : public CollectedHeap {
450450
// Second-level mutator allocation attempt: take the Heap_lock and
451451
// retry the allocation attempt, potentially scheduling a GC
452452
// pause. This should only be used for non-humongous allocations.
453-
HeapWord* attempt_allocation_slow(size_t word_size);
453+
HeapWord* attempt_allocation_slow(uint node_index, size_t word_size);
454454

455455
// Takes the Heap_lock and attempts a humongous allocation. It can
456456
// potentially schedule a GC pause.

0 commit comments

Comments
 (0)