Skip to content

Commit 5c10a79

Browse files
committed
Implementation of a mapped cache
1 parent 9346984 commit 5c10a79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2909
-1675
lines changed

src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -628,30 +628,11 @@ bool ZPhysicalMemoryBacking::commit_inner(zoffset offset, size_t length) const {
628628
return true;
629629
}
630630

631-
static int offset_to_node(zoffset offset) {
632-
const GrowableArray<int>* mapping = os::Linux::numa_nindex_to_node();
633-
const size_t nindex = (untype(offset) >> ZGranuleSizeShift) % mapping->length();
634-
return mapping->at((int)nindex);
635-
}
636-
637-
size_t ZPhysicalMemoryBacking::commit_numa_interleaved(zoffset offset, size_t length) const {
638-
size_t committed = 0;
639-
640-
// Commit one granule at a time, so that each granule
641-
// can be allocated from a different preferred node.
642-
while (committed < length) {
643-
const zoffset granule_offset = offset + committed;
644-
645-
// Setup NUMA policy to allocate memory from a preferred node
646-
os::Linux::numa_set_preferred(offset_to_node(granule_offset));
631+
size_t ZPhysicalMemoryBacking::commit_numa_preferred(zoffset offset, size_t length, int numa_id) const {
632+
// Setup NUMA policy to allocate memory from a preferred node
633+
os::Linux::numa_set_preferred(numa_id);
647634

648-
if (!commit_inner(granule_offset, ZGranuleSize)) {
649-
// Failed
650-
break;
651-
}
652-
653-
committed += ZGranuleSize;
654-
}
635+
size_t committed = commit_default(offset, length);
655636

656637
// Restore NUMA policy
657638
os::Linux::numa_set_preferred(-1);
@@ -687,11 +668,9 @@ size_t ZPhysicalMemoryBacking::commit_default(zoffset offset, size_t length) con
687668
}
688669
}
689670

