drm/amdgpu: Remove rounding from vram allocation path
Subsystems (3)
PATCH 1/2 drm/amdgpu: Remove rounding from vram allocation path
Rounding up allocations in the allocation path caused test regressions, so now just round in the availability path.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +5 -6
@@ -40,10 +40,10 @@#define AMDGPU_USERPTR_RESTORE_DELAY_MS 1/* -* Align VRAM allocations to 2MB to avoid fragmentation caused by 4K allocations in the tail 2MB +* Align VRAM availability to 2MB to avoid fragmentation caused by 4K allocations in the tail 2MB * BO chunk */ -#define VRAM_ALLOCATION_ALIGN (1 << 21) +#define VRAM_AVAILABLITY_ALIGN (1 << 21)/* Impose limit on how much memory KFD can use */ static struct {
@@ -149,7 +149,7 @@ static int amdgpu_amdkfd_reserve_mem_limit(struct amdgpu_device *adev,* to avoid fragmentation caused by 4K allocations in the tail * 2M BO chunk. */ - vram_needed =ALIGN (size,VRAM_ALLOCATION_ALIGN ); + vram_needed = size; }else if (alloc_flag &KFD_IOC_ALLOC_MEM_FLAGS_USERPTR ) { system_mem_needed = size; } else if (!(alloc_flag &
@@ -198,7 +198,7 @@ static void unreserve_mem_limit(struct amdgpu_device *adev, kfd_mem_limit.system_mem_used -= size; kfd_mem_limit.ttm_mem_used -= size; }else if (alloc_flag &KFD_IOC_ALLOC_MEM_FLAGS_VRAM ) { - adev->kfd.vram_used -=ALIGN (size,VRAM_ALLOCATION_ALIGN ); + adev->kfd.vram_used -= size; }else if (alloc_flag &KFD_IOC_ALLOC_MEM_FLAGS_USERPTR ) { kfd_mem_limit.system_mem_used -= size; } else if (!(alloc_flag &
@@ -1642,7 +1642,6 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev)uint64_t reserved_for_pt =ESTIMATE_PT_SIZE (amdgpu_amdkfd_total_mem_size);size_t available; -spin_lock (&kfd_mem_limit.mem_limit_lock); available = adev->gmc.real_vram_size - adev->kfd.vram_used
@@ -1650,7 +1649,7 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev) - reserved_for_pt;spin_unlock (&kfd_mem_limit.mem_limit_lock); -return ALIGN_DOWN (available,VRAM_ALLOCATION_ALIGN ); +return ALIGN_DOWN (available,VRAM_AVAILABLITY_ALIGN ); } int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
Signature · 1 line
2.34.1
PATCH 2/2 drm/amdgpu: Pessimistic availability based on rounded up allocations
Seperately accumulate a statistic of rounded up allocations to use to report availability, with a view to increasing the likelihood a buffer object can be successfully allocated at exactly the size reported by the availability API.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
@@ -96,6 +96,7 @@ struct amdgpu_amdkfd_fence {struct amdgpu_kfd_dev {struct kfd_dev *dev;uint64_t vram_used; +uint64_t vram_used_aligned;bool init_complete;struct work_struct reset_work; };
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3 -1
@@ -181,6 +181,7 @@ static int amdgpu_amdkfd_reserve_mem_limit(struct amdgpu_device *adev,* memory, TTM memory and GPU memory as computed above */ adev->kfd.vram_used += vram_needed; + adev->kfd.vram_used_aligned +=ALIGN (vram_needed,VRAM_AVAILABLITY_ALIGN ); kfd_mem_limit.system_mem_used += system_mem_needed; kfd_mem_limit.ttm_mem_used += ttm_mem_needed;
@@ -199,6 +200,7 @@ static void unreserve_mem_limit(struct amdgpu_device *adev, kfd_mem_limit.ttm_mem_used -= size; }else if (alloc_flag &KFD_IOC_ALLOC_MEM_FLAGS_VRAM ) { adev->kfd.vram_used -= size; + adev->kfd.vram_used_aligned -=ALIGN (size,VRAM_AVAILABLITY_ALIGN ); }else if (alloc_flag &KFD_IOC_ALLOC_MEM_FLAGS_USERPTR ) { kfd_mem_limit.system_mem_used -= size; } else if (!(alloc_flag &
@@ -1644,7 +1646,7 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev)size_t available;spin_lock (&kfd_mem_limit.mem_limit_lock); available = adev->gmc.real_vram_size - - adev->kfd.vram_used + - adev->kfd.vram_used_aligned -atomic64_read (&adev->vram_pin_size) - reserved_for_pt;spin_unlock (&kfd_mem_limit.mem_limit_lock);
Signature · 1 line
2.34.1
Re: [PATCH 2/2] drm/amdgpu: Pessimistic availability based on rounded up allocations
Your patches are missing Signed-off-by lines. If you use "git commit -s", git should add those automatically for your convenience. Other than that, the patches look good to me. With Signed-off-by added, the series is
Am 2022-07-28 um 23:16 schrieb Daniel Phillips:
Quoted 50 lines
Seperately accumulate a statistic of rounded up allocations to use to report availability, with a view to increasing the likelihood a buffer object can be successfully allocated at exactly the size reported by the availability API.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-0@@ -96,6 +96,7 @@ struct amdgpu_amdkfd_fence {struct amdgpu_kfd_dev {struct kfd_dev *dev;uint64_t vram_used; +uint64_t vram_used_aligned;bool init_complete;struct work_struct reset_work; };drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-1@@ -181,6 +181,7 @@ static int amdgpu_amdkfd_reserve_mem_limit(struct amdgpu_device *adev,* memory, TTM memory and GPU memory as computed above */ adev->kfd.vram_used += vram_needed; + adev->kfd.vram_used_aligned +=ALIGN (vram_needed,VRAM_AVAILABLITY_ALIGN ); kfd_mem_limit.system_mem_used += system_mem_needed; kfd_mem_limit.ttm_mem_used += ttm_mem_needed;@@ -199,6 +200,7 @@ static void unreserve_mem_limit(struct amdgpu_device *adev, kfd_mem_limit.ttm_mem_used -= size; }else if (alloc_flag &KFD_IOC_ALLOC_MEM_FLAGS_VRAM ) { adev->kfd.vram_used -= size; + adev->kfd.vram_used_aligned -=ALIGN (size,VRAM_AVAILABLITY_ALIGN ); }else if (alloc_flag &KFD_IOC_ALLOC_MEM_FLAGS_USERPTR ) { kfd_mem_limit.system_mem_used -= size; } else if (!(alloc_flag &@@ -1644,7 +1646,7 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev)size_t available;spin_lock (&kfd_mem_limit.mem_limit_lock); available = adev->gmc.real_vram_size - - adev->kfd.vram_used + - adev->kfd.vram_used_aligned -atomic64_read (&adev->vram_pin_size) - reserved_for_pt;spin_unlock (&kfd_mem_limit.mem_limit_lock);