Skip to content

Commit 0c2dece

Browse files
amd-yangpalexdeucher
authored andcommitted
drm/amdkfd: Page aligned memory reserve size
Use page aligned size to reserve memory usage because page aligned TTM BO size is used to unreserve memory usage, otherwise no page aligned size causes memory usage accounting unbalanced. Change vram_used definition type to int64_t to be able to trigger WARN_ONCE(adev && adev->kfd.vram_used < 0, "..."), to help debug the accounting issue with warning and backtrace. Signed-off-by: Philip Yang <Philip.Yang@amd.com> Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 23b02b0 commit 0c2dece

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct amdgpu_amdkfd_fence {
9797

9898
struct amdgpu_kfd_dev {
9999
struct kfd_dev *dev;
100-
uint64_t vram_used;
100+
int64_t vram_used;
101101
uint64_t vram_used_aligned;
102102
bool init_complete;
103103
struct work_struct reset_work;

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
15981598
struct amdgpu_bo *bo;
15991599
struct drm_gem_object *gobj = NULL;
16001600
u32 domain, alloc_domain;
1601+
uint64_t aligned_size;
16011602
u64 alloc_flags;
16021603
int ret;
16031604

@@ -1653,22 +1654,23 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
16531654
* the memory.
16541655
*/
16551656
if ((*mem)->aql_queue)
1656-
size = size >> 1;
1657+
size >>= 1;
1658+
aligned_size = PAGE_ALIGN(size);
16571659

16581660
(*mem)->alloc_flags = flags;
16591661

16601662
amdgpu_sync_create(&(*mem)->sync);
16611663

1662-
ret = amdgpu_amdkfd_reserve_mem_limit(adev, size, flags);
1664+
ret = amdgpu_amdkfd_reserve_mem_limit(adev, aligned_size, flags);
16631665
if (ret) {
16641666
pr_debug("Insufficient memory\n");
16651667
goto err_reserve_limit;
16661668
}
16671669

16681670
pr_debug("\tcreate BO VA 0x%llx size 0x%llx domain %s\n",
1669-
va, size, domain_string(alloc_domain));
1671+
va, (*mem)->aql_queue ? size << 1 : size, domain_string(alloc_domain));
16701672

1671-
ret = amdgpu_gem_object_create(adev, size, 1, alloc_domain, alloc_flags,
1673+
ret = amdgpu_gem_object_create(adev, aligned_size, 1, alloc_domain, alloc_flags,
16721674
bo_type, NULL, &gobj);
16731675
if (ret) {
16741676
pr_debug("Failed to create BO on domain %s. ret %d\n",
@@ -1725,7 +1727,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
17251727
/* Don't unreserve system mem limit twice */
17261728
goto err_reserve_limit;
17271729
err_bo_create:
1728-
amdgpu_amdkfd_unreserve_mem_limit(adev, size, flags);
1730+
amdgpu_amdkfd_unreserve_mem_limit(adev, aligned_size, flags);
17291731
err_reserve_limit:
17301732
mutex_destroy(&(*mem)->lock);
17311733
if (gobj)

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,13 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
11271127
}
11281128

11291129
/* Update the VRAM usage count */
1130-
if (flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)
1131-
WRITE_ONCE(pdd->vram_usage, pdd->vram_usage + args->size);
1130+
if (flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
1131+
uint64_t size = args->size;
1132+
1133+
if (flags & KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM)
1134+
size >>= 1;
1135+
WRITE_ONCE(pdd->vram_usage, pdd->vram_usage + PAGE_ALIGN(size));
1136+
}
11321137

11331138
mutex_unlock(&p->mutex);
11341139

0 commit comments

Comments
 (0)