Skip to content

Free space is asked of Finder once per disk every 3 s, not per destination every 500 ms (refs #478) - #497

Merged
HugeLetters merged 1 commit into
masterfrom
478-free-space-cache
Nov 28, 2026
Merged

HugeLetters merged 1 commit into
masterfrom
478-free-space-cache

Conversation

@HugeLetters

Copy link
Copy Markdown
Owner

Open questions: None

What changed

The engine looks at every destination every 500 ms, and each look called Foundation's free-space query (space::finder). That query walks every volume through IOKit: about 9 ms of CPU a call (95 ms the first time in a process), mostly sys.

space::Cache now keeps Finder's figures per disk (keyed by statfs's fsid and mount) for 3 s, so destinations on one disk share an entry. statfs is still read at every look. Cache::refresh() forgets everything, and it is called when:

  • a torrent newly fails with ENOSPC (once per failure, not at every poll of a torrent that stays failed);
  • a Move or Rename hits ENOSPC;
  • a destination's disk goes away or comes back;
  • the user sends Check.

Free-space refusals before a move (moving::room) use statvfs directly and are unaffected. Stall detection is unaffected: a stalled query is a cache miss, and nothing holds the lock while it runs.

What users notice

The free-space figure can lag a write by up to 3 s. It refreshes at once on a full disk, on a drive going or coming back, and on Check. Deletes show at once (the fresh statfs figure is higher than the cached Finder one, so it wins).

CPU

cargo nextest run -p service -E 'binary(phantom-service)' --no-fail-fast, timed with /usr/bin/time -p (it includes nextest and its children). "Before" is the same code with the cache time set to 0.

user sys total CPU wall load (start→end)
before 114 s 229 s 343 s 179 s 48 → 49
after 110 s 137 s 248 s 250 s 44 → 31

CPU fell by 28% (sys by 40%). Wall time isn't comparable: the machine's load was 30–55 throughout. The 4 tests that failed in the "after" run (all load timeouts) pass when rerun alone.

Tests

  • a_disk_is_asked_once_in_3_s_and_again_after: same disk within 3 s isn't re-queried, after expiry it is, another disk has its own entry.
  • a_refresh_makes_the_next_look_ask_again: refresh forces a new query, and an answer in flight across a refresh isn't kept.
  • the_free_space_shown_follows_writes_and_deletes_on_the_disk now refreshes after each write, with no sleeps.
  • cargo nextest run --workspace: 1303 passed; cargo test -p gui --test appkit: 5 passed; cargo fmt --check clean, no warnings.

Refs #478

@HugeLetters
HugeLetters merged commit 2baa172 into master Nov 28, 2026
@HugeLetters
HugeLetters deleted the 478-free-space-cache branch November 28, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant