Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Medium] drm: memory waste in drm_exec due to unaligned kvmalloc size
--

commit c9e9f41b6b460bbc9dee72fd6820d00dc1915559
Author: Matthew Brost <[email protected]>

drm/exec: track the first few locked objects inline

This commit adds tracking for the first few locked objects inline within
the drm_exec structure. This avoids early allocations and prevents
-ENOMEM failures on paths that only need to lock a few objects.

Link: 
https://sashiko.dev/#/patchset/20261001220632.3190896-1-matthew.brost%40intel.com

> diff --git a/drivers/gpu/drm/drm_exec.c b/drivers/gpu/drm/drm_exec.c
> --- a/drivers/gpu/drm/drm_exec.c
> +++ b/drivers/gpu/drm/drm_exec.c
[ ... ]
> @@ -140,9 +148,16 @@ static int drm_exec_obj_locked(struct drm_exec *exec,
>  {
>       if (unlikely(exec->num_objects == exec->max_objects)) {
>               size_t size = exec->max_objects * sizeof(void *);
> -             void *tmp;
> -
> -             tmp = kvrealloc(exec->objects, size + PAGE_SIZE, GFP_KERNEL);
> +             struct drm_gem_object **tmp;
> +
> +             if (exec->objects == exec->inline_objects) {
> +                     tmp = kvmalloc(size + PAGE_SIZE, GFP_KERNEL);

[Severity: Medium]
When falling back from the inline storage, size is 64 bytes (8 pointers).
The code requests kvmalloc(64 + 4096), which is 4160 bytes. Does this
cause the slab allocator to round up to the kmalloc-8k cache, wasting
nearly half the allocation?

> +                     if (tmp)
> +                             memcpy(tmp, exec->objects, size);
> +             } else {
> +                     tmp = kvrealloc(exec->objects, size + PAGE_SIZE,
> +                                     GFP_KERNEL);
> +             }
>               if (!tmp)
>                       return -ENOMEM;
>  
>               exec->objects = tmp;
>               exec->max_objects += PAGE_SIZE / sizeof(void *);

[Severity: Medium]
Since max_objects started at 8, adding PAGE_SIZE / sizeof(void *) makes
max_objects 520. When the array grows again, size will be 4160 and
kvrealloc will request 8256 bytes, forcing kmalloc-16k. Does this continue
to waste memory at every growth step because the total object count remains
unaligned to the page size?

-- 
Sashiko AI review · 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to