Skip to content

Commit 264d701

Browse files
committedOct 22, 2024
8342610: ZGC: Cleanup pre-touching code
Reviewed-by: aboldtch, mli, jsikstro, eosterlund
1 parent f70ecc2 commit 264d701

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed
 

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

+25-14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "gc/z/zGeneration.inline.hpp"
3131
#include "gc/z/zGenerationId.hpp"
3232
#include "gc/z/zGlobals.hpp"
33+
#include "gc/z/zLargePages.inline.hpp"
3334
#include "gc/z/zLock.inline.hpp"
3435
#include "gc/z/zPage.inline.hpp"
3536
#include "gc/z/zPageAge.hpp"
@@ -46,6 +47,7 @@
4647
#include "runtime/globals.hpp"
4748
#include "runtime/init.hpp"
4849
#include "runtime/java.hpp"
50+
#include "runtime/os.hpp"
4951
#include "utilities/debug.hpp"
5052
#include "utilities/globalDefinitions.hpp"
5153

@@ -232,29 +234,38 @@ bool ZPageAllocator::is_initialized() const {
232234

233235
class ZPreTouchTask : public ZTask {
234236
private:
235-
const ZPhysicalMemoryManager* const _physical;
236-
volatile zoffset _start;
237-
const zoffset_end _end;
237+
volatile uintptr_t _current;
238+
const uintptr_t _end;
239+
240+
static void pretouch(zaddress zaddr, size_t size) {
241+
const uintptr_t addr = untype(zaddr);
242+
const size_t page_size = ZLargePages::is_explicit() ? ZGranuleSize : os::vm_page_size();
243+
os::pretouch_memory((void*)addr, (void*)(addr + size), page_size);
244+
}
238245

239246
public:
240-
ZPreTouchTask(const ZPhysicalMemoryManager* physical, zoffset start, zoffset_end end)
247+
ZPreTouchTask(zoffset start, zoffset_end end)
241248
: ZTask("ZPreTouchTask"),
242-
_physical(physical),
243-
_start(start),
244-
_end(end) {}
249+
_current(untype(start)),
250+
_end(untype(end)) {}
245251

246252
virtual void work() {
253+
const size_t size = ZGranuleSize;
254+
247255
for (;;) {
248-
// Get granule offset
249-
const size_t size = ZGranuleSize;
250-
const zoffset offset = to_zoffset(Atomic::fetch_then_add((uintptr_t*)&_start, size));
251-
if (offset >= _end) {
256+
// Claim an offset for this thread
257+
const uintptr_t claimed = Atomic::fetch_then_add(&_current, size);
258+
if (claimed >= _end) {
252259
// Done
253260
break;
254261
}
255262

256-
// Pre-touch granule
257-
_physical->pretouch(offset, size);
263+
// At this point we know that we have a valid zoffset / zaddress.
264+
const zoffset offset = to_zoffset(claimed);
265+
const zaddress addr = ZOffset::address(offset);
266+
267+
// Pre-touch the granule
268+
pretouch(addr, size);
258269
}
259270
}
260271
};
@@ -271,7 +282,7 @@ bool ZPageAllocator::prime_cache(ZWorkers* workers, size_t size) {
271282

272283
if (AlwaysPreTouch) {
273284
// Pre-touch page
274-
ZPreTouchTask task(&_physical, page->start(), page->end());
285+
ZPreTouchTask task(page->start(), page->end());
275286
workers->run_all(&task);
276287
}
277288

‎src/hotspot/share/gc/z/zPhysicalMemory.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,6 @@ bool ZPhysicalMemoryManager::uncommit(ZPhysicalMemory& pmem) {
357357
return true;
358358
}
359359

360-
void ZPhysicalMemoryManager::pretouch(zoffset offset, size_t size) const {
361-
const uintptr_t addr = untype(ZOffset::address(offset));
362-
const size_t page_size = ZLargePages::is_explicit() ? ZGranuleSize : os::vm_page_size();
363-
os::pretouch_memory((void*)addr, (void*)(addr + size), page_size);
364-
}
365-
366360
// Map virtual memory to physcial memory
367361
void ZPhysicalMemoryManager::map(zoffset offset, const ZPhysicalMemory& pmem) const {
368362
const zaddress_unsafe addr = ZOffset::address_unsafe(offset);

‎src/hotspot/share/gc/z/zPhysicalMemory.hpp

-6
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ class ZPhysicalMemoryManager {
8484
ZPhysicalMemoryBacking _backing;
8585
ZMemoryManager _manager;
8686

87-
void pretouch_view(zaddress addr, size_t size) const;
88-
void map_view(zaddress_unsafe addr, const ZPhysicalMemory& pmem) const;
89-
void unmap_view(zaddress_unsafe addr, size_t size) const;
90-
9187
public:
9288
ZPhysicalMemoryManager(size_t max_capacity);
9389

@@ -102,8 +98,6 @@ class ZPhysicalMemoryManager {
10298
bool commit(ZPhysicalMemory& pmem);
10399
bool uncommit(ZPhysicalMemory& pmem);
104100

105-
void pretouch(zoffset offset, size_t size) const;
106-
107101
void map(zoffset offset, const ZPhysicalMemory& pmem) const;
108102
void unmap(zoffset offset, size_t size) const;
109103
};

0 commit comments

Comments
 (0)
Please sign in to comment.