Skip to content

Detect cache thrashing in LRUCache#2600

Merged
zcbenz merged 2 commits intoml-explore:mainfrom
zcbenz:lru-cache-thrashing
Sep 19, 2025
Merged

Detect cache thrashing in LRUCache#2600
zcbenz merged 2 commits intoml-explore:mainfrom
zcbenz:lru-cache-thrashing

Conversation

@zcbenz
Copy link
Copy Markdown
Collaborator

@zcbenz zcbenz commented Sep 17, 2025

Add a simple detection for cache thrashing when using LRUCache, by counting if cache misses have exceeded 2 * capacity. When that happens an exception would be thrown:

RuntimeError: Cache thrashing is happening, please set the environment variable MLX_CUDA_GRAPH_CACHE_SIZE to a larger value than 100 to fix degraded performance.

Copy link
Copy Markdown
Member

@awni awni left a comment

Choose a reason for hiding this comment

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

Nice, thanks!!

@zcbenz zcbenz merged commit 787c0d9 into ml-explore:main Sep 19, 2025
7 checks passed
@zcbenz zcbenz deleted the lru-cache-thrashing branch September 19, 2025 00:12
faisalmemon pushed a commit to faisalmemon/mlx that referenced this pull request Oct 30, 2025
* Detect cache thrashing in LRUCache

* Do not check cache thrashing in tests
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