*: only increase stack size if evaluations are done

we don't need to mess with this rlimit for e.g. the daemon. increasing
the limit later should always be safe since we don't allocate (or map)
much before constructing the eval states that ultimately fill our heap
and could thus make stack expansion impossible after some time passes.

Change-Id: Ieafda537fbc99a6a7f83a093a981e7df947da437
This commit is contained in:
eldritch horrors
2026-02-02 14:20:54 +00:00
parent c20aaf6ca7
commit b908f9135c
5 changed files with 14 additions and 10 deletions
+6
View File
@@ -4,6 +4,7 @@
#include "lix/libutil/archive.hh"
#include "lix/libutil/ansicolor.hh"
#include "lix/libutil/async.hh"
#include "lix/libutil/current-process.hh"
#include "lix/libutil/deprecated-features.hh"
#include "lix/libutil/error.hh"
#include "lix/libutil/english.hh"
@@ -391,6 +392,11 @@ Evaluator::Evaluator(
box_ptr<EvalState> Evaluator::begin(AsyncIoRoot & aio)
{
assert(!activeEval);
// Increase the default stack size for the evaluator and for
// libstdc++'s std::regex.
ensureStackSizeAtLeast(64ul * 1024 * 1024);
return box_ptr<EvalState>::unsafeFromNonnull(
std::unique_ptr<EvalState>(new EvalState(aio, *this))
);
+5 -1
View File
@@ -54,8 +54,12 @@ unsigned int getMaxCPU()
rlim_t savedStackSize = 0;
void setStackSize(rlim_t stackSize)
void ensureStackSizeAtLeast(rlim_t stackSize)
{
if (savedStackSize >= stackSize) {
return;
}
struct rlimit limit;
if (getrlimit(RLIMIT_STACK, &limit) == 0 && limit.rlim_cur < stackSize) {
savedStackSize = limit.rlim_cur;
+2 -4
View File
@@ -14,12 +14,10 @@ namespace nix {
*/
unsigned int getMaxCPU();
/**
* Change the stack size.
* Increase the stack size rlimit if it is currently smaller than `stackSize`.
*/
void setStackSize(rlim_t stackSize);
void ensureStackSizeAtLeast(rlim_t stackSize);
/**
* Restore the original inherited Unix process context (such as signal
-4
View File
@@ -665,10 +665,6 @@ int main(int argc, char * * argv)
std::abort();
}
// Increase the default stack size for the evaluator and for
// libstdc++'s std::regex.
nix::setStackSize(64ul * 1024 * 1024);
return nix::handleExceptions(argv[0], [&]() {
nix::AsyncIoRoot aio;
return nix::mainWrapped(aio, argc, argv);
+1 -1
View File
@@ -127,7 +127,7 @@ void worker(nix::AutoCloseFD &to, nix::AutoCloseFD &from, MyArgs &args)
try {
// Increase the default stack size for the evaluator and for
// libstdc++'s std::regex.
nix::setStackSize(64 * 1024 * 1024);
nix::ensureStackSizeAtLeast(64 * 1024 * 1024);
#if HAVE_BOEHMGC
// We are doing the garbage collection by killing forks.