drm/amd/amdgpu: Bail out of BO node creation if not enough VRAM
Subsystems (2)
PATCH 1/1 drm/amd/amdgpu: Bail out of BO node creation if not enough VRAM
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +12 -5
@@ -276,7 +276,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,struct drm_mm_node *nodes;enum drm_mm_insert_mode mode;unsigned long lpfn, num_nodes, pages_per_node, pages_left; -uint64_t usage =0 , vis_usage =0 ; +uint64_t vis_usage =0 ;unsigned i;int r;
@@ -284,6 +284,13 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,if (!lpfn) lpfn = man->size; +/* bail out quickly if there's likely not enough VRAM for this BO */ +atomic64_add (mem->num_pages <<PAGE_SHIFT , &mgr->usage); +if (atomic64_read (&mgr->usage) > adev->gmc.mc_vram_size) { +atomic64_sub (mem->num_pages <<PAGE_SHIFT , &mgr->usage); +return -ENOSPC ; + } +if (place->flags &TTM_PL_FLAG_CONTIGUOUS ) { pages_per_node = ~0ul ; num_nodes =1 ;
@@ -300,8 +307,10 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man, nodes =kvmalloc_array ((uint32_t )num_nodes,sizeof (*nodes),GFP_KERNEL | __GFP_ZERO); -if (!nodes) +if (!nodes) { +atomic64_sub (mem->num_pages <<PAGE_SHIFT , &mgr->usage);return -ENOMEM ; + } mode =DRM_MM_INSERT_BEST ;if (place->flags &TTM_PL_FLAG_TOPDOWN )
@@ -321,7 +330,6 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,if (unlikely (r))break ; - usage += nodes[i].size <<PAGE_SHIFT ; vis_usage +=amdgpu_vram_mgr_vis_size (adev, &nodes[i]);amdgpu_vram_mgr_virt_start (mem, &nodes[i]); pages_left -= pages;
@@ -341,14 +349,12 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,if (unlikely (r)) goto error; - usage += nodes[i].size <<PAGE_SHIFT ; vis_usage +=amdgpu_vram_mgr_vis_size (adev, &nodes[i]);amdgpu_vram_mgr_virt_start (mem, &nodes[i]); pages_left -= pages; }spin_unlock (&mgr->lock); -atomic64_add (usage, &mgr->usage);atomic64_add (vis_usage, &mgr->vis_usage); mem->mm_node = nodes;
@@ -359,6 +365,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,while (i--)drm_mm_remove_node (&nodes[i]);spin_unlock (&mgr->lock); +atomic64_sub (mem->num_pages <<PAGE_SHIFT , &mgr->usage);kvfree (nodes);return r == -ENOSPC ?0 : r;
Signature · 6 lines
2.21.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Am 10.06.19 um 16:32 schrieb StDenis, Tom:
Quoted 19 lines
Signed-off-by Tom St Denis <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1
-1@@ -276,7 +276,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,struct drm_mm_node *nodes;enum drm_mm_insert_mode mode;unsigned long lpfn, num_nodes, pages_per_node, pages_left; -uint64_t usage =0 , vis_usage =0 ; +uint64_t vis_usage =0 ;unsigned i;int r;
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man, · line 292
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +6
-0@@ -284,6 +284,13 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,if (!lpfn) lpfn = man->size; +/* bail out quickly if there's likely not enough VRAM for this BO */ +atomic64_add (mem->num_pages <<PAGE_SHIFT , &mgr->usage); +if (atomic64_read (&mgr->usage) > adev->gmc.mc_vram_size) { +atomic64_sub (mem->num_pages <<PAGE_SHIFT , &mgr->usage); +return -ENOSPC ; + }
That's not 100% correct IIRC. See TTM expects a return value of 0, but mem->node to be NULL when allocation fails.
Christian.
Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +4
-4+if (place->flags &TTM_PL_FLAG_CONTIGUOUS ) { pages_per_node = ~0ul ; num_nodes =1 ;@@ -300,8 +307,10 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man, nodes =kvmalloc_array ((uint32_t )num_nodes,sizeof (*nodes),GFP_KERNEL | __GFP_ZERO); -if (!nodes) +if (!nodes) { +atomic64_sub (mem->num_pages <<PAGE_SHIFT , &mgr->usage);return -ENOMEM ; + } mode =DRM_MM_INSERT_BEST ;if (place->flags &TTM_PL_FLAG_TOPDOWN )@@ -321,7 +330,6 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,if (unlikely (r))break ; - usage += nodes[i].size <<PAGE_SHIFT ; vis_usage +=amdgpu_vram_mgr_vis_size (adev, &nodes[i]);amdgpu_vram_mgr_virt_start (mem, &nodes[i]); pages_left -= pages;@@ -341,14 +349,12 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,if (unlikely (r)) goto error; - usage += nodes[i].size <<PAGE_SHIFT ; vis_usage +=amdgpu_vram_mgr_vis_size (adev, &nodes[i]);amdgpu_vram_mgr_virt_start (mem, &nodes[i]); pages_left -= pages; }spin_unlock (&mgr->lock); -atomic64_add (usage, &mgr->usage);atomic64_add (vis_usage, &mgr->vis_usage); mem->mm_node = nodes;
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man, · line 371
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1
-0@@ -359,6 +365,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,while (i--)drm_mm_remove_node (&nodes[i]);spin_unlock (&mgr->lock); +atomic64_sub (mem->num_pages <<PAGE_SHIFT , &mgr->usage);kvfree (nodes);return r == -ENOSPC ?0 : r;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 91bb2355-949f-43a3-67e6-fb752de86b5c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 26 lines · Christian König
Am 10.06.19 um 16:32 schrieb StDenis, Tom:
Quoted 25 lines
Signed-off-by Tom St Denis <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c| 17 ++++++++++++-----1 file changed, 12 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1
-1@@ -276,7 +276,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man, struct drm_mm_node *nodes; enum drm_mm_insert_mode mode; unsigned long lpfn, num_nodes, pages_per_node, pages_left; - uint64_t usage = 0, vis_usage = 0; + uint64_t vis_usage = 0; unsigned i; int r;@@ -284,6 +284,13 @@ static int amdgpu_vram_mgr_new(struct
ttm_mem_type_manager*man,
if (!lpfn)
lpfn =man->size;
+ /* bail out quickly if there's likely not enough VRAM for this BO */
Quoted 8 lines
Quoted 5 lines
+
atomic64_add(mem->num_pages << PAGE_SHIFT, &mgr->usage); + if (atomic64_read(&mgr->usage)>adev->gmc.mc_vram_size) { +atomic64_sub(mem->num_pages << PAGE_SHIFT, &mgr->usage); + return-ENOSPC;
+ }That's not 100% correct IIRC. See TTM expects a return value of 0, but
mem->nodeto be NULL when allocation fails.
Yup, the node creation returns -ENOSPC which this function then translates to 0. I'll submit a v2 in a minute once I pass a piglit test :-)
Tom
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx