Repository navigation
Conversation
…ndbox A process that hosted sandboxes kept two files open for each: the bundle's locked owner file and runsc's stderr log. Every runsc command it runs forks the process, and a fork copies the descriptor table, so the more sandboxes a process hosted, the slower each command started. With 512 sandboxes (1,028 open files), 64 threads ran 435 commands a second in them; with the files closed, 927. Each process now keeps one lock file in /tmp/ray/sandbox/.owners locked for as long as it lives, and each bundle's owner file names it. The stderr log is closed once the sandbox runs: the launch tree writes it through its own descriptors. An owner that can't delete a bundle, because its cgroup won't go, clears the lock from its owner file, so the reclaim pass retries it as before. Reclaim passes delete the locks of processes that are gone; an owner file that names a deleted lock falls back on the PID in the lock's name. Signed-off-by: xyuzh <[email protected]>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
…bundles Write an owner file that no live owner holds or names, rather than lock one with _own_bundle and close it: the bundle reads as unowned whether owners lock their owner files (now) or a lock that the file names (ray-project#67731). Signed-off-by: xyuzh <[email protected]>
…mpty directory The sandbox directory can hold more than bundles (ray-project#67731 adds the owner locks' directory), so look for bundle directories. Signed-off-by: xyuzh <[email protected]>
Signed-off-by: xyuzh <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 42bf898. Configure here.
A reclaim pass deleted the locks of dead owners at its end, even when it had left one of their bundles, say behind a cgroup it couldn't remove. The next pass then went by the PID in the lock's name, and once another process had that PID, it took the bundle for owned and never retried it. Now the pass keeps the locks that bundles on the node still name. Signed-off-by: xyuzh <[email protected]>
Microcheck build 58554 failed in its init step: downloads from GitHub failed during GitHub's incident on 2026-11-09. Signed-off-by: xyuzh <[email protected]>
The jobs that failed in microcheck build 58564 failed only on downloads from GitHub during GitHub's incident on 2026-11-09. Signed-off-by: xyuzh <[email protected]>
microcheck build 58579 failed before running tests: GitHub's incident on 2026-11-09 still blocked downloads from CI then. It's resolved now. Signed-off-by: xyuzh <[email protected]>
Signed-off-by: xyuzh <[email protected]>
GitHub delivered 0ae9fa4's push webhook two hours late, so Buildkite canceled bc509ce's build (58597) for one of the older commit. Signed-off-by: xyuzh <[email protected]>
| name = owner.get("owner_lock") if isinstance(owner, dict) else None | ||
| if name is None: | ||
| return False # Let go of by its owner (see _disown_bundle). |
There was a problem hiding this comment.
What happens during a rolling upgrade or multi-virtualenv setup sharing /tmp/ray/sandbox? Pre-PR workers flock post-PR .owner files and kill live sandboxes, while post-PR _cpus_in_use treats pre-PR .owner files (missing 'owner_lock') as dead and double-assigns their CPUs.
There was a problem hiding this comment.
Not changing this. The format this replaces is #67022's, which is only on master: no release has it (2.59.2 doesn't), so an upgrade between releases never sees both. On nightlies, restarting Ray on a node stops the old workers and their sandboxes first, and the new code still reclaims the bundles they leave. It can't reclaim a live old-format bundle, because reclaim first takes the flock on the owner file, which an old owner holds. Two installs from before and after this PR running sandboxes on one node at once would misread each other as you describe, and the description says not to do that.
| def _owner_locks_named() -> Set[str]: | ||
| """The owner locks that the bundles on this node name.""" | ||
| names = set() | ||
| for root_dir in glob.glob(os.path.join(_RAY_SANDBOX_DIR, "ray-sandbox-*")): | ||
| try: | ||
| with open(os.path.join(root_dir, _OWNER_FILE), encoding="utf-8") as f: | ||
| owner = json.load(f) | ||
| except (OSError, ValueError): | ||
| continue | ||
| name = owner.get("owner_lock") if isinstance(owner, dict) else None | ||
| if isinstance(name, str): | ||
| names.add(name) | ||
| return names |
There was a problem hiding this comment.
Have you considered nesting bundles under a per-owner directory (_RAY_SANDBOX_DIR/owner-/ray-sandbox- with one held flock on owner-/.lock), which keeps 1 FD per process while avoiding .owners/ cross-directory GC, double .owner scans in _reclaim_unowned_bundles, and the _pid_running fallback?
There was a problem hiding this comment.
Not changing this. Nesting would drop the .owners sweep, but it makes a bundle's path depend on its owner: _disown_bundle, which hands a bundle to the reclaim pass by rewriting one file, would have to move the directory, and everything that finds bundles as ray-sandbox-* under the sandbox directory would change with it. With the reordering in the first thread the sweep has no window left, and the PID fallback only applies to a lock that something outside Ray deleted.
Read the bundles' owner files after the owner locks are found free, not before. An owner could write an owner file and die between the two, and its lock was then deleted while a bundle still named it, which left the bundle to the PID in the lock's name. Close a forked child's copies of its parent's owner locks at the fork. A lock is held while any copy of its file is open, so a child that outlived the owner kept the owner's sandboxes from being reclaimed. Signed-off-by: xyuzh <[email protected]>
| name = owner.get("owner_lock") if isinstance(owner, dict) else None | ||
| if name is None: | ||
| return False # Let go of by its owner (see _disown_bundle). |
There was a problem hiding this comment.
Not changing this. The format this replaces is #67022's, which is only on master: no release has it (2.59.2 doesn't), so an upgrade between releases never sees both. On nightlies, restarting Ray on a node stops the old workers and their sandboxes first, and the new code still reclaims the bundles they leave. It can't reclaim a live old-format bundle, because reclaim first takes the flock on the owner file, which an old owner holds. Two installs from before and after this PR running sandboxes on one node at once would misread each other as you describe, and the description says not to do that.
| def _owner_locks_named() -> Set[str]: | ||
| """The owner locks that the bundles on this node name.""" | ||
| names = set() | ||
| for root_dir in glob.glob(os.path.join(_RAY_SANDBOX_DIR, "ray-sandbox-*")): | ||
| try: | ||
| with open(os.path.join(root_dir, _OWNER_FILE), encoding="utf-8") as f: | ||
| owner = json.load(f) | ||
| except (OSError, ValueError): | ||
| continue | ||
| name = owner.get("owner_lock") if isinstance(owner, dict) else None | ||
| if isinstance(name, str): | ||
| names.add(name) | ||
| return names |
There was a problem hiding this comment.
Not changing this. Nesting would drop the .owners sweep, but it makes a bundle's path depend on its owner: _disown_bundle, which hands a bundle to the reclaim pass by rewriting one file, would have to move the directory, and everything that finds bundles as ray-sandbox-* under the sandbox directory would change with it. With the reordering in the first thread the sweep has no window left, and the PID fallback only applies to a lock that something outside Ray deleted.
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |

Description
A process that hosts sandboxes kept two files open for each one: the bundle's locked
.ownerfile and runsc's stderr log. Every runsc command the process runs forks it, and a fork copies the whole descriptor table, so each command started more slowly the more sandboxes the process hosted. Warm pools make one process host hundreds.On a 352-CPU node, with 512 sandboxes in one process (1,028 open files),
trueran at:Two interleaved runs each. With this PR the process held 5 files. Creating the 512 took 38 s either way.
This PR:
/tmp/ray/sandbox/.owners, locked for as long as the process lives, and has each bundle's owner file name it. A bundle's owner is gone once that lock is free. A forked child closes its copies of the lock, so it can't keep the lock held after the owner dies;Bundles that #67022's format left behind are still reclaimed. No release has that format, but a Ray from before this PR would take this PR's bundles for unowned, so don't run both on one node.
Related issues
None.
Additional information
test_an_owner_is_alive_while_its_process_runs(a real process holds the lock, then exits) andtest_a_process_holds_one_descriptor_for_all_its_sandboxes; the reclaim and cgroup tests now orphan bundles through a process that has exited.test_a_dead_owners_lock_stays_while_a_bundle_names_it: a bundle that a reclaim pass couldn't delete keeps its dead owner's lock, so a reused PID can't make it look owned.test_an_owner_that_dies_during_the_lock_sweep_keeps_its_lockandtest_a_forked_child_doesnt_hold_its_parents_owner_lockcover the two review fixes. At bc509ce, with master 81a7e99 merged in, the real-gVisor suites in a privileged container (aarch64, runsc release-20261026.0, erofs-utils 1.9.4),test_cgroup.pyandtest_resource_limits.pyincluded: 476 passed (test_overlayfs.pyin a session of its own), 25 skipped; master a83e55e: 473 passed, and the same two GPU tests fail, since that container's Ray predatesget_cdi_kind. On macOS, the same failures as master, plus 2 passes. pre-commit passes.