umem: write the bind log on a writer thread (never block a caller) #134

Manually merged
github merged 1 commit from github-bot/gh-134 into gh-pr/134/base 2026-12-01 20:20:14 +00:00 AGit
Owner

@⁠lordra9-svg on GitHub · 2026-12-01 20:08 UTC · original
lordra9-svg:fix/bindlog-async → main · +125 −34 · 1 files · 1 commits · merged 2026-12-01 20:16 UTC

What it fixes

greenfield/umem/src/bindlog.rs wrote the 64 KiB buffer (and the flushed line) to the log file while holding the log mutex, so one slow disk write blocked every thread that logs a bind - the renderer, the descriptor helper and the remapper's bind flush. docs/TASKS.md ("The bind log write under its lock stalls every thread for seconds") measured renderer lock waits of 11.3 s and 2.3 s here, with "bind flush: bind log write 2299 ms" and an IO stall. Goal: writing the bind log never blocks a thread that logs a bind; a slow disk costs log lines (dropped and counted), never frames (rule 31).

Change

  • A dedicated umem-bindlog writer thread + a bounded queue (4096 lines). line/bind/coalesced/flushed only format ns <text> and try_send; they never touch the file.
  • A full queue drops the line and increments a counter; detach reports the count (warn sink).
  • The writer writes on each wakeup (coalescing only what is already queued, capped at 64 KiB, no threshold/timer), so lines up to a flushed still reach the file promptly for device-loss decoding.
  • Default path unchanged: UMEM_BINDLOG unset means no thread and no log, exactly as before. Line format is byte-identical.

Tests

  • umem 22 passed, including new off_spawns_no_thread, full_queue_drops_and_never_blocks (fills the queue, 20k enqueues return well under the test's limit, drop counter exact) and line_format_is_unchanged.
  • VKTORY_BIN=<tmp> tools/build.sh exit 0 (built to a separate bin so the running game was untouched).

Not measured

I could not reproduce a genuinely slow disk locally, so there is no before/after stall number in this PR; the guarantee is structural (no file IO on any caller) and covered by the full-queue test. Happy to add a disk-stall harness if you want one.

**@⁠lordra9-svg** on GitHub · 2026-12-01 20:08 UTC · [original](https://github.com/vktory6/VKtory/pull/134) `lordra9-svg:fix/bindlog-async` → `main` · +125 −34 · 1 files · 1 commits · merged 2026-12-01 20:16 UTC ## What it fixes `greenfield/umem/src/bindlog.rs` wrote the 64 KiB buffer (and the `flushed` line) to the log file **while holding the log mutex**, so one slow disk write blocked every thread that logs a bind - the renderer, the descriptor helper and the remapper's bind flush. `docs/TASKS.md` ("The bind log write under its lock stalls every thread for seconds") measured renderer lock waits of 11.3 s and 2.3 s here, with "bind flush: bind log write 2299 ms" and an IO stall. Goal: writing the bind log never blocks a thread that logs a bind; a slow disk costs log lines (dropped and counted), never frames (rule 31). ## Change - A dedicated `umem-bindlog` writer thread + a bounded queue (4096 lines). `line`/`bind`/`coalesced`/`flushed` only format `ns <text>` and `try_send`; they never touch the file. - A full queue drops the line and increments a counter; `detach` reports the count (warn sink). - The writer writes on each wakeup (coalescing only what is already queued, capped at 64 KiB, no threshold/timer), so lines up to a `flushed` still reach the file promptly for device-loss decoding. - Default path unchanged: `UMEM_BINDLOG` unset means no thread and no log, exactly as before. Line format is byte-identical. ## Tests - `umem` 22 passed, including new `off_spawns_no_thread`, `full_queue_drops_and_never_blocks` (fills the queue, 20k enqueues return well under the test's limit, drop counter exact) and `line_format_is_unchanged`. - `VKTORY_BIN=<tmp> tools/build.sh` exit 0 (built to a separate bin so the running game was untouched). ## Not measured I could not reproduce a genuinely slow disk locally, so there is no before/after stall number in this PR; the guarantee is structural (no file IO on any caller) and covered by the full-queue test. Happy to add a disk-stall harness if you want one.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:09:11 +00:00
github-bot changed target branch from main to gh-pr/134/base 2026-12-01 20:20:13 +00:00
github manually merged commit 288d6499ec into gh-pr/134/base 2026-12-01 20:20:14 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-01 20:17 UTC · original

Merged, thanks. That was fast, and it's exactly the shape the task asked for: callers only enqueue, a slow disk costs lines, not frames, and the drop count is reported.

Two notes for next time, no action needed:

  • Your commit's author is set to the VKtory account (VKtory <[email protected]>), probably copied from the repo's history by a tool. Please commit as yourself. The squash merge records you as the author anyway.
  • The dropped-line count shows only at detach. If it ever matters during a run, putting it in umem's periodic stats line would make it visible live (rule 31's "counted").
**@⁠vktory6** on GitHub · 2026-12-01 20:17 UTC · [original](https://github.com/vktory6/VKtory/pull/134#issuecomment-7324405727) Merged, thanks. That was fast, and it's exactly the shape the task asked for: callers only enqueue, a slow disk costs lines, not frames, and the drop count is reported. Two notes for next time, no action needed: - Your commit's author is set to the VKtory account (`VKtory <[email protected]>`), probably copied from the repo's history by a tool. Please commit as yourself. The squash merge records you as the author anyway. - The dropped-line count shows only at `detach`. If it ever matters during a run, putting it in umem's periodic stats line would make it visible live (rule 31's "counted").
This discussion has been locked. Commenting is limited to contributors.
No description provided.