Skip to contentSkip to conversation

drm/amd/display: use vmalloc for struct dc_state

PATCH In review Alex Deucher 2 participants 2 messages Jun 26, 2024 – Jun 27, 2024

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amd/display: use vmalloc for struct dc_state

This is a big structure so use vmalloc as malloc can fail when there is memory pressure.

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +3 -2
index 5d4f831b1e55..080c1d5f7412 100644
@@ -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;
 }
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Alex Deucher

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.

Quoted 32 lines
---
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +3 -2
index 5d4f831b1e55..080c1d5f7412 100644
@@ -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;
  }