Skip to contentSkip to conversation

drm/amdgpu: skip clearing empty freed VM list on GEM close

PATCH Superseded Bob Zhou 3 participants 3 messages Jul 15 – Jul 16

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bob Zhou

author
#0 lore raw

PATCH 1/1 drm/amdgpu: skip clearing empty freed VM list on GEM close

amdgpu_gem_object_close() calls amdgpu_vm_clear_freed() after deleting a BO VA. If vm->freed is empty, that call is a no-op but still allocates sync state and walks reservation fences before returning.

Check vm->freed first to avoid the overhead on the GEM close hot path. This does not change behavior because the empty-list path leaves the fence unset and returns success.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -0
index 6a0699746fbcd..72811f6963a15 100644
@@ -348,6 +348,8 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
 	amdgpu_vm_bo_update_shared(bo);
 	if (!amdgpu_vm_ready(vm))
 		goto out_unlock;
+	if (list_empty(&vm->freed))
+		goto out_unlock;
 
 	r = amdgpu_vm_clear_freed(adev, vm, &fence);
 	if (unlikely(r < 0) && !drm_dev_is_unplugged(adev_to_drm(adev)))
Signature · 1 line
2.34.1
#1 lore raw
Quoted 3 lines · Bob Zhou

amdgpu_gem_object_close() calls amdgpu_vm_clear_freed() after deleting a BO VA. If vm->freed is empty, that call is a no-op but still allocates sync state and walks reservation fences before returning.

Check vm->freed first to avoid the overhead on the GEM close hot path. This does not change behavior because the empty-list path leaves the fence unset and returns success.

I think you could get the same effect if you put the check at the start of amdgpu_vm_clear_freed. The function would just return with "fence" unchanged, or NULL in this case. Then this optimization would also apply to any other situations where amgpu_vm_clear_freed gets called without anything to do. The other advantage is that the callers of amdgpu_vm_clear_freed don't need to make assumption about how it works, or know anything about internal state of struct amdgpu_vm.

Regards,
  Felix

Quoted 22 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
index 6a0699746fbcd..72811f6963a15 100644
@@ -348,6 +348,8 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
         amdgpu_vm_bo_update_shared(bo);
         if (!amdgpu_vm_ready(vm))
                 goto out_unlock;
+       if (list_empty(&vm->freed))
+               goto out_unlock;
 
         r = amdgpu_vm_clear_freed(adev, vm, &fence);
         if (unlikely(r < 0) && !drm_dev_is_unplugged(adev_to_drm(adev)))
--

2.34.1

#2 lore raw

AMD General

Hi Felix,

Thanks for the review and suggestion.

That makes sense. Moving the check to the beginning of amdgpu_vm_clear_freed() is a cleaner approach since it keeps the optimization local to the function and benefits all callers without exposing or duplicating knowledge of vm->freed internals.

I'll update the patch accordingly and send a v2.

Regards,
Bob

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Wednesday, July 15, 2026 11:35 PM
To: Zhou, Bob <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: skip clearing empty freed VM list on GEM close

Quoted 3 lines · Bob Zhou

amdgpu_gem_object_close() calls amdgpu_vm_clear_freed() after deleting a BO VA. If vm->freed is empty, that call is a no-op but still allocates sync state and walks reservation fences before returning.

Check vm->freed first to avoid the overhead on the GEM close hot path. This does not change behavior because the empty-list path leaves the fence unset and returns success.

I think you could get the same effect if you put the check at the start of amdgpu_vm_clear_freed. The function would just return with "fence"
unchanged, or NULL in this case. Then this optimization would also apply to any other situations where amgpu_vm_clear_freed gets called without anything to do. The other advantage is that the callers of amdgpu_vm_clear_freed don't need to make assumption about how it works, or know anything about internal state of struct amdgpu_vm.

Regards,
Felix

Quoted 24 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -0
index 6a0699746fbcd..72811f6963a15 100644
@@ -348,6 +348,8 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
         amdgpu_vm_bo_update_shared(bo);
         if (!amdgpu_vm_ready(vm))
                 goto out_unlock;
+       if (list_empty(&vm->freed))
+               goto out_unlock;
 
         r = amdgpu_vm_clear_freed(adev, vm, &fence);
         if (unlikely(r < 0) &&

!drm_dev_is_unplugged(adev_to_drm(adev)))
--
2.34.1