Repository: ray-project/ray
File: python/ray/_private/resource_isolation_config.py (Python)

Code before:
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )
            if system_reserved_cpu:
                raise ValueError(
                    "system_reserved_cpu cannot be set when resource isolation is not enabled. "
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )

            if self.system_reserved_memory:
                raise ValueError(
                    "system_reserved_memory cannot be set when resource isolation is not enabled. "
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )
            return

        self.system_reserved_cpu_weight = self._validate_and_get_system_reserved_cpu(
            system_reserved_cpu
        )

        if object_store_memory is None:
            object_store_memory = (
                ray._private.utils.get_configured_object_store_memory()
            )

        self.system_reserved_memory = self._validate_and_get_system_reserved_memory(
            system_reserved_memory, object_store_memory
        )

        self.cgroup_path = self._validate_and_get_cgroup_path(cgroup_path)

    def is_enabled(self) -> bool:
        return self._resource_isolation_enabled

    def add_system_pids(self, system_pids: str):
        """A comma-separated list of pids to move into the system cgroup."""
        self.system_pids = system_pids

    @staticmethod
    def _validate_and_get_cgroup_path(cgroup_path: Optional[str]) -> str:
        """Returns the ray_constants.DEFAULT_CGROUP_PATH if cgroup_path is not specified.

        Args:
            cgroup_path: The path for the cgroup the raylet should use to enforce
                resource isolation.

        Returns:
            str: The validated cgroup path.


Review comment (suggestion):
I think we should limit this to just resource isolation configs and let the caller get the default object store memory. It doesn't make sense to pass None as `object_store_memory` to the ctor. 

Code after:
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )
            if system_reserved_cpu:
                raise ValueError(
                    "system_reserved_cpu cannot be set when resource isolation is not enabled. "
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )

            if self.system_reserved_memory:
                raise ValueError(
                    "system_reserved_memory cannot be set when resource isolation is not enabled. "
                    "Set enable_resource_isolation to True if you're using ray.init or use the "
                    "--enable-resource-isolation flag if you're using the ray cli."
                )
            return

        if object_store_memory is None:
            raise ValueError(
                "object_store_memory must be resolved before creating a ResourceIsolationConfig "
                "when resource isolation is enabled. This is likely a bug in Ray, "
                "please report it at https://github.com/ray-project/ray/issues/new/choose."
            )

        self.system_reserved_cpu_weight = self._validate_and_get_system_reserved_cpu(
            system_reserved_cpu
        )

        self.system_reserved_memory = self._validate_and_get_system_reserved_memory(
            system_reserved_memory, object_store_memory
        )

        self.cgroup_path = self._validate_and_get_cgroup_path(cgroup_path)

    def is_enabled(self) -> bool:
        return self._resource_isolation_enabled

    def add_system_pids(self, system_pids: str):
        """A comma-separated list of pids to move into the system cgroup."""
        self.system_pids = system_pids

    @staticmethod
    def _validate_and_get_cgroup_path(cgroup_path: Optional[str]) -> str:
        """Returns the ray_constants.DEFAULT_CGROUP_PATH if cgroup_path is not specified.

        Args:
            cgroup_path: The path for the cgroup the raylet should use to enforce
                resource isolation.

        Returns: