Skip to content

Conversation

@albertnetymk
Copy link
Member

@albertnetymk albertnetymk commented Aug 8, 2025

Refactor the heap-space and OS memory interface code to clearly separate two related but distinct concepts: alignment and os-page-size. These are now represented as two fields in PSVirtualSpace.

The parallel heap consists of four spaces: old, eden, from, and to. The first belongs to the old generation, while the latter three belong to the young generation.

The size of any space is always aligned to alignment, which also determines the unit for resizing. To keep the implementation simple while allowing flexible per-space commit and uncommit operations, each space must contain at least one OS page. As a result, alignment is always greater than or equal to os-page-size.

When using explicit large pages -- which require pre-allocating large pages before the VM starts -- the actual OS page size is not known until the heap has been reserved. The additional logic in ParallelScavengeHeap::initialize detects the OS page size in use and adjusts alignment if necessary.

Test: tier1–8


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8346005: Parallel: Incorrect page size calculation with UseLargePages (Bug - P4)

Reviewers

Contributors

  • Joel Sikström <jsikstro@openjdk.org>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26700/head:pull/26700
$ git checkout pull/26700

Update a local copy of the PR:
$ git checkout pull/26700
$ git pull https://git.openjdk.org/jdk.git pull/26700/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26700

View PR using the GUI difftool:
$ git pr show -t 26700

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26700.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 8, 2025

👋 Welcome back ayang! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 8, 2025

@albertnetymk This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8346005: Parallel: Incorrect page size calculation with UseLargePages

Co-authored-by: Joel Sikström <jsikstro@openjdk.org>
Reviewed-by: jsikstro, fandreuzzi

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 97 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot changed the title 8346005 8346005: Parallel: Incorrect page size calculation with UseLargePages Aug 8, 2025
@openjdk
Copy link

openjdk bot commented Aug 8, 2025

@albertnetymk The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Aug 8, 2025
@albertnetymk
Copy link
Member Author

/cc hotspot-gc

@openjdk openjdk bot added rfr Pull request is ready for review hotspot-gc hotspot-gc-dev@openjdk.org labels Aug 8, 2025
@openjdk
Copy link

openjdk bot commented Aug 8, 2025

@albertnetymk
The hotspot-gc label was successfully added.

@mlbridge
Copy link

mlbridge bot commented Aug 8, 2025

@albertnetymk
Copy link
Member Author

Minor updates after JDK-8366434, as the page-size of reserved-memory reflects the intended/actual OS page-size, when using transparent huge pages.

@openjdk openjdk bot removed the hotspot-gc hotspot-gc-dev@openjdk.org label Sep 25, 2025
@albertnetymk
Copy link
Member Author

/cc hotspot-gc

@albertnetymk
Copy link
Member Author

/touch

@openjdk openjdk bot added the hotspot-gc hotspot-gc-dev@openjdk.org label Sep 29, 2025
@openjdk
Copy link

openjdk bot commented Sep 29, 2025

@albertnetymk
The hotspot-gc label was successfully added.

@openjdk
Copy link

openjdk bot commented Sep 29, 2025

@albertnetymk The pull request is being re-evaluated and the inactivity timeout has been reset.

Copy link
Member

@jsikstro jsikstro left a comment

Choose a reason for hiding this comment

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

Reviewing this is taking some time, so this is not a full review yet, but so far I have some comments:

Why do we need the dance with Parallel being able to set a specific desired_page_size in Universe::reserve_heap()? Maybe I'm wrong, but would it not work to disable UseLargePages early and not have specific logic for Parallel?

// ReservedSpace passed to initialize() must be aligned to this value.
const size_t _alignment;

// OS page size used. If using transparent large pages, it's the desired large page-size.
Copy link
Member

Choose a reason for hiding this comment

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

I'd change this to say Transparent Huge Pages instead.


public:
protected:
size_t page_size() const { return _page_size; }
Copy link
Member

Choose a reason for hiding this comment

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

We should vertically align this with the other blocks.


