Metal cache admission can exceed the configured cache limit

未关闭
#4,841 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

@tijs 已经在做这个了。

开始于 2026年11月6日。

  • #4842 来自 @tijs —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
cpp

调研方向

Start by locating MetalAllocator::free() and the cache limit checks described in the issue. Reproduce the oversized and mixed allocation cases with the allocator tests, then inspect the linked pull request #4842 for the two-file fix and regression coverage. Done means freed buffers respect the configured limit, including zero, and the reported reuse cases are covered.

由索引模型根据 Issue 内容生成。

描述

MetalAllocator::free() checks the current cache size before admitting the incoming buffer, without including that buffer's length. This can exceed set_cache_limit() as soon as a live allocation is released.

On Apple M1 Max, using current main 9f806b3606eaa9f7c807238f6bd465185cd94d6d:

  1. Set the cache limit to 1 MiB and clear it.
  2. Allocate and release a 2 MiB buffer: get_cache_memory() reports 2,097,152 bytes.
  3. Clear it, hold a 512 KiB allocation while allocating/releasing a 768 KiB allocation, then release the 512 KiB allocation: the cache reaches 1,310,720 bytes with a 1,048,576-byte limit.

No later allocation is made before inspecting each overshoot. The checks use allocator::malloc directly, so shader execution and asynchronous command completion are not involved in the reproduction.

Expected: an incoming buffer larger than the allowance should not enter the cache. A smaller incoming buffer should be admitted only after enough older cached bytes are released. Zero should continue to disable reuse. This concerns the freed-buffer cache, not a limit on active allocations or total process memory.

I have a small two-file fix and regression test covering oversized admission, mixed shapes, recent-shape reuse and zero allowance.

主要语言
C++
星标
29.1k
派生
2.4k
平均合并
3 天 20 小时
30 天内合并 PR
103

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ml-explore/mlx 的其他 Issue

查看 ml-explore/mlx 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。