Skip to contentSkip to conversation

Fit one IB struct amdgpu_job into a 512 byte slab

PATCH In review Tvrtko Ursulin 1 participant 4 messages Feb 24, 2025 – Feb 25, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Fit one IB struct amdgpu_job into a 512 byte slab

A lot of the workloads create jobs with just one IB and if we re-order some struct members we can stop that allocation spilling into the 1k SLAB bucket.

Before:

sizeof(struct amdgpu_job) + sizeof(struct amdgpu_ib) = 480 + 40 = 520

After:

sizeof(struct amdgpu_job) + sizeof(struct amdgpu_ib) = 472 + 32 = 504

It is not a huge gain in the big picture but every little helps.

Tvrtko Ursulin (2):
drm/amdgpu: Remove hole from struct amdgpu_ib
drm/amdgpu: Reduce holes in struct amdgpu_job

 drivers/gpu/drm/amd/amdgpu/amdgpu_job.h  | 19 ++++++++-----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  4 ++--
 2 files changed, 10 insertions(+), 13 deletions(-)
Signature · 1 line
2.48.0
#1 lore raw

PATCH 1/2 drm/amdgpu: Remove hole from struct amdgpu_ib

Group the 32- vs 64- members together to remove hole from the struct.

Before:

        /* size: 40, cachelines: 1, members: 5 */
        /* sum members: 32, holes: 1, sum holes: 4 */
        /* padding: 4 */
        /* last cacheline: 40 bytes */

After:

        /* size: 32, cachelines: 1, members: 5 */
        /* last cacheline: 32 bytes */
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -2
index e13407cbb040..9a7ffbc53363 100644
@@ -97,9 +97,9 @@ enum amdgpu_ib_pool_type {
 
 struct amdgpu_ib {
 	struct drm_suballoc		*sa_bo;
-	uint32_t			length_dw;
-	uint64_t			gpu_addr;
 	uint32_t			*ptr;
+	uint64_t			gpu_addr;
+	uint32_t			length_dw;
 	uint32_t			flags;
 };
 
Signature · 1 line
2.48.0
#2 lore raw

PATCH 2/2 drm/amdgpu: Reduce holes in struct amdgpu_job

In reply to Tvrtko Ursulin

Lets group same width types closer together to reduce the number and size of the holes in the struct.

Before:

        /* size: 480, cachelines: 8, members: 30 */
        /* sum members: 469, holes: 3, sum holes: 11 */
        /* forced alignments: 1 */
        /* last cacheline: 32 bytes */

After:

        /* size: 472, cachelines: 8, members: 30 */
        /* sum members: 469, holes: 1, sum holes: 3 */
        /* forced alignments: 1 */
        /* last cacheline: 24 bytes */
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +8 -11
index ce6b9ba967ff..7e5fe3d73a06 100644
@@ -50,17 +50,22 @@ struct amdgpu_job {
 	struct amdgpu_sync	explicit_sync;
 	struct dma_fence	hw_fence;
 	struct dma_fence	*gang_submit;
-	uint32_t		preamble_status;
-	uint32_t                preemption_status;
 	bool                    vm_needs_flush;
 	bool			gds_switch_needed;
 	bool			spm_update_needed;
-	uint64_t		vm_pd_addr;
+	bool			enforce_isolation;
+	bool			init_shadow;
 	unsigned		vmid;
 	unsigned		pasid;
+	uint32_t		num_ibs;
+	uint32_t		preamble_status;
+	uint32_t                preemption_status;
 	uint32_t		gds_base, gds_size;
 	uint32_t		gws_base, gws_size;
 	uint32_t		oa_base, oa_size;
+	/* job_run_counter >= 1 means a resubmit job */
+	uint32_t		job_run_counter;
+	uint64_t		vm_pd_addr;
 	uint64_t		generation;
 
 	/* user fence handling */
@@ -71,15 +76,7 @@ struct amdgpu_job {
 	uint64_t		shadow_va;
 	uint64_t		csa_va;
 	uint64_t		gds_va;
-	bool			init_shadow;
 
-	/* job_run_counter >= 1 means a resubmit job */
-	uint32_t		job_run_counter;
-
-	/* enforce isolation */
-	bool			enforce_isolation;
-
-	uint32_t		num_ibs;
 	struct amdgpu_ib	ibs[];
 };
 
Signature · 1 line
2.48.0
#3 lore raw
In reply to Tvrtko Ursulin
Quoted 5 lines · Tvrtko Ursulin

A lot of the workloads create jobs with just one IB and if we re-order some struct members we can stop that allocation spilling into the 1k SLAB bucket.

Before:

Quoted 7 lines
   sizeof(struct amdgpu_job) + sizeof(struct amdgpu_ib) = 480 + 40 = 520

After:

   sizeof(struct amdgpu_job) + sizeof(struct amdgpu_ib) = 472 + 32 = 504

It is not a huge gain in the big picture but every little helps.

FWIW it is also quite* possible to make two IB jobs fit into 512 by converting booleans to flags and shrinking some fields:

            /* size: 448, cachelines: 7, members: 24 */
            /* forced alignments: 1 */

So 448 + 2 * 64 = 512 !

That avoids spilling _any_ submissions, for example from Cyberpunk 2077, into the 1k SLAB bucket.

*) I said quite because as after I converted booleans to flags, which required u16 for 9 flags, shrunk vmid and num_ibs to u8 and job_run_counter to u16 (all of which seems completely fine), I needed just a tiny bit extra. So I shrank gws_size to u16. Being a size in pages that could also easily be large enough.

Regards,

Tvrtko

Quoted 8 lines

Tvrtko Ursulin (2):
drm/amdgpu: Remove hole from struct amdgpu_ib
drm/amdgpu: Reduce holes in struct amdgpu_job

  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h  | 19 ++++++++-----------
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  4 ++--
  2 files changed, 10 insertions(+), 13 deletions(-)