[PATCH] drm/amd/display: use vmalloc for struct dc_state

Mario Limonciello mario.limonciello at amd.com
Thu Jun 27 03:50:38 UTC 2024


On 6/26/2024 16:45, Alex Deucher wrote:
> This is a big structure so use vmalloc as malloc can
> fail when there is memory pressure.

vmalloc can be a bit slower, but I think it's fine for this context and 
better to handle memory pressure more nicely.

Reviewed-by: Mario Limonciello <mario.limonciello at amd.com>

> 
> Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3454
> Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
> ---
>   drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
> index 5d4f831b1e55..080c1d5f7412 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
> @@ -1491,9 +1491,10 @@ int pre_validate_dsc(struct drm_atomic_state *state,
>   	 * from dm_state->context.
>   	 */
>   
> -	local_dc_state = kmemdup(dm_state->context, sizeof(struct dc_state), GFP_KERNEL);
> +	local_dc_state = vmalloc(sizeof(struct dc_state));
>   	if (!local_dc_state)
>   		return -ENOMEM;
> +	memcpy(local_dc_state, dm_state->context, sizeof(struct dc_state));
>   
>   	for (i = 0; i < local_dc_state->stream_count; i++) {
>   		struct dc_stream_state *stream = dm_state->context->streams[i];
> @@ -1563,7 +1564,7 @@ int pre_validate_dsc(struct drm_atomic_state *state,
>   			dc_stream_release(local_dc_state->streams[i]);
>   	}
>   
> -	kfree(local_dc_state);
> +	vfree(local_dc_state);
>   
>   	return ret;
>   }



More information about the amd-gfx mailing list