Skip to content

Commit 703a7dc

Browse files
committed
8370345: Parallel: Rework TLAB accounting in MutableNUMASpace
1 parent 9a88d7f commit 703a7dc

File tree

5 files changed

+39
-48
lines changed

5 files changed

+39
-48
lines changed

src/hotspot/os/linux/os_linux.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -846,10 +846,6 @@ static void *thread_native_entry(Thread *thread) {
846846

847847
osthread->set_thread_id(checked_cast<pid_t>(os::current_thread_id()));
848848

849-
if (UseNUMA) {
850-
thread->update_lgrp_id();
851-
}
852-
853849
// initialize signal mask for this thread
854850
PosixSignals::hotspot_sigmask(thread);
855851

@@ -1175,10 +1171,6 @@ bool os::create_attached_thread(JavaThread* thread) {
11751171

11761172
thread->set_osthread(osthread);
11771173

1178-
if (UseNUMA) {
1179-
thread->update_lgrp_id();
1180-
}
1181-
11821174
if (os::is_primordial_thread()) {
11831175
// If current thread is primordial thread, its stack is mapped on demand,
11841176
// see notes about MAP_GROWSDOWN. Here we try to force kernel to map

src/hotspot/share/gc/parallel/mutableNUMASpace.cpp

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -94,47 +94,42 @@ void MutableNUMASpace::ensure_parsability() {
9494

9595
size_t MutableNUMASpace::used_in_words() const {
9696
size_t s = 0;
97-
for (int i = 0; i < lgrp_spaces()->length(); i++) {
98-
s += lgrp_spaces()->at(i)->space()->used_in_words();
97+
for (LGRPSpace* ls : *lgrp_spaces()) {
98+
s += ls->space()->used_in_words();
9999
}
100100
return s;
101101
}
102102

103103
size_t MutableNUMASpace::free_in_words() const {
104104
size_t s = 0;
105-
for (int i = 0; i < lgrp_spaces()->length(); i++) {
106-
s += lgrp_spaces()->at(i)->space()->free_in_words();
105+
for (LGRPSpace* ls : *lgrp_spaces()) {
106+
s += ls->space()->free_in_words();
107107
}
108108
return s;
109109
}
110110

111-
MutableNUMASpace::LGRPSpace *MutableNUMASpace::lgrp_space_for_thread(Thread* thr) const {
112-
guarantee(thr != nullptr, "No thread");
113-
114-
int lgrp_id = thr->lgrp_id();
115-
assert(lgrp_id != -1, "lgrp_id must be set during thread creation");
116-
117-
int lgrp_spaces_index = lgrp_spaces()->find_if([&](LGRPSpace* space) {
118-
return space->lgrp_id() == (uint)lgrp_id;
119-
});
120-
121-
if (lgrp_spaces_index == -1) {
122-
// Running on a CPU with no memory; pick another CPU based on %.
123-
lgrp_spaces_index = lgrp_id % lgrp_spaces()->length();
111+
size_t MutableNUMASpace::tlab_capacity(Thread *ignored) const {
112+
size_t s = 0;
113+
for (LGRPSpace* ls : *lgrp_spaces()) {
114+
s += ls->space()->capacity_in_bytes();
124115
}
125-
return lgrp_spaces()->at(lgrp_spaces_index);
126-
}
127-
128-
size_t MutableNUMASpace::tlab_capacity(Thread *thr) const {
129-
return lgrp_space_for_thread(thr)->space()->capacity_in_bytes();
116+
return s / (size_t)lgrp_spaces()->length();
130117
}
131118

132-
size_t MutableNUMASpace::tlab_used(Thread *thr) const {
133-
return lgrp_space_for_thread(thr)->space()->used_in_bytes();
119+
size_t MutableNUMASpace::tlab_used(Thread *ignored) const {
120+
size_t s = 0;
121+
for (LGRPSpace* ls : *lgrp_spaces()) {
122+
s += ls->space()->used_in_bytes();
123+
}
124+
return s / (size_t)lgrp_spaces()->length();
134125
}
135126

136-
size_t MutableNUMASpace::unsafe_max_tlab_alloc(Thread *thr) const {
137-
return lgrp_space_for_thread(thr)->space()->free_in_bytes();
127+
size_t MutableNUMASpace::unsafe_max_tlab_alloc(Thread *ignored) const {
128+
size_t s = 0;
129+
for (LGRPSpace* ls : *lgrp_spaces()) {
130+
s += ls->space()->free_in_bytes();
131+
}
132+
return s / (size_t)lgrp_spaces()->length();
138133
}
139134

140135
// Bias region towards the first-touching lgrp. Set the right page sizes.
@@ -442,13 +437,22 @@ void MutableNUMASpace::clear(bool mangle_space) {
442437
}
443438
}
444439

445-
HeapWord* MutableNUMASpace::cas_allocate(size_t size) {
446-
Thread *thr = Thread::current();
440+
MutableNUMASpace::LGRPSpace *MutableNUMASpace::lgrp_space_for_current_thread() const {
441+
const int lgrp_id = os::numa_get_group_id();
442+
int lgrp_spaces_index = lgrp_spaces()->find_if([&](LGRPSpace* space) {
443+
return space->lgrp_id() == (uint)lgrp_id;
444+
});
447445

448-
// Update the locality group to match where the thread actually is.
449-
thr->update_lgrp_id();
446+
if (lgrp_spaces_index == -1) {
447+
// Running on a CPU with no memory; pick another CPU based on %.
448+
lgrp_spaces_index = lgrp_id % lgrp_spaces()->length();
449+
}
450450

451-
LGRPSpace *ls = lgrp_space_for_thread(thr);
451+
return lgrp_spaces()->at(lgrp_spaces_index);
452+
}
453+
454+
HeapWord* MutableNUMASpace::cas_allocate(size_t size) {
455+
LGRPSpace *ls = lgrp_space_for_current_thread();
452456
MutableSpace *s = ls->space();
453457
HeapWord *p = s->cas_allocate(size);
454458
if (p != nullptr) {

src/hotspot/share/gc/parallel/mutableNUMASpace.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class MutableNUMASpace : public MutableSpace {
140140
void select_tails(MemRegion new_region, MemRegion intersection,
141141
MemRegion* bottom_region, MemRegion *top_region);
142142

143-
LGRPSpace *lgrp_space_for_thread(Thread *thr) const;
143+
LGRPSpace *lgrp_space_for_current_thread() const;
144144

145145
public:
146146
GrowableArray<LGRPSpace*>* lgrp_spaces() const { return _lgrp_spaces; }
@@ -166,9 +166,9 @@ class MutableNUMASpace : public MutableSpace {
166166
virtual size_t used_in_words() const;
167167
virtual size_t free_in_words() const;
168168

169-
virtual size_t tlab_capacity(Thread* thr) const;
170-
virtual size_t tlab_used(Thread* thr) const;
171-
virtual size_t unsafe_max_tlab_alloc(Thread* thr) const;
169+
virtual size_t tlab_capacity(Thread* ignored) const;
170+
virtual size_t tlab_used(Thread* ignored) const;
171+
virtual size_t unsafe_max_tlab_alloc(Thread* ignored) const;
172172

173173
// Allocation (return null if full)
174174
virtual HeapWord* cas_allocate(size_t word_size);

src/hotspot/share/runtime/thread.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ Thread::Thread(MemTag mem_tag) {
6565
// stack and get_thread
6666
set_stack_base(nullptr);
6767
set_stack_size(0);
68-
_lgrp_id = -1;
6968
DEBUG_ONLY(clear_suspendible_thread();)
7069
DEBUG_ONLY(clear_indirectly_suspendible_thread();)
7170
DEBUG_ONLY(clear_indirectly_safepoint_thread();)

src/hotspot/share/runtime/thread.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ class Thread: public ThreadShadow {
522522
// Support for stack overflow handling, get_thread, etc.
523523
address _stack_base;
524524
size_t _stack_size;
525-
int _lgrp_id;
526525

527526
public:
528527
// Stack overflow support
@@ -537,9 +536,6 @@ class Thread: public ThreadShadow {
537536
void register_thread_stack_with_NMT();
538537
void unregister_thread_stack_with_NMT();
539538

540-
int lgrp_id() const { return _lgrp_id; }
541-
void update_lgrp_id() { _lgrp_id = os::numa_get_group_id(); }
542-
543539
// Printing
544540
void print_on(outputStream* st, bool print_extended_info) const;
545541
virtual void print_on(outputStream* st) const { print_on(st, false); }

0 commit comments

Comments
 (0)