Skip to content

Commit 9385b86

Browse files
committed
Bugfix for NUMA preferred explicit large pages
1 parent 31ba7da commit 9385b86

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

src/hotspot/share/gc/z/zPageAllocator.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,13 @@ bool ZPageAllocator::prime_cache(ZWorkers* workers, size_t size) {
463463
return false;
464464
}
465465

466-
map_virtual_to_physical(vmem);
466+
map_virtual_to_physical(vmem, numa_id);
467+
468+
// Memory should have ended up on the desired NUMA id, if that's not the case, print error.
469+
int actual = ZNUMA::memory_id(untype(ZOffset::address(vmem.start())));
470+
if (actual != numa_id) {
471+
log_debug(gc, heap)("NUMA Mismatch (priming): desired %d, actual %d", numa_id, actual);
472+
}
467473

468474
if (AlwaysPreTouch) {
469475
// Pre-touch memory
@@ -638,9 +644,9 @@ void ZPageAllocator::uncommit_physical(const ZMemoryRange& vmem) {
638644
_physical.uncommit(_physical_mappings.get_addr(vmem.start()), vmem.size());
639645
}
640646

641-
void ZPageAllocator::map_virtual_to_physical(const ZMemoryRange& vmem) {
647+
void ZPageAllocator::map_virtual_to_physical(const ZMemoryRange& vmem, int numa_id) {
642648
// Map virtual memory to physical memory
643-
_physical.map(vmem.start(), _physical_mappings.get_addr(vmem.start()), vmem.size());
649+
_physical.map(vmem.start(), _physical_mappings.get_addr(vmem.start()), vmem.size(), numa_id);
644650
}
645651

646652
void ZPageAllocator::unmap_virtual(const ZMemoryRange& vmem) {
@@ -677,9 +683,10 @@ void ZPageAllocator::remap_and_defragment_mapping(const ZMemoryRange& vmem, ZArr
677683

678684
// The entries array may contain entires from other defragmentations as well,
679685
// so we only operate on the last ranges that we have just inserted
686+
int numa_id = _virtual.get_numa_id(vmem);
680687
for (int idx = entries->length() - num_ranges; idx < entries->length(); idx++) {
681688
ZMemoryRange v = entries->at(idx);
682-
map_virtual_to_physical(v);
689+
map_virtual_to_physical(v, numa_id);
683690
pretouch_memory(v.start(), v.size());
684691
}
685692
}
@@ -897,7 +904,7 @@ bool ZPageAllocator::claim_virtual_memory(ZPageAllocation* allocation) {
897904
if (allocation->harvested() > 0) {
898905
ZArrayIterator<ZMemoryRange> iter(allocation->claimed_mappings());
899906
for (ZMemoryRange vmem; iter.next(&vmem);) {
900-
map_virtual_to_physical(vmem);
907+
map_virtual_to_physical(vmem, allocation->numa_id());
901908
}
902909
}
903910

@@ -921,9 +928,15 @@ bool ZPageAllocator::commit_and_map_memory(ZPageAllocation* allocation, const ZM
921928
}
922929

923930
sort_segments_physical(committed_vmem);
924-
map_virtual_to_physical(committed_vmem);
931+
map_virtual_to_physical(committed_vmem, allocation->numa_id());
925932
allocation->claimed_mappings()->append(committed_vmem);
926933

934+
// Memory should have ended up on the desired NUMA id, if that's not the case, print error.
935+
int actual = ZNUMA::memory_id(untype(ZOffset::address(vmem.start())));
936+
if (actual != allocation->numa_id()) {
937+
log_debug(gc, heap)("NUMA Mismatch (allocation): desired %d, actual %d", allocation->numa_id(), actual);
938+
}
939+
927940
if (committed_vmem.size() != vmem.size()) {
928941
log_trace(gc, page)("Split memory [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT "]",
929942
untype(committed_vmem.start()),
@@ -935,7 +948,6 @@ bool ZPageAllocator::commit_and_map_memory(ZPageAllocation* allocation, const ZM
935948
return true;
936949
}
937950

938-
939951
ZPage* ZPageAllocator::alloc_page_inner(ZPageAllocation* allocation) {
940952
retry:
941953
// Claim physical memory by taking it from the mapped cache or by increasing

src/hotspot/share/gc/z/zPageAllocator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ZPageAllocator {
7575
bool commit_physical(ZMemoryRange* vmem, int numa_id);
7676
void uncommit_physical(const ZMemoryRange& vmem);
7777

78-
void map_virtual_to_physical(const ZMemoryRange& vmem);
78+
void map_virtual_to_physical(const ZMemoryRange& vmem, int numa_id);
7979

8080
void unmap_virtual(const ZMemoryRange& vmem);
8181
void free_virtual(const ZMemoryRange& vmem);

src/hotspot/share/gc/z/zPhysicalMemoryManager.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "gc/z/zAddress.inline.hpp"
2626
#include "gc/z/zArray.inline.hpp"
2727
#include "gc/z/zGlobals.hpp"
28+
#include "gc/z/zLargePages.inline.hpp"
2829
#include "gc/z/zList.inline.hpp"
2930
#include "gc/z/zNMT.hpp"
3031
#include "gc/z/zNUMA.inline.hpp"
@@ -75,7 +76,7 @@ void ZPhysicalMemoryManager::try_enable_uncommit(size_t min_capacity, size_t max
7576
// Test if uncommit is supported by the operating system by committing
7677
// and then uncommitting a granule.
7778
const zoffset offset{};
78-
if (!commit(&offset, ZGranuleSize) || !uncommit(&offset, ZGranuleSize)) {
79+
if (!commit(&offset, ZGranuleSize, -1) || !uncommit(&offset, ZGranuleSize)) {
7980
log_info_p(gc, init)("Uncommit: Implicitly Disabled (Not supported by operating system)");
8081
FLAG_SET_ERGO(ZUncommit, false);
8182
return;
@@ -189,7 +190,7 @@ size_t ZPhysicalMemoryManager::uncommit(const zoffset* pmem, size_t size) {
189190
}
190191

191192
// Map virtual memory to physical memory
192-
void ZPhysicalMemoryManager::map(zoffset offset, const zoffset* pmem, size_t size) const {
193+
void ZPhysicalMemoryManager::map(zoffset offset, const zoffset* pmem, size_t size, int numa_id) const {
193194
const zaddress_unsafe addr = ZOffset::address_unsafe(offset);
194195

195196
size_t mapped = 0;
@@ -198,6 +199,11 @@ void ZPhysicalMemoryManager::map(zoffset offset, const zoffset* pmem, size_t siz
198199
mapped += segment_size;
199200
});
200201
postcond(mapped == size);
202+
203+
// Setup NUMA preferred for large pages
204+
if (ZNUMA::is_enabled() && ZLargePages::is_explicit()) {
205+
os::numa_make_local((char*)addr, size, numa_id);
206+
}
201207
}
202208

203209
// Unmap virtual memory from physical memory

src/hotspot/share/gc/z/zPhysicalMemoryManager.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ class ZPhysicalMemoryManager {
4646
void warn_commit_limits(size_t max_capacity) const;
4747
void try_enable_uncommit(size_t min_capacity, size_t max_capacity);
4848

49-
void alloc(zoffset* pmem, size_t size, int numa_id = -1);
49+
void alloc(zoffset* pmem, size_t size, int numa_id);
5050
void free(const zoffset* pmem, size_t size, int numa_id);
5151

52-
size_t commit(const zoffset* pmem, size_t size, int numa_id = -1);
52+
size_t commit(const zoffset* pmem, size_t size, int numa_id);
5353
size_t uncommit(const zoffset* pmem, size_t size);
5454

55-
void map(zoffset offset, const zoffset* pmem, size_t size) const;
55+
void map(zoffset offset, const zoffset* pmem, size_t size, int numa_id) const;
5656
void unmap(zoffset offset, const zoffset* pmem, size_t size) const;
5757

5858
size_t count_segments(const zoffset* pmem, size_t size);

0 commit comments

Comments
 (0)