Skip to contentSkip to conversation

drm: i915: use kzalloc_flex

PATCH Superseded Rosen Penev 3 participants 3 messages Jun 30 – Jul 1

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: i915: use kzalloc_flex

Simplifies allocations by using a flexible array member in this struct. No need to free separately.

---
 drivers/gpu/drm/i915/gt/intel_gtt.h   |  2 +-
 drivers/gpu/drm/i915/gt/intel_ppgtt.c | 15 +--------------
 2 files changed, 2 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/gt/intel_gtt.h +1 -1
index f6f223090760..49b2d2d24fd8 100644
@@ -187,7 +187,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) \
drivers/gpu/drm/i915/gt/intel_ppgtt.c +1 -14
index 72d8473a448b..20cc59a005c9 100644
@@ -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);
 	if (unlikely(!pd))
 		return NULL;
 
-	pd->entry = kzalloc_objs(*pd->entry, count, I915_GFP_ALLOW_FAIL);
-	if (unlikely(!pd->entry)) {
-		kfree(pd);
-		return NULL;
-	}
-
 	spin_lock_init(&pd->lock);
 	return pd;
 }
@@ -60,7 +54,6 @@ struct i915_page_directory *alloc_pd(struct i915_address_space *vm)
 
 	pd->pt.base = vm->alloc_pt_dma(vm, I915_GTT_PAGE_SIZE_4K);
 	if (IS_ERR(pd->pt.base)) {
-		kfree(pd->entry);
 		kfree(pd);
 		return ERR_PTR(-ENOMEM);
 	}
@@ -72,12 +65,6 @@ void free_px(struct i915_address_space *vm, struct i915_page_table *pt, int lvl)
 {
 	BUILD_BUG_ON(offsetof(struct i915_page_directory, pt));
 
-	if (lvl) {
-		struct i915_page_directory *pd =
-			container_of(pt, typeof(*pd), pt);
-		kfree(pd->entry);
-	}
-
 	if (pt->base)
 		i915_gem_object_put(pt->base);
 
Signature · 1 line
2.54.0
#1 lore raw
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. --

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.

Quoted 18 lines
drivers/gpu/drm/i915/gt/intel_gtt.h +1 -1
index b54ee4f25af10..642b5c856a55a 100644
@@ -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) \
drivers/gpu/drm/i915/gt/intel_ppgtt.c +0 -0
index 72d8473a448b9..20cc59a005c97 100644

drivers/gpu/drm/i915/gt/intel_ppgtt.c struct i915_page_directory *__alloc_pd(int count) · line 39

Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_ppgtt.c +1 -1
@@ -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.

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw

✗ LGCI.VerificationFailed: failure for drm: i915: use kzalloc_flex

In reply to Rosen Penev
== Series Details ==

== Series Details ==

Series: drm: i915: use kzalloc_flex
URL : https://patchwork.freedesktop.org/series/169617/
State : failure

== Summary ==

Series author address '[email protected]' is not on the allowlist, which prevents CI from being automatically triggered. If you want CI to run for this series, ask Patchwork project owners to click 'retest' on the series in Patchwork. Exception occurred during validation, bailing out!
Build URL: http://gfx-ci.igk.intel.com:8080/job/CI_PW_kernel/180290/ (on built-in)