Skip to content

Commit 57d8e1e

Browse files
committed
8268127: Shenandoah: Heap size may be too small for region to align to large page size
Reviewed-by: rkennke, shade Backport-of: 5ad4a91
1 parent 4e19090 commit 57d8e1e

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ void ShenandoahArguments::initialize() {
5050

5151
FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);
5252
#endif
53-
54-
if (UseLargePages && (MaxHeapSize / os::large_page_size()) < ShenandoahHeapRegion::MIN_NUM_REGIONS) {
55-
warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit",
56-
os::large_page_size() / K);
57-
FLAG_SET_DEFAULT(ShenandoahUncommit, false);
53+
if (UseLargePages) {
54+
size_t large_page_size = os::large_page_size();
55+
if ((align_up(MaxHeapSize, large_page_size) / large_page_size) < ShenandoahHeapRegion::MIN_NUM_REGIONS) {
56+
warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit",
57+
os::large_page_size() / K);
58+
FLAG_SET_DEFAULT(ShenandoahUncommit, false);
59+
}
5860
}
5961

6062
// Enable NUMA by default. While Shenandoah is not NUMA-aware, enabling NUMA makes

src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ size_t ShenandoahHeapRegion::block_size(const HeapWord* p) const {
462462
}
463463
}
464464

465-
void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
465+
size_t ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
466466
// Absolute minimums we should not ever break.
467467
static const size_t MIN_REGION_SIZE = 256*K;
468468

@@ -537,14 +537,28 @@ void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
537537
region_size = ShenandoahRegionSize;
538538
}
539539

540-
// Make sure region size is at least one large page, if enabled.
541-
// The heap sizes would be rounded by heap initialization code by
542-
// page size, so we need to round up the region size too, to cover
543-
// the heap exactly.
540+
// Make sure region size and heap size are page aligned.
541+
// If large pages are used, we ensure that region size is aligned to large page size if
542+
// heap size is large enough to accommodate minimal number of regions. Otherwise, we align
543+
// region size to regular page size.
544+
545+
// Figure out page size to use, and aligns up heap to page size
546+
int page_size = os::vm_page_size();
544547
if (UseLargePages) {
545-
region_size = MAX2(region_size, os::large_page_size());
548+
size_t large_page_size = os::large_page_size();
549+
max_heap_size = align_up(max_heap_size, large_page_size);
550+
if ((max_heap_size / align_up(region_size, large_page_size)) >= MIN_NUM_REGIONS) {
551+
page_size = (int)large_page_size;
552+
} else {
553+
// Should have been checked during argument initialization
554+
assert(!ShenandoahUncommit, "Uncommit requires region size aligns to large page size");
555+
}
556+
} else {
557+
max_heap_size = align_up(max_heap_size, page_size);
546558
}
547559

560+
// Align region size to page size
561+
region_size = align_up(region_size, page_size);
548562
int region_size_log = log2_long((jlong) region_size);
549563
// Recalculate the region size to make sure it's a power of
550564
// 2. This means that region_size is the largest power of 2 that's
@@ -614,6 +628,8 @@ void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
614628
byte_size_in_proper_unit(HumongousThresholdBytes), proper_unit_for_byte_size(HumongousThresholdBytes));
615629
log_info(gc, init)("Max TLAB size: " SIZE_FORMAT "%s",
616630
byte_size_in_proper_unit(MaxTLABSizeBytes), proper_unit_for_byte_size(MaxTLABSizeBytes));
631+
632+
return max_heap_size;
617633
}
618634

619635
void ShenandoahHeapRegion::do_commit() {

src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ class ShenandoahHeapRegion {
250250

251251
static const size_t MIN_NUM_REGIONS = 10;
252252

253-
static void setup_sizes(size_t max_heap_size);
253+
// Return adjusted max heap size
254+
static size_t setup_sizes(size_t max_heap_size);
254255

255256
double empty_time() {
256257
return _empty_time;

0 commit comments

Comments
 (0)