From c6772e9d22b5d6e035fdc49276b4091de9013f55 Mon Sep 17 00:00:00 2001 From: David Tenty Date: Fri, 7 Nov 2025 00:54:17 -0500 Subject: [PATCH 1/2] [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. --- llvm/lib/Support/InitLLVM.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/llvm/lib/Support/InitLLVM.cpp b/llvm/lib/Support/InitLLVM.cpp index b8fbfd21c4f28..5c0f206d389de 100644 --- a/llvm/lib/Support/InitLLVM.cpp +++ b/llvm/lib/Support/InitLLVM.cpp @@ -32,6 +32,35 @@ #endif #endif +static void RaiseLimits() { +#ifdef _AIX + // AIX has restrictive memory soft-limits out-of-box, so raise them if needed. + auto RaiseLimit = [](int resource) { + struct rlimit r; + getrlimit(resource, &r); + + // Increase the soft limit to the hard limit, if necessary and + // possible. + if (r.rlim_cur != RLIM_INFINITY && + r.rlim_cur != r.rlim_max) { + r.rlim_cur = r.rlim_max; + setrlimit(resource, &r); + } + }; + + // Address space size. + RaiseLimit(RLIMIT_AS); + // Heap size. + RaiseLimit(RLIMIT_DATA); + // Stack size. + RaiseLimit(RLIMIT_STACK); +#ifdef RLIMIT_RSS + // Resident set size. + RaiseLimit(RLIMIT_RSS); +#endif +#endif +} + void CleanupStdHandles(void *Cookie) { llvm::raw_ostream *Outs = &llvm::outs(), *Errs = &llvm::errs(); Outs->flush(); @@ -67,6 +96,7 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv, StackPrinter.emplace(Argc, Argv); sys::PrintStackTraceOnErrorSignal(Argv[0]); install_out_of_memory_new_handler(); + RaiseLimits(); #ifdef __MVS__ From 6234b76aad3e1105c86e5c13cfd439878ab08f5c Mon Sep 17 00:00:00 2001 From: David Tenty Date: Thu, 13 Nov 2025 13:51:20 -0500 Subject: [PATCH 2/2] clang-format --- llvm/lib/Support/InitLLVM.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/lib/Support/InitLLVM.cpp b/llvm/lib/Support/InitLLVM.cpp index 5c0f206d389de..b90f4e0714458 100644 --- a/llvm/lib/Support/InitLLVM.cpp +++ b/llvm/lib/Support/InitLLVM.cpp @@ -41,8 +41,7 @@ static void RaiseLimits() { // Increase the soft limit to the hard limit, if necessary and // possible. - if (r.rlim_cur != RLIM_INFINITY && - r.rlim_cur != r.rlim_max) { + if (r.rlim_cur != RLIM_INFINITY && r.rlim_cur != r.rlim_max) { r.rlim_cur = r.rlim_max; setrlimit(resource, &r); }