Skip to content

Commit da1eeb9

Browse files
committed
Map unmapped harvested memory before returning it to cache.
1 parent a654f7e commit da1eeb9

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,42 +83,42 @@ class ZMemory : public CHeapObj<mtGC> {
8383
ZMemory* ZMemoryManager::create(zoffset start, size_t size) {
8484
ZMemory* const area = new ZMemory(start, size);
8585
if (_callbacks._create != nullptr) {
86-
_callbacks._create(area);
86+
_callbacks._create(area->range());
8787
}
8888
return area;
8989
}
9090

9191
void ZMemoryManager::destroy(ZMemory* area) {
9292
if (_callbacks._destroy != nullptr) {
93-
_callbacks._destroy(area);
93+
_callbacks._destroy(area->range());
9494
}
9595
delete area;
9696
}
9797

9898
void ZMemoryManager::shrink_from_front(ZMemory* area, size_t size) {
9999
if (_callbacks._shrink_from_front != nullptr) {
100-
_callbacks._shrink_from_front(area, size);
100+
_callbacks._shrink_from_front(area->range(), size);
101101
}
102102
area->shrink_from_front(size);
103103
}
104104

105105
void ZMemoryManager::shrink_from_back(ZMemory* area, size_t size) {
106106
if (_callbacks._shrink_from_back != nullptr) {
107-
_callbacks._shrink_from_back(area, size);
107+
_callbacks._shrink_from_back(area->range(), size);
108108
}
109109
area->shrink_from_back(size);
110110
}
111111

112112
void ZMemoryManager::grow_from_front(ZMemory* area, size_t size) {
113113
if (_callbacks._grow_from_front != nullptr) {
114-
_callbacks._grow_from_front(area, size);
114+
_callbacks._grow_from_front(area->range(), size);
115115
}
116116
area->grow_from_front(size);
117117
}
118118

119119
void ZMemoryManager::grow_from_back(ZMemory* area, size_t size) {
120120
if (_callbacks._grow_from_back != nullptr) {
121-
_callbacks._grow_from_back(area, size);
121+
_callbacks._grow_from_back(area->range(), size);
122122
}
123123
area->grow_from_back(size);
124124
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ class ZMemoryManager {
8484
Callbacks _callbacks;
8585

8686
ZMemory* create(zoffset start, size_t size);
87-
void destroy(const ZMemoryRange& range);
88-
void shrink_from_front(const ZMemoryRange& range, size_t size);
89-
void shrink_from_back(const ZMemoryRange& range, size_t size);
90-
void grow_from_front(const ZMemoryRange& range, size_t size);
91-
void grow_from_back(const ZMemoryRange& range, size_t size);
87+
void destroy(ZMemory* area);
88+
void shrink_from_front(ZMemory* area, size_t size);
89+
void shrink_from_back(ZMemory* area, size_t size);
90+
void grow_from_front(ZMemory* area, size_t size);
91+
void grow_from_back(ZMemory* area, size_t size);
9292

9393
ZMemoryRange alloc_low_address_inner(size_t size);
9494
ZMemoryRange alloc_low_address_at_most_inner(size_t size);

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,8 @@ void ZPageAllocator::harvest_claimed_physical(ZPageAllocation* allocation) {
841841
segments.stash(allocation->claimed_mappings());
842842

843843
// Shuffle vmem. We allocate enough memory to cover the entire allocation size, not just the harvested memory.
844+
// If we fail to allocate additional virtual memory, the allocated virtual memory will match the harvested amount
845+
// instead of the allocation request.
844846
_virtual.shuffle_vmem_to_low_addresses_contiguous(allocation->size(), allocation->claimed_mappings());
845847

846848
// Restore segments
@@ -933,9 +935,18 @@ ZPage* ZPageAllocator::alloc_page_inner(ZPageAllocation* allocation) {
933935
allocation->claimed_mappings()->append(vmem);
934936
}
935937

936-
// Check if we've successfully gotten a large enough virtual address range
938+
// Check if we've successfully gotten a large enough virtual address range.
937939
if (!is_alloc_satisfied(allocation)) {
938940
log_error(gc)("Out of address space");
941+
942+
// The harvested memory has not been mapped yet. Map it before we put it back into the cache.
943+
if (allocation->harvested() > 0) {
944+
ZArrayIterator<ZMemoryRange> iter(allocation->claimed_mappings());
945+
for (ZMemoryRange vmem; iter.next(&vmem);) {
946+
map_virtual_to_physical(vmem);
947+
}
948+
}
949+
939950
free_memory_alloc_failed(allocation);
940951
return nullptr;
941952
}

0 commit comments

Comments
 (0)