diff mbox series

[7/7] drm/i915: Trim unused workaround list entries

Message ID 20181130174412.15767-8-tvrtko.ursulin@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series Restore workarounds after engine reset and unify their handling | expand

Commit Message

Tvrtko Ursulin Nov. 30, 2018, 5:44 p.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

The new workaround list allocator grows the list in chunks so will end up
with some unused space. Trim it when the initialization phase is done to
free up a tiny bit of slab.

v2:
 * Simplify with kmemdup. (Chris Wilson)

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/i915/intel_workarounds.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Chris Wilson Nov. 30, 2018, 9:58 p.m. UTC | #1
Quoting Tvrtko Ursulin (2018-11-30 17:44:12)
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> The new workaround list allocator grows the list in chunks so will end up
> with some unused space. Trim it when the initialization phase is done to
> free up a tiny bit of slab.
> 
> v2:
>  * Simplify with kmemdup. (Chris Wilson)
> 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
>  drivers/gpu/drm/i915/intel_workarounds.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/intel_workarounds.c b/drivers/gpu/drm/i915/intel_workarounds.c
> index 3e6b388ea022..9d876d554e57 100644
> --- a/drivers/gpu/drm/i915/intel_workarounds.c
> +++ b/drivers/gpu/drm/i915/intel_workarounds.c
> @@ -55,6 +55,19 @@ static void wa_init_start(struct i915_wa_list *wal, const char *name)
>  
>  static void wa_init_finish(struct i915_wa_list *wal)
>  {
> +       /* Trim unused entries. */
> +       if (wal->count < wal->__size) {
> +               struct i915_wa *list = kmemdup(wal->list,
> +                                              wal->count * sizeof(*list),
> +                                              GFP_KERNEL);
> +
> +               if (list) {
> +                       kfree(wal->list);
> +                       wal->list = list;
> +                       wal->__size = wal->count;

Hmm. We could kill __size entirely if you reallocated on 
is_power_of_two(wal->count).

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
Tvrtko Ursulin Dec. 3, 2018, 10:39 a.m. UTC | #2
On 30/11/2018 21:58, Chris Wilson wrote:
> Quoting Tvrtko Ursulin (2018-11-30 17:44:12)
>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>
>> The new workaround list allocator grows the list in chunks so will end up
>> with some unused space. Trim it when the initialization phase is done to
>> free up a tiny bit of slab.
>>
>> v2:
>>   * Simplify with kmemdup. (Chris Wilson)
>>
>> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>> ---
>>   drivers/gpu/drm/i915/intel_workarounds.c | 13 +++++++++++++
>>   1 file changed, 13 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/i915/intel_workarounds.c b/drivers/gpu/drm/i915/intel_workarounds.c
>> index 3e6b388ea022..9d876d554e57 100644
>> --- a/drivers/gpu/drm/i915/intel_workarounds.c
>> +++ b/drivers/gpu/drm/i915/intel_workarounds.c
>> @@ -55,6 +55,19 @@ static void wa_init_start(struct i915_wa_list *wal, const char *name)
>>   
>>   static void wa_init_finish(struct i915_wa_list *wal)
>>   {
>> +       /* Trim unused entries. */
>> +       if (wal->count < wal->__size) {
>> +               struct i915_wa *list = kmemdup(wal->list,
>> +                                              wal->count * sizeof(*list),
>> +                                              GFP_KERNEL);
>> +
>> +               if (list) {
>> +                       kfree(wal->list);
>> +                       wal->list = list;
>> +                       wal->__size = wal->count;
> 
> Hmm. We could kill __size entirely if you reallocated on
> is_power_of_two(wal->count).

You mean allocate to next power of two is is_power_of_two(wal->count) ? 
In that case I could also allocate to next ALIGN(wal->count, CHUNK_SIZE) 
if IS_ALIGNED which looks more appropriate for this particular use case.

Can't decide whether it is worth it though. Why not..

Regards,

Tvrtko

> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> -Chris
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/intel_workarounds.c b/drivers/gpu/drm/i915/intel_workarounds.c
index 3e6b388ea022..9d876d554e57 100644
--- a/drivers/gpu/drm/i915/intel_workarounds.c
+++ b/drivers/gpu/drm/i915/intel_workarounds.c
@@ -55,6 +55,19 @@  static void wa_init_start(struct i915_wa_list *wal, const char *name)
 
 static void wa_init_finish(struct i915_wa_list *wal)
 {
+	/* Trim unused entries. */
+	if (wal->count < wal->__size) {
+		struct i915_wa *list = kmemdup(wal->list,
+					       wal->count * sizeof(*list),
+					       GFP_KERNEL);
+
+		if (list) {
+			kfree(wal->list);
+			wal->list = list;
+			wal->__size = wal->count;
+		}
+	}
+
 	if (wal->count)
 		DRM_DEBUG_DRIVER("Initialized %u %s workarounds\n",
 				 wal->wa_count, wal->name);