Skip to content

Commit 6360bbb

Browse files
authored
[AIX] Raise soft memory limits to hard limits (#167928)
AIX out-of-box memory soft limits are often insufficient to run LLVM on reasonably size inputs. Thus, we often encounter users who run into spurious out of memory errors. This change raises the memory soft limits to the hard limits at LLVM startup to prevent these types of issues.
1 parent aa4de7b commit 6360bbb

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

llvm/lib/Support/InitLLVM.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@
3232
#endif
3333
#endif
3434

35+
static void RaiseLimits() {
36+
#ifdef _AIX
37+
// AIX has restrictive memory soft-limits out-of-box, so raise them if needed.
38+
auto RaiseLimit = [](int resource) {
39+
struct rlimit r;
40+
getrlimit(resource, &r);
41+
42+
// Increase the soft limit to the hard limit, if necessary and
43+
// possible.
44+
if (r.rlim_cur != RLIM_INFINITY && r.rlim_cur != r.rlim_max) {
45+
r.rlim_cur = r.rlim_max;
46+
setrlimit(resource, &r);
47+
}
48+
};
49+
50+
// Address space size.
51+
RaiseLimit(RLIMIT_AS);
52+
// Heap size.
53+
RaiseLimit(RLIMIT_DATA);
54+
// Stack size.
55+
RaiseLimit(RLIMIT_STACK);
56+
#ifdef RLIMIT_RSS
57+
// Resident set size.
58+
RaiseLimit(RLIMIT_RSS);
59+
#endif
60+
#endif
61+
}
62+
3563
void CleanupStdHandles(void *Cookie) {
3664
llvm::raw_ostream *Outs = &llvm::outs(), *Errs = &llvm::errs();
3765
Outs->flush();
@@ -67,6 +95,7 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv,
6795
StackPrinter.emplace(Argc, Argv);
6896
sys::PrintStackTraceOnErrorSignal(Argv[0]);
6997
install_out_of_memory_new_handler();
98+
RaiseLimits();
7099

71100
#ifdef __MVS__
72101

0 commit comments

Comments
 (0)