[PATCH] drm/amdgpu: Use kvmalloc_array for allocating VRAM manager nodes array

Christian König ckoenig.leichtzumerken at gmail.com
Fri Jun 15 15:05:34 UTC 2018


Am 15.06.2018 um 16:27 schrieb Michel Dänzer:
> From: Michel Dänzer <michel.daenzer at amd.com>
>
> It can be quite big, and there's no need for it to be physically
> contiguous. This is less likely to fail under memory pressure (has
> actually happened while running piglit).

Mhm, the last time I looked a drm_mm node had around 160 bytes, which 
means that you need to allocate more than 50MB of VRAM to fill up a 4K page.

If I'm not completely mistaken you can still nearly fit a 4K 8bit RGB 
texture into that.

Christian.

>
> Cc: stable at vger.kernel.org
> Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 9aca653bec07..9c47e860e5e6 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -135,7 +135,8 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
>   		num_nodes = DIV_ROUND_UP(mem->num_pages, pages_per_node);
>   	}
>   
> -	nodes = kcalloc(num_nodes, sizeof(*nodes), GFP_KERNEL);
> +	nodes = kvmalloc_array(num_nodes, sizeof(*nodes),
> +			       GFP_KERNEL | __GFP_ZERO);
>   	if (!nodes)
>   		return -ENOMEM;
>   
> @@ -190,7 +191,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
>   		drm_mm_remove_node(&nodes[i]);
>   	spin_unlock(&mgr->lock);
>   
> -	kfree(nodes);
> +	kvfree(nodes);
>   	return r == -ENOSPC ? 0 : r;
>   }
>   
> @@ -229,7 +230,7 @@ static void amdgpu_vram_mgr_del(struct ttm_mem_type_manager *man,
>   	atomic64_sub(usage, &mgr->usage);
>   	atomic64_sub(vis_usage, &mgr->vis_usage);
>   
> -	kfree(mem->mm_node);
> +	kvfree(mem->mm_node);
>   	mem->mm_node = NULL;
>   }
>   



More information about the amd-gfx mailing list