Skip to content

Commit

Permalink
8268127: Shenandoah: Heap size may be too small for region to align t…
Browse files Browse the repository at this point in the history
…o large page size

Reviewed-by: rkennke, shade
  • Loading branch information
zhengyu123 committed Jun 8, 2021
1 parent 7a37816 commit 5ad4a91
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
14 changes: 8 additions & 6 deletions src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ void ShenandoahArguments::initialize() {

FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);
#endif

if (UseLargePages && (MaxHeapSize / os::large_page_size()) < ShenandoahHeapRegion::MIN_NUM_REGIONS) {
warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit",
os::large_page_size() / K);
FLAG_SET_DEFAULT(ShenandoahUncommit, false);
if (UseLargePages) {
size_t large_page_size = os::large_page_size();
if ((align_up(MaxHeapSize, large_page_size) / large_page_size) < ShenandoahHeapRegion::MIN_NUM_REGIONS) {
warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit",
os::large_page_size() / K);
FLAG_SET_DEFAULT(ShenandoahUncommit, false);
}
}

// Enable NUMA by default. While Shenandoah is not NUMA-aware, enabling NUMA makes
Expand Down Expand Up @@ -177,7 +179,7 @@ size_t ShenandoahArguments::conservative_max_heap_alignment() {

void ShenandoahArguments::initialize_alignments() {
// Need to setup sizes early to get correct alignments.
ShenandoahHeapRegion::setup_sizes(MaxHeapSize);
MaxHeapSize = ShenandoahHeapRegion::setup_sizes(MaxHeapSize);

// This is expected by our algorithm for ShenandoahHeap::heap_region_containing().
size_t align = ShenandoahHeapRegion::region_size_bytes();
Expand Down
29 changes: 23 additions & 6 deletions src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ size_t ShenandoahHeapRegion::block_size(const HeapWord* p) const {
}
}

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

Expand Down Expand Up @@ -542,14 +542,29 @@ void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
region_size = ShenandoahRegionSize;
}

// Make sure region size is at least one large page, if enabled.
// The heap sizes would be rounded by heap initialization code by
// page size, so we need to round up the region size too, to cover
// the heap exactly.
// Make sure region size and heap size are page aligned.
// If large pages are used, we ensure that region size is aligned to large page size if
// heap size is large enough to accommodate minimal number of regions. Otherwise, we align
// region size to regular page size.

// Figure out page size to use, and aligns up heap to page size
int page_size = os::vm_page_size();
if (UseLargePages) {
region_size = MAX2(region_size, os::large_page_size());
size_t large_page_size = os::large_page_size();
max_heap_size = align_up(max_heap_size, large_page_size);
if ((max_heap_size / align_up(region_size, large_page_size)) >= MIN_NUM_REGIONS) {
page_size = (int)large_page_size;
} else {
// Should have been checked during argument initialization
assert(!ShenandoahUncommit, "Uncommit requires region size aligns to large page size");
}
} else {
max_heap_size = align_up(max_heap_size, page_size);
}

// Align region size to page size
region_size = align_up(region_size, page_size);

int region_size_log = log2i(region_size);
// Recalculate the region size to make sure it's a power of
// 2. This means that region_size is the largest power of 2 that's
Expand Down Expand Up @@ -612,6 +627,8 @@ void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
guarantee(MaxTLABSizeBytes == 0, "we should only set it once");
MaxTLABSizeBytes = MaxTLABSizeWords * HeapWordSize;
assert (MaxTLABSizeBytes > MinTLABSize, "should be larger");

return max_heap_size;
}

void ShenandoahHeapRegion::do_commit() {
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ class ShenandoahHeapRegion {

static const size_t MIN_NUM_REGIONS = 10;

static void setup_sizes(size_t max_heap_size);
// Return adjusted max heap size
static size_t setup_sizes(size_t max_heap_size);

double empty_time() {
return _empty_time;
Expand Down

1 comment on commit 5ad4a91

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.