Skip to content

Commit c6772e9

Browse files
committed
[AIX] Raise soft memory limits to hard limits
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 5e4505d commit c6772e9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

llvm/lib/Support/InitLLVM.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,35 @@
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 &&
45+
r.rlim_cur != r.rlim_max) {
46+
r.rlim_cur = r.rlim_max;
47+
setrlimit(resource, &r);
48+
}
49+
};
50+
51+
// Address space size.
52+
RaiseLimit(RLIMIT_AS);
53+
// Heap size.
54+
RaiseLimit(RLIMIT_DATA);
55+
// Stack size.
56+
RaiseLimit(RLIMIT_STACK);
57+
#ifdef RLIMIT_RSS
58+
// Resident set size.
59+
RaiseLimit(RLIMIT_RSS);
60+
#endif
61+
#endif
62+
}
63+
3564
void CleanupStdHandles(void *Cookie) {
3665
llvm::raw_ostream *Outs = &llvm::outs(), *Errs = &llvm::errs();
3766
Outs->flush();
@@ -67,6 +96,7 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv,
6796
StackPrinter.emplace(Argc, Argv);
6897
sys::PrintStackTraceOnErrorSignal(Argv[0]);
6998
install_out_of_memory_new_handler();
99+
RaiseLimits();
70100

71101
#ifdef __MVS__
72102

0 commit comments

Comments
 (0)