Skip to content

[Misc] Reduce the logs generated by lazy memory allocator#3068

Merged
deng451e merged 1 commit intoLMCache:devfrom
ApostaC:worktree-reduce-lazy-logs
Apr 17, 2026
Merged

[Misc] Reduce the logs generated by lazy memory allocator#3068
deng451e merged 1 commit intoLMCache:devfrom
ApostaC:worktree-reduce-lazy-logs

Conversation

@ApostaC
Copy link
Copy Markdown
Contributor

@ApostaC ApostaC commented Apr 17, 2026

What this PR does / why we need it:

The LazyMemoryAllocator currently logs every 1 GB of background pinned-memory expansion (COMMIT_SIZE). On machines with large pools (e.g. ~164 GB seen during MP server runs), this floods the log with hundreds of lines like:

LazyMemoryAllocator: Expanded 1024 MB pinned memory, now total is 167936 MB

This PR:

  • Throttles the log to every 10 GB of cumulative expansion (still emitted on the final commit so the total is always reported).
  • Includes the final target and a percentage in each line so the user can see progress, e.g.:
LazyMemoryAllocator: Expanded 10240 MB pinned memory, now total is 20480 MB / 167936 MB (12.2%)

The commit cadence (1 GB) is unchanged — only logging is decoupled from it.

Special notes for your reviewers:

No functional change to allocation behavior. Introduces a new class constant LOG_INTERVAL = 10 << 30 and a small _log_expansion_progress helper.

If applicable:

  • this PR contains user facing changes - docs added
  • this PR contains unit tests

Note

Low Risk
Logging-only change in the background expansion worker; allocation/commit behavior is unchanged, with minimal runtime risk beyond altered observability cadence.

Overview
Reduces log volume from LazyMemoryAllocator background pinned-memory expansion by decoupling logging from the 1GB commit cadence and emitting progress logs only every 10GB (and on the final commit).

Adds LOG_INTERVAL, tracks last_log_size, and updates the log message to include the final target size and percent complete via a new _log_expansion_progress helper.

Reviewed by Cursor Bugbot for commit 16d2931. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: ApostaC <yihua98@uchicago.edu>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces periodic logging of memory expansion progress in the LazyMemoryAllocator. It adds a LOG_INTERVAL constant, a new _log_expansion_progress method to report cumulative progress and percentage, and updates the _expand_worker to trigger logging every 10 GB or at the end of the expansion process. A review comment identifies a missing return type hint for the new method, which is required by the repository's style guide.

"""
self._address_manager.sbrk(expand_size)

def _log_expansion_progress(self, expanded_since_last_log: int):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new method _log_expansion_progress is missing a return type hint. According to the repository style guide, all new functions must have type hints for both arguments and return values.

Suggested change
def _log_expansion_progress(self, expanded_since_last_log: int):
def _log_expansion_progress(self, expanded_since_last_log: int) -> None:
References
  1. All new functions have type hints (arguments + return values) (link)

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 16d2931. Configure here.

"""
self._address_manager.sbrk(expand_size)

def _log_expansion_progress(self, expanded_since_last_log: int):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New method missing return type annotation

Low Severity

The new _log_expansion_progress method is missing a -> None return type hint. The project's AGENTS.md convention requires all functions and methods to have type hints for both arguments and return values, and the review rule lists missing type hints on new functions as an error-level concern.

Fix in Cursor Fix in Web

Triggered by project rule: LMCache Code Review Style Guide

Reviewed by Cursor Bugbot for commit 16d2931. Configure here.

Copy link
Copy Markdown
Contributor

@sammshen sammshen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Collaborator

@deng451e deng451e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@deng451e deng451e enabled auto-merge (squash) April 17, 2026 20:11
@deng451e deng451e added the full Run comprehensive tests on this PR label Apr 17, 2026
@deng451e deng451e merged commit ea84d4e into LMCache:dev Apr 17, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full Run comprehensive tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants