Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [High] Flexible array conversion forces inefficient order-1 (8KB) allocations 
for page directories.
--

commit ed37e64eb293a3ef09353d34ef014044171cfe28
Author: Rosen Penev <[email protected]>
drm: i915: use kzalloc_flex

This patch simplifies the allocation of i915_page_directory structures by
replacing a pointer with a flexible array member, consolidating two
allocations into one.

> diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.h 
> b/drivers/gpu/drm/i915/gt/intel_gtt.h
> index b54ee4f25af10..642b5c856a55a 100644
> --- a/drivers/gpu/drm/i915/gt/intel_gtt.h
> +++ b/drivers/gpu/drm/i915/gt/intel_gtt.h
> @@ -186,7 +186,7 @@ struct i915_page_table {
>  struct i915_page_directory {
>       struct i915_page_table pt;
>       spinlock_t lock;
> -     void **entry;
> +     void *entry[];
>  };
>  
>  #define __px_choose_expr(x, type, expr, other) \
> diff --git a/drivers/gpu/drm/i915/gt/intel_ppgtt.c 
> b/drivers/gpu/drm/i915/gt/intel_ppgtt.c
> index 72d8473a448b9..20cc59a005c97 100644
> --- a/drivers/gpu/drm/i915/gt/intel_ppgtt.c
> +++ b/drivers/gpu/drm/i915/gt/intel_ppgtt.c
> @@ -36,16 +36,10 @@ struct i915_page_directory *__alloc_pd(int count)
>  {
>       struct i915_page_directory *pd;
>  
> -     pd = kzalloc_obj(*pd, I915_GFP_ALLOW_FAIL);
> +     pd = kzalloc_flex(*pd, entry, count, I915_GFP_ALLOW_FAIL);

[Severity: High]
Does this flexible array conversion force inefficient order-1 (8KB)
allocations for page directories?

Consolidating the entry array into struct i915_page_directory pushes the
allocation size from exactly 4096 bytes (for the array) to 4128 bytes. The
base struct is roughly 32 bytes, plus 512 * 8 bytes for the flexible array.

On systems with 4KB pages (like x86), a 4128-byte request cannot be satisfied
by the kmalloc-4k cache and spills over to the kmalloc-8k cache. This requires
an order-1 page allocation, wasting 4064 bytes per page directory and
significantly increasing the risk of allocation failures under memory
fragmentation compared to the previous order-0 allocation.

[ ... ]

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

Reply via email to