if (page_sz == os::vm_page_size()) {
log_warning(gc, heap)("MinHeapSize (%zu) must be large enough for 4 * page-size; Disabling UseLargePages for heap", MinHeapSize);
return;
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it make sense to do FLAG_SET_ERGO(UseLargepages, false) here since it is effectively disabled.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are non-heap uses of UseLargePages as well. Here we concluded heap can't use large-page, but other systems still can.

Copy link
Member

Choose a reason for hiding this comment

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

I see, thank you.

assert(is_power_of_2((intptr_t)page_sz), "must be a power of 2");
size_t new_alignment = align_up(page_sz, SpaceAlignment);
// Space is largepage-aligned.
size_t new_alignment = page_sz;
Copy link
Member

Choose a reason for hiding this comment

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

To me it looks like new_alignment will always be different from SpaceAlignment here. We could simplify this to the following:

  SpaceAlignment = page_sz;
    
  // Redo everything from the start
  initialize_heap_flags_and_sizes_one_pass();

Copy link
Member Author

Choose a reason for hiding this comment

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

To me it looks like new_alignment will always be different from SpaceAlignment here.

Why so? (I know the default value of SpaceAlignment is 64K*8 bytes, which is not a common large-page-size, but that info is not directly accessible in this context.)

Copy link
Member

Choose a reason for hiding this comment

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

We discussed this offline, but if default_space_alignment() ever coincided with a Large page size, say 2MB, and 2MB large pages are chosen, SpaceAlignment would still be equal to default_space_alignment() and we would end up reserving small pages in ParallelScavengeHeap::initialize().

Copy link
Member Author

@albertnetymk albertnetymk left a comment

Choose a reason for hiding this comment

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

Why do we need the dance with Parallel being able to set a specific desired_page_size in Universe::reserve_heap()?

Because heap contains subspaces (eden,from,to,old) which needs to be larger than a OS-page in Parallel. Maybe this doesn't have to be this way, but that's what Parallel NUMA relies on currently. It would be much more invasive to change that.


if (page_sz == os::vm_page_size()) {
log_warning(gc, heap)("MinHeapSize (%zu) must be large enough for 4 * page-size; Disabling UseLargePages for heap", MinHeapSize);
return;
Copy link
Member Author

Choose a reason for hiding this comment

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

There are non-heap uses of UseLargePages as well. Here we concluded heap can't use large-page, but other systems still can.

assert(is_power_of_2((intptr_t)page_sz), "must be a power of 2");
size_t new_alignment = align_up(page_sz, SpaceAlignment);
// Space is largepage-aligned.
size_t new_alignment = page_sz;
Copy link
Member Author

Choose a reason for hiding this comment

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

To me it looks like new_alignment will always be different from SpaceAlignment here.

Why so? (I know the default value of SpaceAlignment is 64K*8 bytes, which is not a common large-page-size, but that info is not directly accessible in this context.)

@albertnetymk
Copy link
Member Author

/contributor add jsikstro

@openjdk
Copy link

openjdk bot commented Oct 3, 2025

@albertnetymk
Contributor Joel Sikström <jsikstro@openjdk.org> successfully added.

Copy link
Member

@jsikstro jsikstro left a comment

Choose a reason for hiding this comment

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

I have a few small comments, but I think this looks pretty good now.

void increment_samples_count() { ++_samples_count; }

size_t _base_space_size;
void set_base_space_size(size_t v) { _base_space_size = v; }
Copy link
Member

Choose a reason for hiding this comment

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

These are unused.

Comment on lines 359 to 368
} else {
if (i < lgrp_spaces()->length() - 1) { // Middle chunks
MutableSpace *ps = lgrp_spaces()->at(i - 1)->space();
new_region = MemRegion(ps->end(),
ps->end() + (chunk_byte_size >> LogHeapWordSize));
chunk_byte_size >> LogHeapWordSize);
} else { // Top chunk
MutableSpace *ps = lgrp_spaces()->at(i - 1)->space();
new_region = MemRegion(ps->end(), end());
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This is technically fine, but maybe we can combine the else and the if to something like below to fit better with the comments?

if (i == 0) { // Bottom chunk
...
} else if (i < lgrp_spaces()->length() - 1) { // Middle chunks
...
} else { // Top chunk
...
}

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 10, 2025
@albertnetymk
Copy link
Member Author

Thanks for review.

/integrate

@openjdk
Copy link

openjdk bot commented Oct 21, 2025

Going to push as commit 2be273f.
Since your change was applied there have been 111 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 21, 2025
@openjdk openjdk bot closed this Oct 21, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 21, 2025
@openjdk
Copy link

openjdk bot commented Oct 21, 2025

@albertnetymk Pushed as commit 2be273f.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@albertnetymk albertnetymk deleted the pgc-largepage branch October 21, 2025 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot hotspot-dev@openjdk.org hotspot-gc hotspot-gc-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants