drm/amdgpu: drop the gang leader reference when freeing gang jobs
Subsystems (2)
PATCH v4 1/1 drm/amdgpu: drop the gang leader reference when freeing gang jobs
Every job of a gang except the leader holds a reference to the scheduled fence of the leader in job->gang_submit. Only amdgpu_job_free(), used for jobs which never ran, drops it, so for every gang submission which completes the scheduler fence of the leader, and with it its hardware fence, is leaked. amdgpu_job_free() in turn checks for the leader only after drm_sched_job_cleanup() cleared the scheduler fence, so a leader freed there drops a reference it never took.
On navi31, 100 submissions of a GFX + COMPUTE gang grow the slab cache drm_sched_fence is merged into by 60 to 180 objects each time, while 100 GFX only submissions don't.
Use amdgpu_job_free() for the jobs the scheduler frees too, and check for the gang leader there before drm_sched_job_cleanup() clears the scheduler fence. As the scheduler clears the entity of the jobs it picked up, check for the scheduler fence instead to tell whether the job needs cleaning up.
Keep freeing the remaining IBs with amdgpu_job_free_resources() after drm_sched_job_cleanup(), so that it frees them with the hardware fence or right away and not with the scheduler fence, which nobody signals for jobs aborted after drm_sched_job_arm(), like a CS returning -EAGAIN.
v2: unify amdgpu_job_free() and amdgpu_job_free_cb() (Christian), don't
free the remaining IBs with the scheduler fence
v3: drop the comments (Christian)
v4: free the IBs with amdgpu_job_free_resources() again (Christian)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5 -19
@@ -313,22 +313,7 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)static void amdgpu_job_free_cb (struct drm_sched_job *s_job) { -struct amdgpu_job *job =to_amdgpu_job (s_job); - -drm_sched_job_cleanup (s_job); - -amdgpu_sync_free (&job->explicit_sync); - -if (dma_fence_was_initialized (&job->hw_fence->base)) -dma_fence_put (&job->hw_fence->base); -else -kfree (job->hw_fence); -if (dma_fence_was_initialized (&job->hw_vm_fence->base)) -dma_fence_put (&job->hw_vm_fence->base); -else -kfree (job->hw_vm_fence); - -kfree (job); +amdgpu_job_free (to_amdgpu_job (s_job)); } void amdgpu_job_set_gang_leader(struct amdgpu_job *job,
@@ -349,13 +334,14 @@ void amdgpu_job_set_gang_leader(struct amdgpu_job *job,void amdgpu_job_free (struct amdgpu_job *job) { -if (job->base.entity) +if (job->gang_submit != &job->base.s_fence->scheduled) +dma_fence_put (job->gang_submit); + +if (job->base.s_fence)drm_sched_job_cleanup (&job->base);amdgpu_job_free_resources (job);amdgpu_sync_free (&job->explicit_sync); -if (job->gang_submit != &job->base.s_fence->scheduled) -dma_fence_put (job->gang_submit);if (dma_fence_was_initialized (&job->hw_fence->base))dma_fence_put (&job->hw_fence->base);
Signature · 1 line
2.50.1
Quoted 23 lines · Jesse Zhang
Every job of a gang except the leader holds a reference to the scheduled fence of the leader in
job->gang_submit. Onlyamdgpu_job_free(), used for jobs which never ran, drops it, so for every gang submission which completes the scheduler fence of the leader, and with it its hardware fence, is leaked.amdgpu_job_free()in turn checks for the leader only afterdrm_sched_job_cleanup()cleared the scheduler fence, so a leader freed there drops a reference it never took.On navi31, 100 submissions of a GFX + COMPUTE gang grow the slab cache
drm_sched_fenceis merged into by 60 to 180 objects each time, while 100 GFX only submissions don't.Use
amdgpu_job_free()for the jobs the scheduler frees too, and check for the gang leader there beforedrm_sched_job_cleanup()clears the scheduler fence. As the scheduler clears the entity of the jobs it picked up, check for the scheduler fence instead to tell whether the job needs cleaning up.Keep freeing the remaining IBs with
amdgpu_job_free_resources()afterdrm_sched_job_cleanup(), so that it frees them with the hardware fence or right away and not with the scheduler fence, which nobody signals for jobs aborted afterdrm_sched_job_arm(), like a CS returning-EAGAIN.
Quoted 8 lines
v2: unify
amdgpu_job_free()andamdgpu_job_free_cb()(Christian), don't
free the remaining IBs with the scheduler fence
v3: drop the comments (Christian)
v4: free the IBs withamdgpu_job_free_resources()again (Christian)Fixes 68ce8b242242 ("drm/amdgpu: add gang submit backend v2")Fixes f7d66fb2ea43 ("drm/amdgpu: cleanup scheduler job initialization v2")Signed-off-by Jesse Zhang <[email protected]>
Quoted 50 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5
-19@@ -313,22 +313,7 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)static void amdgpu_job_free_cb (struct drm_sched_job *s_job) { -struct amdgpu_job *job =to_amdgpu_job (s_job); - -drm_sched_job_cleanup (s_job); - -amdgpu_sync_free (&job->explicit_sync); - -if (dma_fence_was_initialized (&job->hw_fence->base)) -dma_fence_put (&job->hw_fence->base); -else -kfree (job->hw_fence); -if (dma_fence_was_initialized (&job->hw_vm_fence->base)) -dma_fence_put (&job->hw_vm_fence->base); -else -kfree (job->hw_vm_fence); - -kfree (job); +amdgpu_job_free (to_amdgpu_job (s_job)); } void amdgpu_job_set_gang_leader(struct amdgpu_job *job,@@ -349,13 +334,14 @@ void amdgpu_job_set_gang_leader(struct amdgpu_job *job,void amdgpu_job_free (struct amdgpu_job *job) { -if (job->base.entity) +if (job->gang_submit != &job->base.s_fence->scheduled) +dma_fence_put (job->gang_submit); + +if (job->base.s_fence)drm_sched_job_cleanup (&job->base);amdgpu_job_free_resources (job);amdgpu_sync_free (&job->explicit_sync); -if (job->gang_submit != &job->base.s_fence->scheduled) -dma_fence_put (job->gang_submit);if (dma_fence_was_initialized (&job->hw_fence->base))dma_fence_put (&job->hw_fence->base);