changeset 59432:b4ef7c2ed04a

8245757: Shenandoah: AlwaysPreTouch should not disable heap resizing or uncommits Reviewed-by: rkennke
author shade
date Tue, 26 May 2020 09:31:00 +0200
parents 4ca6fc2d0e3d
children 83e4e11e7f11
files src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp
diffstat 4 files changed, 28 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp	Tue May 26 09:30:23 2020 +0200
+++ b/src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp	Tue May 26 09:31:00 2020 +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);
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp	Tue May 26 09:30:23 2020 +0200
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp	Tue May 26 09:31:00 2020 +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;
 }
 
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp	Tue May 26 09:30:23 2020 +0200
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp	Tue May 26 09:31:00 2020 +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:
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp	Tue May 26 09:30:23 2020 +0200
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp	Tue May 26 09:31:00 2020 +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());
 }