690-
size_t ZPhysicalMemoryBacking::commit(zoffset offset, size_t length) const {
691-
if (ZNUMA::is_enabled() && !ZLargePages::is_explicit()) {
692-
// To get granule-level NUMA interleaving when using non-large pages,
693-
// we must explicitly interleave the memory at commit/fallocate time.
694-
return commit_numa_interleaved(offset, length);
671+
size_t ZPhysicalMemoryBacking::commit(zoffset offset, size_t length, int numa_id) const {
672+
if (ZNUMA::is_enabled()) {
673+
return commit_numa_preferred(offset, length, numa_id);
695674
}
696675

697676
return commit_default(offset, length);

src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ZPhysicalMemoryBacking {
5959
ZErrno fallocate(bool punch_hole, zoffset offset, size_t length) const;
6060

6161
bool commit_inner(zoffset offset, size_t length) const;
62-
size_t commit_numa_interleaved(zoffset offset, size_t length) const;
62+
size_t commit_numa_preferred(zoffset offset, size_t length, int numa_id) const;
6363
size_t commit_default(zoffset offset, size_t length) const;
6464

6565
public:
@@ -69,7 +69,7 @@ class ZPhysicalMemoryBacking {
6969

7070
void warn_commit_limits(size_t max_capacity) const;
7171

72-
size_t commit(zoffset offset, size_t length) const;
72+
size_t commit(zoffset offset, size_t length, int numa_id) const;
7373
size_t uncommit(zoffset offset, size_t length) const;
7474

7575
void map(zaddress_unsafe addr, size_t size, zoffset offset) const;

src/hotspot/os/windows/gc/z/zVirtualMemory_windows.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "gc/z/zLargePages.inline.hpp"
2828
#include "gc/z/zMapper_windows.hpp"
2929
#include "gc/z/zSyscall_windows.hpp"
30+
#include "gc/z/zValue.inline.hpp"
3031
#include "gc/z/zVirtualMemory.inline.hpp"
3132
#include "utilities/align.hpp"
3233
#include "utilities/debug.hpp"
@@ -222,7 +223,7 @@ void ZVirtualMemoryManager::pd_initialize_before_reserve() {
222223
}
223224

224225
void ZVirtualMemoryManager::pd_initialize_after_reserve() {
225-
_impl->initialize_after_reserve(&_manager);
226+
_impl->initialize_after_reserve(&_managers.get(0));
226227
}
227228

228229
bool ZVirtualMemoryManager::pd_reserve(zaddress_unsafe addr, size_t size) {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,8 @@ typedef ZAttachedArray<ZForwarding, ZForwardingEntry> ZAttachedArrayForForwardin
8383
\
8484
nonstatic_field(ZPage, _type, const ZPageType) \
8585
volatile_nonstatic_field(ZPage, _seqnum, uint32_t) \
86-
nonstatic_field(ZPage, _virtual, const ZVirtualMemory) \
8786
volatile_nonstatic_field(ZPage, _top, zoffset_end) \
8887
\
89-
nonstatic_field(ZPageAllocator, _max_capacity, const size_t) \
90-
volatile_nonstatic_field(ZPageAllocator, _capacity, size_t) \
91-
volatile_nonstatic_field(ZPageAllocator, _used, size_t) \
92-
\
9388
nonstatic_field(ZPageTable, _map, ZGranuleMapForPageTable) \
9489
\
9590
nonstatic_field(ZGranuleMapForPageTable, _map, ZPage** const) \

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,22 @@
3131
// Allocation flags layout
3232
// -----------------------
3333
//
34-
// 7 2 1 0
35-
// +-----+-+-+-+
36-
// |00000|1|1|1|
37-
// +-----+-+-+-+
38-
// | | | |
39-
// | | | * 0-0 Non-Blocking Flag (1-bit)
40-
// | | |
41-
// | | * 1-1 GC Relocation Flag (1-bit)
42-
// | |
43-
// | * 2-2 Low Address Flag (1-bit)
34+
// 7 1 0
35+
// +-------+-+-+
36+
// |0000000|1|1|
37+
// +-------+-+-+
38+
// | | |
39+
// | | * 0-0 Non-Blocking Flag (1-bit)
40+
// | |
41+
// | * 1-1 GC Relocation Flag (1-bit)
4442
// |
45-
// * 7-3 Unused (5-bits)
43+
// * 7-2 Unused (6-bits)
4644
//
4745

4846
class ZAllocationFlags {
4947
private:
5048
typedef ZBitField<uint8_t, bool, 0, 1> field_non_blocking;
5149
typedef ZBitField<uint8_t, bool, 1, 1> field_gc_relocation;
52-
typedef ZBitField<uint8_t, bool, 2, 1> field_low_address;
5350

5451
uint8_t _flags;
5552

@@ -65,21 +62,13 @@ class ZAllocationFlags {
6562
_flags |= field_gc_relocation::encode(true);
6663
}
6764

68-
void set_low_address() {
69-
_flags |= field_low_address::encode(true);
70-
}
71-
7265
bool non_blocking() const {
7366
return field_non_blocking::decode(_flags);
7467
}
7568

7669
bool gc_relocation() const {
7770
return field_gc_relocation::decode(_flags);
7871
}
79-
80-
bool low_address() const {
81-
return field_low_address::decode(_flags);
82-
}
8372
};
8473

8574
#endif // SHARE_GC_Z_ZALLOCATIONFLAGS_HPP

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,6 @@ void ZGeneration::select_relocation_set(ZGenerationId generation, bool promote_a
195195
for (ZPage* page; pt_iter.next(&page);) {
196196
if (!page->is_relocatable()) {
197197
// Not relocatable, don't register
198-
// Note that the seqnum can change under our feet here as the page
199-
// can be concurrently freed and recycled by a concurrent generation
200-
// collection. However this property is stable across such transitions.
201-
// If it was not relocatable before recycling, then it won't be
202-
// relocatable after it gets recycled either, as the seqnum atomically
203-
// becomes allocating for the given generation. The opposite property
204-
// also holds: if the page is relocatable, then it can't have been
205-
// concurrently freed; if it was re-allocated it would not be
206-
// relocatable, and if it was not re-allocated we know that it was
207-
// allocated earlier than mark start of the current generation
208-
// collection.
209198
continue;
210199
}
211200

@@ -218,15 +207,14 @@ void ZGeneration::select_relocation_set(ZGenerationId generation, bool promote_a
218207

219208
// Reclaim empty pages in bulk
220209

221-
// An active iterator blocks immediate recycle and delete of pages.
222-
// The intent it to allow the code that iterates over the pages to
223-
// safely read the properties of the pages without them being changed
224-
// by another thread. However, this function both iterates over the
225-
// pages AND frees/recycles them. We "yield" the iterator, so that we
226-
// can perform immediate recycling (as long as no other thread is
227-
// iterating over the pages). The contract is that the pages that are
228-
// about to be freed are "owned" by this thread, and no other thread
229-
// will change their states.
210+
// An active iterator blocks immediate deletion of pages. The intent is
211+
// to allow the code that iterates over pages to safely read properties
212+
// of the pages without them being freed/deleted. However, this function
213+
// both iterates over the pages AND frees them. We "yield" the iterator,
214+
// so that we can perform immediate deletion (as long as no other thread
215+
// is iterating over the pages). The contract is that the pages that are
216+
// about to be freed are "owned" by this thread, and no other thread will
217+
// change their states.
230218
pt_iter.yield([&]() {
231219
free_empty_pages(&selector, 64 /* bulk */);
232220
});
@@ -939,7 +927,7 @@ void ZGenerationYoung::flip_promote(ZPage* from_page, ZPage* to_page) {
939927
_page_table->replace(from_page, to_page);
940928

941929
// Update statistics
942-
_page_allocator->promote_used(from_page->size());
930+
_page_allocator->promote_used(from_page, to_page);
943931
increase_freed(from_page->size());
944932
increase_promoted(from_page->live_bytes());
945933
}
@@ -948,7 +936,7 @@ void ZGenerationYoung::in_place_relocate_promote(ZPage* from_page, ZPage* to_pag
948936
_page_table->replace(from_page, to_page);
949937

950938
// Update statistics
951-
_page_allocator->promote_used(from_page->size());
939+
_page_allocator->promote_used(from_page, to_page);
952940
}
953941

954942
void ZGenerationYoung::register_flip_promoted(const ZArray<ZPage*>& pages) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class ZGranuleMap {
4949
~ZGranuleMap();
5050

5151
T get(zoffset offset) const;
52+
T* get_addr(zoffset offset) const;
5253
void put(zoffset offset, T value);
5354
void put(zoffset offset, size_t size, T value);
5455

src/hotspot/share/gc/z/zGranuleMap.inline.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ inline T ZGranuleMap<T>::get(zoffset offset) const {
6666
return at(index);
6767
}
6868

69+
template <typename T>
70+
inline T* ZGranuleMap<T>::get_addr(zoffset offset) const {
71+
const size_t index = index_for_offset(offset);
72+
return _map + index;
73+
}
74+
6975
template <typename T>
7076
inline void ZGranuleMap<T>::put(zoffset offset, T value) {
7177
const size_t index = index_for_offset(offset);

0 commit comments

Comments
 (0)