Skip to content

Commit

Permalink
8303215: Make thread stacks not use huge pages
Browse files Browse the repository at this point in the history
Reviewed-by: stuefe, dholmes
  • Loading branch information
Poonam Bajaj committed Jun 2, 2023
1 parent cb1e5e3 commit 59d9d9f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
20 changes: 15 additions & 5 deletions src/hotspot/os/linux/os_linux.cpp
Expand Up @@ -927,6 +927,15 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
}
assert(is_aligned(stack_size, os::vm_page_size()), "stack_size not aligned");

// Add an additional page to the stack size to reduce its chances of getting large page aligned
// so that the stack does not get backed by a transparent huge page.
size_t default_large_page_size = os::Linux::default_large_page_size();
if (default_large_page_size != 0 &&
stack_size >= default_large_page_size &&
is_aligned(stack_size, default_large_page_size)) {
stack_size += os::vm_page_size();
}

int status = pthread_attr_setstacksize(&attr, stack_size);
if (status != 0) {
// pthread_attr_setstacksize() function can fail
Expand Down Expand Up @@ -3745,8 +3754,11 @@ bool os::Linux::setup_large_page_type(size_t page_size) {
}

void os::large_page_init() {
// 1) Handle the case where we do not want to use huge pages and hence
// there is no need to scan the OS for related info
// Always initialize the default large page size even if large pages are not being used.
size_t default_large_page_size = scan_default_large_page_size();
os::Linux::_default_large_page_size = default_large_page_size;

// 1) Handle the case where we do not want to use huge pages
if (!UseLargePages &&
!UseTransparentHugePages &&
!UseHugeTLBFS &&
Expand All @@ -3764,9 +3776,7 @@ void os::large_page_init() {
return;
}

// 2) Scan OS info
size_t default_large_page_size = scan_default_large_page_size();
os::Linux::_default_large_page_size = default_large_page_size;
// 2) check if large pages are configured
if (default_large_page_size == 0) {
// No large pages configured, return.
warn_no_large_pages_configured();
Expand Down
14 changes: 11 additions & 3 deletions src/hotspot/os_cpu/linux_aarch64/globals_linux_aarch64.hpp
Expand Up @@ -30,10 +30,18 @@
// (see globals.hpp)

define_pd_global(bool, DontYieldALot, false);
define_pd_global(intx, ThreadStackSize, 2048); // 0 => use system default
define_pd_global(intx, VMThreadStackSize, 2048);

define_pd_global(intx, CompilerThreadStackSize, 2048);
// Set default stack sizes < 2MB so as to prevent stacks from getting
// large-page aligned and backed by THPs on systems where 2MB is the
// default huge page size. For non-JavaThreads, glibc may add an additional
// guard page to the total stack size, so to keep the default sizes same
// for all the following flags, we set them to 2 pages less than 2MB. On
// systems where 2MB is the default large page size, 4KB is most commonly
// the regular page size.
define_pd_global(intx, ThreadStackSize, 2040); // 0 => use system default
define_pd_global(intx, VMThreadStackSize, 2040);

define_pd_global(intx, CompilerThreadStackSize, 2040);

define_pd_global(uintx,JVMInvokeMethodSlack, 8192);

Expand Down

8 comments on commit 59d9d9f

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@TheRealMDoerr
Copy link
Contributor

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 59d9d9f Jun 22, 2023

Choose a reason for hiding this comment

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

@TheRealMDoerr the backport was successfully created on the branch TheRealMDoerr-backport-59d9d9fc in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 59d9d9fc from the openjdk/jdk repository.

The commit being backported was authored by Poonam Bajaj on 2 Jun 2023 and was reviewed by Thomas Stuefe and David Holmes.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git TheRealMDoerr-backport-59d9d9fc:TheRealMDoerr-backport-59d9d9fc
$ git checkout TheRealMDoerr-backport-59d9d9fc
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git TheRealMDoerr-backport-59d9d9fc

@openjdk
Copy link

@openjdk openjdk bot commented on 59d9d9f Aug 25, 2023

Choose a reason for hiding this comment

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

@tstuefe Could not automatically backport 59d9d9fc to openjdk/jdk11u due to conflicts in the following files:

  • src/hotspot/os/linux/os_linux.cpp

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b tstuefe-backport-59d9d9fc

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 59d9d9fcb93c26dd8931d70934b889245b050acc

# Backport the commit
$ git cherry-pick --no-commit 59d9d9fcb93c26dd8931d70934b889245b050acc
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 59d9d9fcb93c26dd8931d70934b889245b050acc'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u with the title Backport 59d9d9fcb93c26dd8931d70934b889245b050acc.

@TheRealMDoerr
Copy link
Contributor

Choose a reason for hiding this comment

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

/backport jdk11u

Not jdk11u-dev?

@tstuefe
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, probably. But I do it manually anyway, no harm done.

@tstuefe
Copy link
Member

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 59d9d9f Oct 24, 2023

Choose a reason for hiding this comment

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

@tstuefe Could not automatically backport 59d9d9fc to openjdk/jdk11u-dev due to conflicts in the following files:

  • src/hotspot/os/linux/os_linux.cpp

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b tstuefe-backport-59d9d9fc

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 59d9d9fcb93c26dd8931d70934b889245b050acc

# Backport the commit
$ git cherry-pick --no-commit 59d9d9fcb93c26dd8931d70934b889245b050acc
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 59d9d9fcb93c26dd8931d70934b889245b050acc'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 59d9d9fcb93c26dd8931d70934b889245b050acc.

Please sign in to comment.