--- old/src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp 2020-05-25 21:23:24.457812757 +0200 +++ new/src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp 2020-05-25 21:23:24.145812625 +0200 @@ -148,13 +148,6 @@ FLAG_SET_DEFAULT(LogEventsBufferEntries, 250); } - if (AlwaysPreTouch) { - if (!FLAG_IS_DEFAULT(ShenandoahUncommit)) { - warning("AlwaysPreTouch is enabled, disabling ShenandoahUncommit"); - } - FLAG_SET_DEFAULT(ShenandoahUncommit, false); - } - if ((InitialHeapSize == MaxHeapSize) && ShenandoahUncommit) { log_info(gc)("Min heap equals to max heap, disabling ShenandoahUncommit"); FLAG_SET_DEFAULT(ShenandoahUncommit, false); --- old/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp 2020-05-25 21:23:25.205813071 +0200 +++ new/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp 2020-05-25 21:23:24.893812940 +0200 @@ -110,7 +110,9 @@ virtual void work(uint worker_id) { ShenandoahHeapRegion* r = _regions.next(); while (r != NULL) { - os::pretouch_memory(r->bottom(), r->end(), _page_size); + if (r->is_committed()) { + os::pretouch_memory(r->bottom(), r->end(), _page_size); + } r = _regions.next(); } } @@ -136,7 +138,9 @@ size_t end = (r->index() + 1) * ShenandoahHeapRegion::region_size_bytes() / MarkBitMap::heap_map_factor(); assert (end <= _bitmap_size, "end is sane: " SIZE_FORMAT " < " SIZE_FORMAT, end, _bitmap_size); - os::pretouch_memory(_bitmap_base + start, _bitmap_base + end, _page_size); + if (r->is_committed()) { + os::pretouch_memory(_bitmap_base + start, _bitmap_base + end, _page_size); + } r = _regions.next(); } @@ -155,11 +159,6 @@ size_t reg_size_bytes = ShenandoahHeapRegion::region_size_bytes(); - if (AlwaysPreTouch) { - // Enabled pre-touch means the entire heap is committed right away. - init_byte_size = max_byte_size; - } - Universe::check_alignment(max_byte_size, reg_size_bytes, "Shenandoah heap"); Universe::check_alignment(init_byte_size, reg_size_bytes, "Shenandoah heap"); @@ -350,30 +349,26 @@ // we touch the region and the corresponding bitmaps from the same thread. ShenandoahPushWorkerScope scope(workers(), _max_workers, false); - size_t pretouch_heap_page_size = heap_page_size; - size_t pretouch_bitmap_page_size = bitmap_page_size; + _pretouch_heap_page_size = heap_page_size; + _pretouch_bitmap_page_size = bitmap_page_size; #ifdef LINUX // UseTransparentHugePages would madvise that backing memory can be coalesced into huge // pages. But, the kernel needs to know that every small page is used, in order to coalesce // them into huge one. Therefore, we need to pretouch with smaller pages. if (UseTransparentHugePages) { - pretouch_heap_page_size = (size_t)os::vm_page_size(); - pretouch_bitmap_page_size = (size_t)os::vm_page_size(); + _pretouch_heap_page_size = (size_t)os::vm_page_size(); + _pretouch_bitmap_page_size = (size_t)os::vm_page_size(); } #endif // OS memory managers may want to coalesce back-to-back pages. Make their jobs // simpler by pre-touching continuous spaces (heap and bitmap) separately. - log_info(gc, init)("Pretouch bitmap: " SIZE_FORMAT " regions, " SIZE_FORMAT " bytes page", - _num_regions, pretouch_bitmap_page_size); - ShenandoahPretouchBitmapTask bcl(bitmap.base(), _bitmap_size, pretouch_bitmap_page_size); + ShenandoahPretouchBitmapTask bcl(bitmap.base(), _bitmap_size, _pretouch_bitmap_page_size); _workers->run_task(&bcl); - log_info(gc, init)("Pretouch heap: " SIZE_FORMAT " regions, " SIZE_FORMAT " bytes page", - _num_regions, pretouch_heap_page_size); - ShenandoahPretouchHeapTask hcl(pretouch_heap_page_size); + ShenandoahPretouchHeapTask hcl(_pretouch_heap_page_size); _workers->run_task(&hcl); } @@ -2685,9 +2680,16 @@ size_t slice = r->index() / _bitmap_regions_per_slice; size_t off = _bitmap_bytes_per_slice * slice; size_t len = _bitmap_bytes_per_slice; - if (!os::commit_memory((char*)_bitmap_region.start() + off, len, false)) { + char* start = (char*) _bitmap_region.start() + off; + + if (!os::commit_memory(start, len, false)) { return false; } + + if (AlwaysPreTouch) { + os::pretouch_memory(start, start + len, _pretouch_bitmap_page_size); + } + return true; } --- old/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp 2020-05-25 21:23:26.001813404 +0200 +++ new/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp 2020-05-25 21:23:25.697813277 +0200 @@ -629,6 +629,9 @@ size_t _bitmap_regions_per_slice; size_t _bitmap_bytes_per_slice; + size_t _pretouch_heap_page_size; + size_t _pretouch_bitmap_page_size; + bool _bitmap_region_special; bool _aux_bitmap_region_special; @@ -665,6 +668,8 @@ ShenandoahLiveData* get_liveness_cache(uint worker_id); void flush_liveness_cache(uint worker_id); + size_t pretouch_heap_page_size() { return _pretouch_heap_page_size; } + // ---------- Evacuation support // private: --- old/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp 2020-05-25 21:23:26.789813734 +0200 +++ new/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp 2020-05-25 21:23:26.477813603 +0200 @@ -626,6 +626,9 @@ if (!heap->commit_bitmap_slice(this)) { report_java_out_of_memory("Unable to commit bitmaps for region"); } + if (AlwaysPreTouch) { + os::pretouch_memory(bottom(), end(), heap->pretouch_heap_page_size()); + } heap->increase_committed(ShenandoahHeapRegion::region_size_bytes()); }