cros_sdk: increase soft rlimit nproc to hard
On systems that set the nproc soft rlimit lower than the hard
limit, increase to the hard limit to mitigate cases where the
soft limit is too low to be usable. This doesn't guarantee
the hard limit is enough, but there isn't much we can do if
the admin has set that too low.
BUG=b:234353695
TEST=CQ passes
Change-Id: I19e887864d8926fb04eb87a17e31fc6bc21617cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3686276
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Gilberto Contreras <gcontreras@google.com>
diff --git a/scripts/cros_sdk.py b/scripts/cros_sdk.py
index 6cb82a0..59e3708 100644
--- a/scripts/cros_sdk.py
+++ b/scripts/cros_sdk.py
@@ -193,6 +193,14 @@
cmd.append('--')
cmd.extend(additional_args)
+ # Some systems set the soft limit too low. Bump it up to the hard limit.
+ # We don't override the hard limit because it's something the admins put
+ # in place and we want to respect such configs. http://b/234353695
+ soft, hard = resource.getrlimit(resource.RLIMIT_NPROC)
+ if soft != resource.RLIM_INFINITY and soft < 4096:
+ if soft < hard or hard == resource.RLIM_INFINITY:
+ resource.setrlimit(resource.RLIMIT_NPROC, (hard, hard))
+
# ThinLTO opens lots of files at the same time.
# Set rlimit and vm.max_map_count to accommodate this.
file_limit = 262144