Skip to content

[MP][Optimize] Skip locked keys during LRU eviction to improve eviction efficiency#2978

Merged
maobaolong merged 4 commits intoLMCache:devfrom
chunxiaozheng:mp/lru-evict
Apr 14, 2026
Merged

[MP][Optimize] Skip locked keys during LRU eviction to improve eviction efficiency#2978
maobaolong merged 4 commits intoLMCache:devfrom
chunxiaozheng:mp/lru-evict

Conversation

@chunxiaozheng
Copy link
Copy Markdown
Collaborator

@chunxiaozheng chunxiaozheng commented Apr 8, 2026

In the current LRU eviction implementation, get_eviction_actions blindly selects the first target_count keys from the LRU order without checking whether those keys are actually evictable (i.e., not locked).
For example, if target_count = 10 but 8 out of the first 10 LRU keys are currently read-locked or write-locked, the subsequent delete call can only successfully remove 2 keys. Meanwhile, there may be plenty of unlocked keys further down the LRU order that could have been evicted instead, this leads to extremely low eviction efficiency and prevents memory from being released in a timely manner.


Note

Medium Risk
Changes eviction selection logic and the EvictionPolicy.get_eviction_actions interface, which could affect eviction behavior and call sites; however the change is localized and covered by new unit tests.

Overview
Improves L1 eviction efficiency by skipping read/write-locked keys when choosing LRU eviction candidates.

This extends EvictionPolicy.get_eviction_actions with an optional key_eligible_filter callback, implements filtering in LRUEvictionPolicy, and wires L1EvictionController to pass L1Manager.is_key_evictable so eviction avoids non-deletable keys.

Adds unit tests for L1Manager.is_key_evictable and for the new LRU filter behavior (including order/ratio handling and all/none acceptance cases).

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

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 a key filtering mechanism into the eviction process to skip locked objects. It adds an is_key_evictable method to the L1Manager and updates the eviction policy interface and LRU implementation to support an optional key_filter callable. Comprehensive tests for the new filtering logic and evictability checks are included. Feedback suggests lowering the log level from warning to debug in is_key_evictable to account for expected race conditions during concurrent deletions.

Comment thread lmcache/v1/distributed/l1_manager.py Outdated
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 b2cbe0d. Configure here.

Comment thread lmcache/v1/distributed/l1_manager.py
@chunxiaozheng chunxiaozheng added the mp Buildkite trigger for multi-processing mode test label Apr 8, 2026
@chunxiaozheng
Copy link
Copy Markdown
Collaborator Author

@ApostaC could you help take a look? Thanks!

def get_eviction_actions(
self,
expected_ratio: float,
key_filter: Callable[[ObjectKey], bool] | None = None,
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.

tiny nit: maybe name with something that implies whether True or False means eligible or not e.g. key_eligible_filter or key_eligible_fn

feel free not to take, I also really like the filter naming

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@sammshen Thanks for your review, I have updated.

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

Signed-off-by: idellzheng <idellzheng@tencent.com>
Signed-off-by: idellzheng <idellzheng@tencent.com>
Signed-off-by: idellzheng <idellzheng@tencent.com>
Signed-off-by: idellzheng <idellzheng@tencent.com>
Copy link
Copy Markdown
Collaborator

@maobaolong maobaolong left a comment

Choose a reason for hiding this comment

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

LGTM

@maobaolong maobaolong enabled auto-merge (squash) April 14, 2026 08:04
@github-actions github-actions Bot added the full Run comprehensive tests on this PR label Apr 14, 2026
@maobaolong maobaolong merged commit cb8b1c0 into LMCache:dev Apr 14, 2026
39 checks passed
maobaolong pushed a commit to maobaolong/LMCache that referenced this pull request Apr 14, 2026
…on efficiency (LMCache#2978)

* [MP][optimize] optimize lru eviction

Signed-off-by: idellzheng <idellzheng@tencent.com>

* add ut

Signed-off-by: idellzheng <idellzheng@tencent.com>

* delete log

Signed-off-by: idellzheng <idellzheng@tencent.com>

* rename

Signed-off-by: idellzheng <idellzheng@tencent.com>

---------

Signed-off-by: idellzheng <idellzheng@tencent.com>
ekaynar pushed a commit to ekaynar/LMCache that referenced this pull request Apr 15, 2026
…on efficiency (LMCache#2978)

* [MP][optimize] optimize lru eviction

Signed-off-by: idellzheng <idellzheng@tencent.com>

* add ut

Signed-off-by: idellzheng <idellzheng@tencent.com>

* delete log

Signed-off-by: idellzheng <idellzheng@tencent.com>

* rename

Signed-off-by: idellzheng <idellzheng@tencent.com>

---------

Signed-off-by: idellzheng <idellzheng@tencent.com>
ftian1 pushed a commit to ftian1/LMCache that referenced this pull request Apr 20, 2026
…on efficiency (LMCache#2978)

* [MP][optimize] optimize lru eviction

Signed-off-by: idellzheng <idellzheng@tencent.com>

* add ut

Signed-off-by: idellzheng <idellzheng@tencent.com>

* delete log

Signed-off-by: idellzheng <idellzheng@tencent.com>

* rename

Signed-off-by: idellzheng <idellzheng@tencent.com>

---------

Signed-off-by: idellzheng <idellzheng@tencent.com>
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 mp Buildkite trigger for multi-processing mode test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants