-
Notifications
You must be signed in to change notification settings - Fork 396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix omrsysinfo_get_limit/omrsysinfo_set_limit API reporting of hard limits on macOS #4990
Comments
@rwy0717 you played around with a C test case. Could you upload it to this issue so we don't lose track of that once we get some resources to be able to fix this? |
It's very very rough, but here: #include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <fcntl.h>
static size_t files_opened = 3;
int open_to(size_t n) {
printf("opening to: %lu\n", n);
while (files_opened < n) {
char name[PATH_MAX];
sprintf(name, "/tmp/max_open-%d", files_opened);
int fd = open(name, O_CREAT | O_RDWR);
if (fd < 0) {
printf("failed to open file no=%zu\n", files_opened + 1);
return -1;
}
files_opened += 1;
}
printf("success\n");
return 0;
}
extern "C" int main() {
struct rlimit rlim;
getrlimit(RLIMIT_NOFILE, &rlim);
int name[2] = { CTL_KERN, KERN_MAXFILESPERPROC };
int sysctl_max = 1;
size_t len = sizeof(sysctl_max);
sysctl(name, 2, &sysctl_max, &len, NULL, 0);
printf("** initial report\n");
printf("OPEN_MAX = %d\n", OPEN_MAX);
printf("rlim.rlim_cur = %llu\n", rlim.rlim_cur);
printf("rlim.rlim_max = %llu\n", rlim.rlim_max);
printf("sysctl_max = %d\n", sysctl_max);
///////////////
{
struct rlimit new_lim = rlim;
new_lim.rlim_max = rlim.rlim_max - 32;
int err = setrlimit(RLIMIT_NOFILE, &new_lim);
printf("** set rlim_max to (rlim_max - 32): %d\n", err);
}
getrlimit(RLIMIT_NOFILE, &rlim);
sysctl(name, 2, &sysctl_max, &len, NULL, 0);
printf("OPEN_MAX = %d\n", OPEN_MAX);
printf("rlim.rlim_cur = %llu\n", rlim.rlim_cur);
printf("rlim.rlim_max = %llu\n", rlim.rlim_max);
printf("sysctl_max = %d\n", sysctl_max);
//////////////////
{
struct rlimit new_lim = rlim;
new_lim.rlim_max = sysctl_max + 32;
int err = setrlimit(RLIMIT_NOFILE, &new_lim);
printf("** set rlim_max to sysctl_max + 32: %d\n", err);
}
getrlimit(RLIMIT_NOFILE, &rlim);
sysctl(name, 2, &sysctl_max, &len, NULL, 0);
printf("OPEN_MAX = %d\n", OPEN_MAX);
printf("rlim.rlim_cur = %llu\n", rlim.rlim_cur);
printf("rlim.rlim_max = %llu\n", rlim.rlim_max);
printf("sysctl_max = %d\n", sysctl_max);
//////////////////
{
struct rlimit new_lim = rlim;
new_lim.rlim_max = rlim.rlim_cur + 32;
int err = setrlimit(RLIMIT_NOFILE, &new_lim);
printf("** set rlim_max to rlim_cur + 32: %d\n", err);
}
getrlimit(RLIMIT_NOFILE, &rlim);
sysctl(name, 2, &sysctl_max, &len, NULL, 0);
printf("OPEN_MAX = %d\n", OPEN_MAX);
printf("rlim.rlim_cur = %llu\n", rlim.rlim_cur);
printf("rlim.rlim_max = %llu\n", rlim.rlim_max);
printf("sysctl_max = %d\n", sysctl_max);
//////////////////
open_to(sysctl_max);
return 0;
//////////////////
struct rlimit new_lim = rlim;
new_lim.rlim_cur = OPEN_MAX;
int err = setrlimit(RLIMIT_NOFILE, &new_lim);
printf("set to OPEN_MAX: %d\n", err);
open_to(OPEN_MAX);
new_lim.rlim_cur = sysctl_max;
err = setrlimit(RLIMIT_NOFILE, &new_lim);
printf("set to sysctl_max: %d\n", err);
open_to(sysctl_max);
new_lim.rlim_cur = sysctl_max + 1;
err = setrlimit(RLIMIT_NOFILE, &new_lim);
printf("set to sysctl_max + 1: %d\n", err);
open_to(sysctl_max + 1);
new_lim.rlim_cur = rlim.rlim_max;
err = setrlimit(RLIMIT_NOFILE, &new_lim);
printf("set to rlim_max: %d\n", err);
open_to(rlim.rlim_max);
return 0;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
During a Slack discussion [1] which I'll quote here:
It was identified that the hard limit values returned by
omrsysinfo_get_limit
may not be the true limit that we can set the soft file descriptor limit to. As perthe above example, callingomrsysinfo_set_limit
to update the soft limit to the reported hard limit would fail on macOS depending on system configuration.Various solutions were discussed and it seems there was general concensus that we should report the hard limit which we can acutally set, iregardless of what the system reports as the hard limit. Another quote said:
We should investigate a path forward, and revert the change which disables this test in #4980.
[1] https://eclipse-omr.slack.com/archives/C010F8XPRT9/p1584990621015600
The text was updated successfully, but these errors were encountered: