From 33cf91ceac15964366a3f8b97ff81ed53cc4c2a3 Mon Sep 17 00:00:00 2001 From: knownexus Date: Thu, 30 Aug 2018 11:45:53 +0100 Subject: Added `set_resource_limits()` to platform This has been moved from app.py As it will have different functionality depending on platform Once the Darwin (MacOS) platform is added Removed `resource.setrlimit()` functionality from app.py Added `resource.setrlimit()` functionality to platform.py as function --- buildstream/_frontend/app.py | 8 -------- buildstream/_platform/linux.py | 1 - buildstream/_platform/platform.py | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py index ccdbb2d5d..44b4cfb95 100644 --- a/buildstream/_frontend/app.py +++ b/buildstream/_frontend/app.py @@ -115,14 +115,6 @@ class App(): else: self.colors = False - # Increase the soft limit for open file descriptors to the maximum. - # SafeHardlinks FUSE needs to hold file descriptors for all processes in the sandbox. - # Avoid hitting the limit too quickly. - limits = resource.getrlimit(resource.RLIMIT_NOFILE) - if limits[0] != limits[1]: - # Set soft limit to hard limit - resource.setrlimit(resource.RLIMIT_NOFILE, (limits[1], limits[1])) - # create() # # Should be used instead of the regular constructor. diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py index a5fd0d687..d29a1d575 100644 --- a/buildstream/_platform/linux.py +++ b/buildstream/_platform/linux.py @@ -52,7 +52,6 @@ class Linux(Platform): # Private Methods # ################################################ def _check_user_ns_available(self, context): - # Here, lets check if bwrap is able to create user namespaces, # issue a warning if it's not available, and save the state # locally so that we can inform the sandbox to not try it diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py index 8a074eb62..a10c66da9 100644 --- a/buildstream/_platform/platform.py +++ b/buildstream/_platform/platform.py @@ -19,6 +19,7 @@ import os import sys +import resource from .._exceptions import PlatformError, ImplError @@ -37,6 +38,7 @@ class Platform(): # def __init__(self, context): self.context = context + self.set_resource_limits() @classmethod def create_instance(cls, *args, **kwargs): @@ -92,3 +94,15 @@ class Platform(): def create_sandbox(self, *args, **kwargs): raise ImplError("Platform {platform} does not implement create_sandbox()" .format(platform=type(self).__name__)) + + def set_resource_limits(self, soft_limit=None, hard_limit=None): + # Need to set resources for _frontend/app.py as this is dependent on the platform + # SafeHardlinks FUSE needs to hold file descriptors for all processes in the sandbox. + # Avoid hitting the limit too quickly. + limits = resource.getrlimit(resource.RLIMIT_NOFILE) + if limits[0] != limits[1]: + if soft_limit is None: + soft_limit = limits[1] + if hard_limit is None: + hard_limit = limits[1] + resource.setrlimit(resource.RLIMIT_NOFILE, (soft_limit, hard_limit)) -- cgit v1.2.1