diff options
| author | Claude <noreply@anthropic.com> | 2026-11-25 22:10:37 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-11-25 22:10:37 +0000 |
| commit | aab7653566e4ecf80a8026cfbd48e74966a4d04c (patch) | |
| tree | ca519f26361ce9034393b9e9ab669d47bb01f59f /runtime/src | |
| parent | c3b8520683b1ed19c1af9f0061b48ceb57bad928 (diff) | |
d3d12: retry a failed heavy cache write and never publish a VK_INCOMPLETE snapshot
Review of RT-HEAVY-PIPELINE-CACHE:
- The writer thread marked a generation written even when the save failed, so the
cache stayed unsaved until teardown. A failed save now keeps the cache dirty and
is retried after a bounded backoff (5 s, doubling, capped at 2 min), so a write
that keeps failing does not spin. WriteSchedule::failed() holds that decision and
heavy_pipeline_cache_test checks it.
- save_heavy_pipeline_cache accepted VK_INCOMPLETE and published the truncated blob
over a complete file. It now requires VK_SUCCESS, like the session cache, and
keeps the previous file; the next try queries a fresh size.
Changes made by Claude Code (AI-assisted).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/heavy_pipeline_cache.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/runtime/src/heavy_pipeline_cache.h b/runtime/src/heavy_pipeline_cache.h index f7b55aebc..8cad10e66 100644 --- a/runtime/src/heavy_pipeline_cache.h +++ b/runtime/src/heavy_pipeline_cache.h | |||
| @@ -40,11 +40,15 @@ inline Threshold parse_threshold(const char* text) { | |||
| 40 | 40 | ||
| 41 | // When the writer thread writes. A heavy compile marks the cache dirty; the write waits `settle_ms` after the | 41 | // When the writer thread writes. A heavy compile marks the cache dirty; the write waits `settle_ms` after the |
| 42 | // newest one (heavy compiles come in bursts at a load, and each write copies the whole heavy cache) but never more | 42 | // newest one (heavy compiles come in bursts at a load, and each write copies the whole heavy cache) but never more |
| 43 | // than `max_delay_ms` after the first unwritten one, so a long burst is still saved as it goes. | 43 | // than `max_delay_ms` after the first unwritten one, so a long burst is still saved as it goes. A write that fails |
| 44 | // keeps the cache dirty and is tried again `retry_ms` later, the delay doubling with each failure in a row up to | ||
| 45 | // `max_retry_ms`, so a disk that stays full or a driver that keeps failing does not make the writer spin. | ||
| 44 | class WriteSchedule { | 46 | class WriteSchedule { |
| 45 | public: | 47 | public: |
| 46 | static constexpr std::uint64_t settle_ms = 3000; | 48 | static constexpr std::uint64_t settle_ms = 3000; |
| 47 | static constexpr std::uint64_t max_delay_ms = 20000; | 49 | static constexpr std::uint64_t max_delay_ms = 20000; |
| 50 | static constexpr std::uint64_t retry_ms = 5000; | ||
| 51 | static constexpr std::uint64_t max_retry_ms = 120000; | ||
| 48 | 52 | ||
| 49 | void note_heavy(std::uint64_t now_ms) { | 53 | void note_heavy(std::uint64_t now_ms) { |
| 50 | if (!dirty_) first_ = now_ms; | 54 | if (!dirty_) first_ = now_ms; |
| @@ -56,7 +60,8 @@ public: | |||
| 56 | // The time to write at; only meaningful while dirty. | 60 | // The time to write at; only meaningful while dirty. |
| 57 | std::uint64_t due_ms() const { | 61 | std::uint64_t due_ms() const { |
| 58 | const std::uint64_t settled = last_ + settle_ms, latest = first_ + max_delay_ms; | 62 | const std::uint64_t settled = last_ + settle_ms, latest = first_ + max_delay_ms; |
| 59 | return settled < latest ? settled : latest; | 63 | const std::uint64_t at = settled < latest ? settled : latest; |
| 64 | return at > retry_at_ ? at : retry_at_; | ||
| 60 | } | 65 | } |
| 61 | bool due(std::uint64_t now_ms) const { return dirty_ && now_ms >= due_ms(); } | 66 | bool due(std::uint64_t now_ms) const { return dirty_ && now_ms >= due_ms(); } |
| 62 | // Taken when a write starts; the write covers every heavy compile noted up to then. | 67 | // Taken when a write starts; the write covers every heavy compile noted up to then. |
| @@ -64,13 +69,26 @@ public: | |||
| 64 | // A write that started at `generation` and `started_ms` is done. A heavy compile noted after it started, even in | 69 | // A write that started at `generation` and `started_ms` is done. A heavy compile noted after it started, even in |
| 65 | // the same millisecond tick, keeps the cache dirty for the next write, due as if it were first noted then. | 70 | // the same millisecond tick, keeps the cache dirty for the next write, due as if it were first noted then. |
| 66 | void written(std::uint64_t generation, std::uint64_t started_ms) { | 71 | void written(std::uint64_t generation, std::uint64_t started_ms) { |
| 72 | failures_ = 0; | ||
| 73 | retry_at_ = 0; | ||
| 67 | if (generation_ == generation) dirty_ = false; | 74 | if (generation_ == generation) dirty_ = false; |
| 68 | else first_ = started_ms; | 75 | else first_ = started_ms; |
| 69 | } | 76 | } |
| 77 | // A write that started at `started_ms` failed: the cache stays dirty and the next try waits out the backoff. | ||
| 78 | void failed(std::uint64_t started_ms) { | ||
| 79 | std::uint64_t delay = retry_ms; | ||
| 80 | for (std::uint32_t i = 0; i < failures_ && delay < max_retry_ms; ++i) delay *= 2; | ||
| 81 | if (delay > max_retry_ms) delay = max_retry_ms; | ||
| 82 | if (failures_ < 64) ++failures_; | ||
| 83 | retry_at_ = started_ms + delay; | ||
| 84 | } | ||
| 85 | std::uint32_t failures() const { return failures_; } | ||
| 70 | 86 | ||
| 71 | private: | 87 | private: |
| 72 | bool dirty_ = false; | 88 | bool dirty_ = false; |
| 73 | std::uint64_t first_ = 0, last_ = 0, generation_ = 0; | 89 | std::uint64_t first_ = 0, last_ = 0, generation_ = 0; |
| 90 | std::uint32_t failures_ = 0; // failed writes in a row | ||
| 91 | std::uint64_t retry_at_ = 0; // no write before this time after a failure | ||
| 74 | }; | 92 | }; |
| 75 | 93 | ||
| 76 | } // namespace leonida::heavy_pipeline_cache | 94 | } // namespace leonida::heavy_pipeline_cache |