From d53d5bd193b249ba5d90e79a04059be51cbe7507 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Sun, 15 Nov 2026 02:58:55 -0600 Subject: [PATCH 1/2] gpu: free a closed GEM's mappings at handle close On GPUs without tracked submission (G13, G14), closing a GEM handle unmaps the object in drop_mappings_now(). The unmap only queues the GPUVA unlink and the VM BO put on the GPUVM deferred list. Nothing runs that list until the next VM_BIND or similar ioctl. Until then the deferred VM BO holds a reference to the closed GEM, so its pages stay pinned and its bytes stay charged against the per-client admission limit. A client that frees memory to make room for a new buffer is therefore refused: the GEM_CREATE fails with ENOMEM although the client has just closed gigabytes. On a 13-inch M1 MacBook Pro (client_limit 8112390144), an MLX run closed about 5 GiB of buffers and then failed to create a 40 MiB buffer with ENOMEM. fdinfo drm-total-system stayed at 7706 MiB for 4.5 s of idle time and fell to 2426 MiB only after the next small allocation bound a new buffer. Run the deferred cleanup at the end of drop_mappings_now(), after the reservations are released, as drop_mappings_low_memory(), drop_mappings_filtered() and the deferred-drain path already do. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/gpu/drm/asahi/mmu.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/asahi/mmu.rs b/drivers/gpu/drm/asahi/mmu.rs index ed032ab146dd06..fc69ed698e9511 100644 --- a/drivers/gpu/drm/asahi/mmu.rs +++ b/drivers/gpu/drm/asahi/mmu.rs @@ -2848,6 +2848,9 @@ impl Vm { // unmap error. Always release reservations before dropping it. core::mem::drop(vm_exec); core::mem::drop(bo); + // The unmap only queues the GPUVA and VM BO puts. Run them now so the + // closed GEM and its admission charge go away with the handle. + self.bo_deferred_cleanup(); if result == Err(ENOMEM) { return self.drop_mappings_low_memory(gem); } From 00fdcb87d01f7acecb8abf65bd351d4539ab13c6 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Sun, 15 Nov 2026 09:54:16 -0600 Subject: [PATCH 2/2] gpu: correct the drop_mappings_now() comment on the deferred cleanup The GPUVA unlink and the refcount drops happen at once. Only the zombie VM BO's destruction is deferred, and that deferred VM BO is what still holds the GEM. Say so in the comment above bo_deferred_cleanup(). No code change. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/gpu/drm/asahi/mmu.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/asahi/mmu.rs b/drivers/gpu/drm/asahi/mmu.rs index fc69ed698e9511..66419c4adbbd02 100644 --- a/drivers/gpu/drm/asahi/mmu.rs +++ b/drivers/gpu/drm/asahi/mmu.rs @@ -2848,8 +2848,8 @@ impl Vm { // unmap error. Always release reservations before dropping it. core::mem::drop(vm_exec); core::mem::drop(bo); - // The unmap only queues the GPUVA and VM BO puts. Run them now so the - // closed GEM and its admission charge go away with the handle. + // The unlinked VM BO waits on the deferred list and still holds the GEM. + // Free it now so the closed GEM and its admission charge go with the handle. self.bo_deferred_cleanup(); if result == Err(ENOMEM) { return self.drop_mappings_low_memory(gem);