Skip to content

fix(l1): preserve the largest prefix when a batch is short on memory - #9

Open
voipmonitor wants to merge 2 commits into
release/v0.5.2-glm52-dcp-basefrom
fix/lmcache-l1-partial-prefix-20260729
Open

fix(l1): preserve the largest prefix when a batch is short on memory#9
voipmonitor wants to merge 2 commits into
release/v0.5.2-glm52-dcp-basefrom
fix/lmcache-l1-partial-prefix-20260729

Conversation

@voipmonitor

Copy link
Copy Markdown

Problem

reserve_write used an all-or-nothing batch allocation. If a large L2-to-L1 restore was short by only a few blocks, every key became OUT_OF_MEMORY and the complete prefix had to be recomputed. FLO observed a 5700-chunk restore retaining only 8 chunks after missing the batch by 1140 blocks.

Change

  • leave the successful single-allocation hot path unchanged
  • after full-batch OOM, use the allocator all-or-nothing contract to binary-search the largest fitting prefix
  • allocate and write-lock that prefix in request order
  • return explicit OUT_OF_MEMORY results for the unallocated tail
  • keep one-key and zero-fit behavior unchanged

This improves the original Florian Bernd implementation: its byte estimate plus halving could stop below the true maximum under alignment or fragmentation. Binary search runs only on the OOM recovery path and finds the actual maximum supported by the allocator. The original commit and authorship are preserved.

Validation

  • Ruff check and format pass
  • 5 targeted CPU/shared-memory tests pass
  • 77 unrelated hardware/configuration variants skip in this container
  • covers partial prefix, committable prefix, total OOM, single-key OOM, and a synthetic capacity boundary proving the search reaches 7/10 rather than stopping at a smaller fit.

flobernd and others added 2 commits July 29, 2026 16:57
reserve_write's batch allocation was all-or-nothing: short by a few
blocks meant every key got OUT_OF_MEMORY. A large L2->L1 restore then
collapsed to zero prefix hits and the request re-prefilled its whole
context (observed live: a 5700-chunk ~19 GB restore completed 8/5700
after missing the batch by 1140 blocks, stalling decode for minutes).

Fall back to allocating the longest prefix that fits, estimated from
the allocator's free space and halved on failure. The unallocated tail
keeps explicit per-key OUT_OF_MEMORY results. Both callers already
handle per-key failure: prefetch trims to the contiguous prefix and the
store path skips failed keys.
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@voipmonitor, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 11f17185-d272-46cf-9ca7-10e8fa18ec03

📥 Commits

Reviewing files that changed from the base of the PR and between 9cebd40 and c3b73de.

📒 Files selected for processing (3)
  • lmcache/v1/distributed/l1_manager.py
  • tests/v1/distributed/test_l1_manager.py
  • tests/v1/distributed/test_l1_manager_partial_alloc.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@voipmonitor

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

2 participants