Skip to content

Commit

Permalink
8324577: [REDO] - [IMPROVE] OPEN_MAX is no longer the max limit on ma…
Browse files Browse the repository at this point in the history
…cOS >= 10.6 for RLIMIT_NOFILE

Reviewed-by: dcubed, dholmes
  • Loading branch information
Gerard Ziemski committed Apr 24, 2024
1 parent 74b11cc commit f1d0e71
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2140,16 +2140,25 @@ jint os::init_2(void) {
if (status != 0) {
log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
} else {
nbr_files.rlim_cur = nbr_files.rlim_max;

#ifdef __APPLE__
// Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if
// you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must
// be used instead
nbr_files.rlim_cur = MIN(OPEN_MAX, nbr_files.rlim_cur);
#endif
rlim_t rlim_original = nbr_files.rlim_cur;

// On macOS according to setrlimit(2), OPEN_MAX must be used instead
// of RLIM_INFINITY, but testing on macOS >= 10.6, reveals that
// we can, in fact, use even RLIM_INFINITY, so try the max value
// that the system claims can be used first, same as other BSD OSes.
// However, some terminals (ksh) will internally use "int" type
// to store this value and since RLIM_INFINITY overflows an "int"
// we might end up with a negative value, so cap the system limit max
// at INT_MAX instead, just in case, for everyone.
nbr_files.rlim_cur = MIN(INT_MAX, nbr_files.rlim_max);

status = setrlimit(RLIMIT_NOFILE, &nbr_files);
if (status != 0) {
// If that fails then try lowering the limit to either OPEN_MAX
// (which is safe) or the original limit, whichever was greater.
nbr_files.rlim_cur = MAX(OPEN_MAX, rlim_original);
status = setrlimit(RLIMIT_NOFILE, &nbr_files);
}
if (status != 0) {
log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));
}
Expand Down

3 comments on commit f1d0e71

@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 jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on f1d0e71 May 31, 2024

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 backport-TheRealMDoerr-f1d0e715 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-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 f1d0e715 from the openjdk/jdk repository.

The commit being backported was authored by Gerard Ziemski on 24 Apr 2024 and was reviewed by Daniel D. Daugherty 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/jdk21u-dev:

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

Please sign in to comment.