Repository navigation
[core][sandbox] Keep a free-space floor under the image cache - #67025
Conversation
The image cache was capped at half of its filesystem, whatever else was on the disk. The cache shares that disk with sandboxes' writable overlays, logs and spilled objects. Some of SkyRL's SWE-bench Multimodal nodes had 44 GB free, less than the ~115 GB that its 46 images take as EROFS, and the cap didn't account for it. A full disk fails every sandbox on the node and gets Pods evicted. Before each pull, eviction now also frees unused images, least recently extracted first, until the filesystem has a minimum of free space: RAY_SANDBOX_IMAGE_CACHE_MIN_FREE_BYTES, by default a tenth of the filesystem, the level at which the kubelet starts evicting Pods. Images in use are never evicted, as before. Setting both this and RAY_SANDBOX_IMAGE_CACHE_MAX_BYTES to 0 disables eviction. The sandbox tests turn the floor off, so a full runner disk can't change them. Signed-off-by: xyuzh <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a minimum free space floor configuration (RAY_SANDBOX_IMAGE_CACHE_MIN_FREE_BYTES) for the sandbox image cache, defaulting to a tenth of the filesystem capacity. When the free space falls below this threshold, the least recently used images are evicted to prevent disk exhaustion. The changes include updates to the eviction logic, documentation, and corresponding unit tests. Feedback on the changes suggests minor improvements to the tests: asserting that a warning is correctly logged when an invalid environment variable value is parsed (to avoid polluting test logs), and removing a redundant import of the os module in one of the test files.
| monkeypatch.setenv("RAY_SANDBOX_IMAGE_CACHE_MIN_FREE_BYTES", "5G") | ||
| assert image_cache_min_free_bytes(str(tmp_path)) == tenth |
There was a problem hiding this comment.
In test_image_cache_min_free_bytes_default_and_env, when testing the invalid env value '5G', a warning is logged. To prevent this warning from polluting the test output and to verify that the warning is indeed logged correctly, we should patch logger.warning and assert its call, similar to how it is done in test_image_cache_max_bytes_default_and_env below.
| monkeypatch.setenv("RAY_SANDBOX_IMAGE_CACHE_MIN_FREE_BYTES", "5G") | |
| assert image_cache_min_free_bytes(str(tmp_path)) == tenth | |
| monkeypatch.setenv("RAY_SANDBOX_IMAGE_CACHE_MIN_FREE_BYTES", "5G") | |
| with patch( | |
| "ray.experimental.sandbox._internal.image_utils.logger.warning" | |
| ) as warning: | |
| assert image_cache_min_free_bytes(str(tmp_path)) == tenth | |
| warning.assert_called_once_with( | |
| "Ignoring %s=%r: expected an integer number of bytes.", | |
| "RAY_SANDBOX_IMAGE_CACHE_MIN_FREE_BYTES", | |
| "5G", | |
| ) |
| import os | ||
| import time |
Review follow-up: the test now asserts the warning that an unparsable RAY_SANDBOX_IMAGE_CACHE_MIN_FREE_BYTES logs, as the cap's test does, and drops a redundant import. Signed-off-by: xyuzh <[email protected]>
…oject#67025) ## Description The image cache is capped at half of the filesystem that holds it, whatever else is on that disk. The cache shares the disk with sandboxes' writable overlays, logs and spilled objects. SkyRL's SWE-bench Multimodal report found nodes with 44 GB free, against about 115 GB that its 46 images take as EROFS. The cap doesn't account for free space at all. A disk that fills fails every sandbox on the node, and on Kubernetes it gets the node's Pods evicted. This PR keeps a free-space floor under the cache: - **Eviction also frees space.** Before each pull, eviction now also removes unused images, least recently extracted first, until the cache's filesystem has a minimum of free space, besides fitting the size cap. Images that a running sandbox uses, and the image being pulled, are never evicted, as before. - **The floor.** `RAY_SANDBOX_IMAGE_CACHE_MIN_FREE_BYTES` sets it. The default is a tenth of the filesystem, the level of the kubelet's default `nodefs.available<10%` eviction threshold. Setting both it and `RAY_SANDBOX_IMAGE_CACHE_MAX_BYTES` to `0` disables eviction. - **Tests turn it off.** The sandbox tests set the floor to 0 in `conftest.py`, so a full runner disk can't change their results. The laptop I tested on had 2% free. - **Docs.** The "Bound the image cache" section describes the floor. ## Related issues None filed. Found with SkyRL's Harbor environment for Ray Sandbox (skyrl-project/SkyRL#2467). ## Additional information - **Not a duplicate.** I searched open PRs for "sandbox image cache", "sandbox disk", "sandbox eviction" and "erofs". None changes when the cache evicts. ray-project#66469 changes how an evicted image's directory is deleted (rename first) in the same loop. Whichever lands second needs a small merge. - **Experiment.** Anyscale staging didn't start clusters on 2026-10-14, so I ran this as a pod on a CoreWeave Kubernetes cluster: `rayproject/ray:nightly-py312` (Ray 3.0.0.dev0 1ba2dca), runsc release-20261005.0, erofs-utils 1.9.4. I pulled `busybox:latest`, which no sandbox uses, and `alpine:3.20`, pinned as a live sandbox's image. Then I set the floor one byte above the current free space, as on a disk that other data has filled, and pulled `debian:bookworm-slim`: | | master | This PR | | --- | --- | --- | | `busybox:latest` (unused) | still cached | evicted (4.5 MB) | | `alpine:3.20` (in use) | still cached | still cached | | `debian:bookworm-slim` | pulled | pulled | - **Tests.** In the same pod, with `TEST_SANDBOX=1 pytest --import-mode=importlib` in `python/ray/experimental/sandbox/tests`: - `test_gvisor_backend.py -k netns`: 7 passed. - `test_image_utils.py test_image_manager.py test_sandbox_config.py test_sandbox_runtime.py test_gvisor_backend.py -k "not netns"`: 90 passed, 1 skipped. `test_create_sandbox_helper` was deselected because it starts its own Ray driver. - The new tests are `test_image_cache_eviction_keeps_a_free_space_floor` and `test_image_cache_min_free_bytes_default_and_env`. The first works with no size cap: eviction frees space down to the floor, oldest first, and keeps an image in use even when the floor can't be met. Both fail on master. - Lint: the repo's pre-commit hooks (pre-commit 3.5.0: ruff, black, pydoclint) pass on commit. - **Review follow-up (fb71212).** As gemini suggested, the floor's test asserts the warning that an unparsable setting logs, and a redundant import is gone. - AI assistance (Claude Code) was used to prepare this change and run the tests above. --------- Signed-off-by: xyuzh <[email protected]> Signed-off-by: Pawel Beza <[email protected]> Co-authored-by: Copilot <[email protected]> Copilot-Session: 4b9df5c4-6ec3-4e1f-ac3e-54f320ebd8c4
Description
The image cache is capped at half of the filesystem that holds it, whatever else is on that disk. The cache shares the disk with sandboxes' writable overlays, logs and spilled objects. SkyRL's SWE-bench Multimodal report found nodes with 44 GB free, against about 115 GB that its 46 images take as EROFS. The cap doesn't account for free space at all. A disk that fills fails every sandbox on the node, and on Kubernetes it gets the node's Pods evicted.
This PR keeps a free-space floor under the cache:
RAY_SANDBOX_IMAGE_CACHE_MIN_FREE_BYTESsets it. The default is a tenth of the filesystem, the level of the kubelet's defaultnodefs.available<10%eviction threshold. Setting both it andRAY_SANDBOX_IMAGE_CACHE_MAX_BYTESto0disables eviction.conftest.py, so a full runner disk can't change their results. The laptop I tested on had 2% free.Related issues
None filed. Found with SkyRL's Harbor environment for Ray Sandbox (skyrl-project/SkyRL#2467).
Additional information
Not a duplicate. I searched open PRs for "sandbox image cache", "sandbox disk", "sandbox eviction" and "erofs". None changes when the cache evicts. [core][sandbox] Move an image aside before deleting it #66469 changes how an evicted image's directory is deleted (rename first) in the same loop. Whichever lands second needs a small merge.
Experiment. Anyscale staging didn't start clusters on 2026-10-14, so I ran this as a pod on a CoreWeave Kubernetes cluster:
rayproject/ray:nightly-py312(Ray 3.0.0.dev0 1ba2dca), runsc release-20261005.0, erofs-utils 1.9.4. I pulledbusybox:latest, which no sandbox uses, andalpine:3.20, pinned as a live sandbox's image. Then I set the floor one byte above the current free space, as on a disk that other data has filled, and pulleddebian:bookworm-slim:busybox:latest(unused)alpine:3.20(in use)debian:bookworm-slimTests. In the same pod, with
TEST_SANDBOX=1 pytest --import-mode=importlibinpython/ray/experimental/sandbox/tests:test_gvisor_backend.py -k netns: 7 passed.test_image_utils.py test_image_manager.py test_sandbox_config.py test_sandbox_runtime.py test_gvisor_backend.py -k "not netns": 90 passed, 1 skipped.test_create_sandbox_helperwas deselected because it starts its own Ray driver.test_image_cache_eviction_keeps_a_free_space_floorandtest_image_cache_min_free_bytes_default_and_env. The first works with no size cap: eviction frees space down to the floor, oldest first, and keeps an image in use even when the floor can't be met. Both fail on master.Review follow-up (fb71212). As gemini suggested, the floor's test asserts the warning that an unparsable setting logs, and a redundant import is gone.
AI assistance (Claude Code) was used to prepare this change and run the tests above.