drm/ttm: fix pipelined gutting for evictions
Subsystems (3)
PATCH 1/1 drm/ttm: fix pipelined gutting for evictions
We can't pipeline that during eviction because the memory needs to be available immediately.
--- drivers/gpu/drm/ttm/ttm_bo.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +10 -2
@@ -651,8 +651,16 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, placement.num_busy_placement =0 ; bdev->driver->evict_flags (bo, &placement); -if (!placement.num_placement && !placement.num_busy_placement) -return ttm_bo_pipeline_gutting (bo); +if (!placement.num_placement && !placement.num_busy_placement) { +ttm_bo_wait (bo, false, false); + +ttm_tt_destroy (bo->ttm); + +memset (&bo->mem,0 ,sizeof (bo->mem)); + bo->mem.mem_type =TTM_PL_SYSTEM ; + bo->ttm =NULL ; +return 0 ; + } evict_mem = bo->mem; evict_mem.mm_node =NULL ;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 2020-07-23 um 5:00 a.m. schrieb Christian König:
Quoted 4 lines
We can't pipeline that during eviction because the memory needs to be available immediately.
Signed-off-by Christian König <[email protected]>
Looks good to me.
Alex, in this case the synchronous ttm_bo_wait would be triggering the eviction fence rather than a delayed delete.
Scheduling an eviction worker, like we currently do, would only add unnecessary latency here. The best place to do the HMM migration to system memory synchronously and minimize the wait time here may be in amdgpu_eviction_flags. That way all the SDMA copies to system memory pages would already be in the pipe by the time we get to the ttm_bo_wait.
Regards,
Felix
Quoted 17 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +3
-2@@ -651,8 +651,16 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, placement.num_busy_placement =0 ; bdev->driver->evict_flags (bo, &placement); -if (!placement.num_placement && !placement.num_busy_placement) -return ttm_bo_pipeline_gutting (bo); +if (!placement.num_placement && !placement.num_busy_placement) { +ttm_bo_wait (bo, false, false); +
drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_evict(struct ttm_buffer_object *bo, · line 666
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +7
-0+ttm_tt_destroy (bo->ttm); + +memset (&bo->mem,0 ,sizeof (bo->mem)); + bo->mem.mem_type =TTM_PL_SYSTEM ; + bo->ttm =NULL ; +return 0 ; + } evict_mem = bo->mem; evict_mem.mm_node =NULL ;
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 2020-07-23 um 5:00 a.m. schrieb Christian König:
Quoted 14 lines
We can't pipeline that during eviction because the memory needs to be available immediately.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +0
-0@@ -651,8 +651,16 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, placement.num_busy_placement =0 ;
drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_evict(struct ttm_buffer_object *bo, · line 659
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +6
-2bdev->driver->evict_flags (bo, &placement); -if (!placement.num_placement && !placement.num_busy_placement) -return ttm_bo_pipeline_gutting (bo); +if (!placement.num_placement && !placement.num_busy_placement) { +ttm_bo_wait (bo, false, false); + +ttm_tt_destroy (bo->ttm); + +memset (&bo->mem,0 ,sizeof (bo->mem));
Where does the memory in the bo->mem (ttm_mem_reg) get destroyed? It doesn't get attached to a ghost BO in this case, so someone will have to call ttm_bo_mem_put explicitly before you wipe out bo->mem.
Regards,
Felix
drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_evict(struct ttm_buffer_object *bo, · line 666
Quoted 7 lines
drivers/gpu/drm/ttm/ttm_bo.c +4
-0+ bo->mem.mem_type =TTM_PL_SYSTEM ; + bo->ttm =NULL ; +return 0 ; + } evict_mem = bo->mem; evict_mem.mm_node =NULL ;
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 17 lines · Felix Kuehling
Am 2020-07-23 um 5:00 a.m. schrieb Christian König:
Quoted 16 lines
We can't pipeline that during eviction because the memory needs to be available immediately.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +0
-0@@ -651,8 +651,16 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, placement.num_busy_placement =0 ; bdev->driver->evict_flags (bo, &placement);
Quoted 11 lines
drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_evict(struct ttm_buffer_object *bo, · line 659
Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +6
-2-if (!placement.num_placement && !placement.num_busy_placement) -return ttm_bo_pipeline_gutting (bo); +if (!placement.num_placement && !placement.num_busy_placement) { +ttm_bo_wait (bo, false, false); + +ttm_tt_destroy (bo->ttm); + +memset (&bo->mem,0 ,sizeof (bo->mem));Where does the memory in the
bo->mem(ttm_mem_reg) get destroyed? It doesn't get attached to a ghost BO in this case, so someone will have to callttm_bo_mem_putexplicitly before you wipe outbo->mem.
After migrating to ram, svm_range_bo_unref-->amdgpu_unref_bo->ttm_bo_put->ttm_bo_release calls ttm_bo_mem_put.
vram is already freed before we signal fence, right?
Regards,
Philip
Quoted 11 lines
Regards,
Felixdrivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_evict(struct ttm_buffer_object *bo, · line 666
Quoted 7 lines
drivers/gpu/drm/ttm/ttm_bo.c +4
-0+ bo->mem.mem_type =TTM_PL_SYSTEM ; + bo->ttm =NULL ; +return 0 ; + } evict_mem = bo->mem; evict_mem.mm_node =NULL ;
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 2020-07-23 um 9:58 p.m. schrieb philip yang:
Quoted 32 lines · Felix Kuehling
Quoted 21 lines
Am 2020-07-23 um 5:00 a.m. schrieb Christian König:
Quoted 20 lines
We can't pipeline that during eviction because the memory needs to be available immediately.
Signed-off-by Christian König <[email protected]>---
drivers/gpu/drm/ttm/ttm_bo.c| 12 ++++++++++--1 file changed, 10 insertions(+), 2 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -651,8 +651,16 @@ static int ttm_bo_evict(structttm_buffer_object *bo, placement.num_busy_placement = 0; bdev->driver->evict_flags(bo, &placement); - if (!placement.num_placement && !placement.num_busy_placement) - return ttm_bo_pipeline_gutting(bo); + if (!placement.num_placement && !placement.num_busy_placement) {Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_evict(struct ttm_buffer_object *bo, · line 659
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_bo.c +5
-0+ ttm_bo_wait(bo, false, false); + + ttm_tt_destroy(bo->ttm); + + memset(&bo->mem, 0, sizeof(bo->mem));Where does the memory in the
bo->mem(ttm_mem_reg) get destroyed? It doesn't get attached to a ghost BO in this case, so someone will have to callttm_bo_mem_putexplicitly before you wipe outbo->mem.
Quoted 3 lines
After migrating to ram, svm_range_bo_unref-->amdgpu_unref_bo->ttm_bo_put->ttm_bo_release calls
ttm_bo_mem_put.
amdgpu_bo_unref won't free anything if the reference count doesn't go to
0. And TTM is still holding a reference here. The BO won't be freed until ttm_mem_evict_first calls ttm_bo_put.
The memset above overwrites the ttm_mem_reg structure, which means it will forget about the VRAM nodes held by the BO. They need to be released first. That's what frees the space that ttm_bo_evict was trying to make available in the first place.
Regards,
Felix
Quoted 16 lines
vram is already freed before we signal fence, right?
Regards,
Philip
Quoted 10 lines
Regards,
FelixQuoted 6 lines
drivers/gpu/drm/ttm/ttm_bo.c +4
-0+ bo->mem.mem_type = TTM_PL_SYSTEM; + bo->ttm = NULL; + return 0; + } evict_mem = bo->mem; evict_mem.mm_node = NULL;
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 24.07.20 um 04:56 schrieb Felix Kuehling:
Quoted 34 lines
Am 2020-07-23 um 9:58 p.m. schrieb philip yang:
Quoted 30 lines · Felix Kuehling
Quoted 21 lines
Am 2020-07-23 um 5:00 a.m. schrieb Christian König:
Quoted 20 lines
We can't pipeline that during eviction because the memory needs to be available immediately.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -651,8 +651,16 @@ static int ttm_bo_evict(structttm_buffer_object *bo, placement.num_busy_placement = 0; bdev->driver->evict_flags(bo, &placement); - if (!placement.num_placement && !placement.num_busy_placement) - return ttm_bo_pipeline_gutting(bo); + if (!placement.num_placement && !placement.num_busy_placement) {Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_evict(struct ttm_buffer_object *bo, · line 659
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_bo.c +5
-0+ ttm_bo_wait(bo, false, false); + + ttm_tt_destroy(bo->ttm); + + memset(&bo->mem, 0, sizeof(bo->mem));Where does the memory in the
bo->mem(ttm_mem_reg) get destroyed? It doesn't get attached to a ghost BO in this case, so someone will have to callttm_bo_mem_putexplicitly before you wipe outbo->mem.Quoted 3 lines
After migrating to ram, svm_range_bo_unref-->amdgpu_unref_bo->ttm_bo_put->ttm_bo_release calls
ttm_bo_mem_put.
Quoted 8 lines
amdgpu_bo_unrefwon't free anything if the reference count doesn't go to
0. And TTM is still holding a reference here. The BO won't be freed untilttm_mem_evict_firstcallsttm_bo_put.The memset above overwrites the
ttm_mem_regstructure, which means it will forget about the VRAM nodes held by the BO. They need to be released first. That's what frees the space thatttm_bo_evictwas trying to make available in the first place.
Yeah, Felix is right that this is a bug.
Going to send a v2 in a minute.
Thanks,
Christian.
Quoted 21 lines
Regards,
FelixQuoted 16 lines
vram is already freed before we signal fence, right?
Regards,
Philip
Quoted 10 lines
Regards,
FelixQuoted 6 lines
drivers/gpu/drm/ttm/ttm_bo.c +4
-0+ bo->mem.mem_type = TTM_PL_SYSTEM; + bo->ttm = NULL; + return 0; + } evict_mem = bo->mem; evict_mem.mm_node = NULL;
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel