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

Code before:

    with open(memory_usage_filename, "r") as f:
        lines = f.readlines()
        cgroup_usage_in_bytes = int(lines[0].strip())

    if (
        inactive_file_bytes == -1
        or cgroup_usage_in_bytes == -1
        or active_file_bytes == -1
    ):
        return None

    return cgroup_usage_in_bytes - inactive_file_bytes - active_file_bytes


def resolve_object_store_memory(
    available_memory: int,
    object_store_memory: Optional[int] = None,
) -> int:
    """Resolve the object store memory size.

    This function determines the appropriate object store memory size based on
    the provided value or calculates a default based on available system memory.

    Args:
        available_memory: The memory available for this raylet.
        object_store_memory: The user-specified object store memory size in bytes.
            If None, a default size will be calculated.

    Returns:
        The resolved object store memory size in bytes.
    """
    # Derive default object store memory if not specified
    if object_store_memory is None:
        object_store_memory_cap = ray_constants.DEFAULT_OBJECT_STORE_MAX_MEMORY_BYTES

        # Cap by shm size by default to avoid low performance, but don't
        # go lower than REQUIRE_SHM_SIZE_THRESHOLD.
        if sys.platform == "linux" or sys.platform == "linux2":
            # Multiple by 0.95 to give a bit of wiggle-room.
            # https://github.com/ray-project/ray/pull/23034/files
            shm_avail = get_shared_memory_bytes() * 0.95
            shm_cap = max(ray_constants.REQUIRE_SHM_SIZE_THRESHOLD, shm_avail)

            object_store_memory_cap = min(object_store_memory_cap, shm_cap)

        object_store_memory = int(
            available_memory * ray_constants.DEFAULT_OBJECT_STORE_MEMORY_PROPORTION
        )

        # Set the object_store_memory size to 2GB on Mac

Review comment (suggestion):
```suggestion
        available_memory: The memory available for this node.
```

Code after:

    with open(memory_usage_filename, "r") as f:
        lines = f.readlines()
        cgroup_usage_in_bytes = int(lines[0].strip())

    if (
        inactive_file_bytes == -1
        or cgroup_usage_in_bytes == -1
        or active_file_bytes == -1
    ):
        return None

    return cgroup_usage_in_bytes - inactive_file_bytes - active_file_bytes


def resolve_object_store_memory(
    available_memory_bytes: int,
    object_store_memory: Optional[int] = None,
) -> int:
    """Resolve the object store memory size.

    This function determines the appropriate object store memory size based on
    the provided value or calculates a default based on available system memory.

    Args:
        available_memory_bytes: The memory available for this node.
        object_store_memory: The user-specified object store memory size in bytes.
            If None, a default size will be calculated.

    Returns:
        The resolved object store memory size in bytes.
    """
    # Derive default object store memory if not specified
    if object_store_memory is None:
        object_store_memory_cap = ray_constants.DEFAULT_OBJECT_STORE_MAX_MEMORY_BYTES

        # Cap by shm size by default to avoid low performance, but don't
        # go lower than REQUIRE_SHM_SIZE_THRESHOLD.
        if sys.platform == "linux" or sys.platform == "linux2":
            # Multiple by 0.95 to give a bit of wiggle-room.
            # https://github.com/ray-project/ray/pull/23034/files
            shm_avail = get_shared_memory_bytes() * 0.95
            shm_cap = max(ray_constants.REQUIRE_SHM_SIZE_THRESHOLD, shm_avail)

            object_store_memory_cap = min(object_store_memory_cap, shm_cap)

        object_store_memory = int(
            available_memory_bytes
            * ray_constants.DEFAULT_OBJECT_STORE_MEMORY_PROPORTION
        )