Metal cache admission can exceed the configured cache limit

Abierto
#4,841 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

@tijs ya está trabajando en esto.

Desde el 6/11/2026.

  • #4842 de @tijs — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
cpp

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C++
Estrellas
29.1k
Forks
2.4k
Merge medio
3 d 20 h
PR fusionados (30 d)
103

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ml-explore/mlx

Todos los issues de ml-explore/mlx

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.