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
Backport-of: 5ad4a91
  • Loading branch information
zhengyu123 committed Jun 16, 2021
1 parent 4e19090 commit 57d8e1e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,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
28 changes: 22 additions & 6 deletions src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,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 @@ -537,14 +537,28 @@ 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 = log2_long((jlong) 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 @@ -614,6 +628,8 @@ void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
byte_size_in_proper_unit(HumongousThresholdBytes), proper_unit_for_byte_size(HumongousThresholdBytes));
log_info(gc, init)("Max TLAB size: " SIZE_FORMAT "%s",
byte_size_in_proper_unit(MaxTLABSizeBytes), proper_unit_for_byte_size(MaxTLABSizeBytes));

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 @@ -250,7 +250,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 57d8e1e

@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.