Commit 63335b38 authored by Mukul Joshi's avatar Mukul Joshi Committed by Alex Deucher

drm/amdkfd: Add VRAM accounting for SVM migration

Do VRAM accounting when doing migrations to vram to make sure
there is enough available VRAM and migrating to VRAM doesn't evict
other possible non-unified memory BOs. If migrating to VRAM fails,
driver can fall back to using system memory seamlessly.
Signed-off-by: default avatarMukul Joshi <mukul.joshi@amd.com>
Reviewed-by: default avatarFelix Kuehling <felix.kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent fa7bb2ca
...@@ -509,10 +509,19 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc, ...@@ -509,10 +509,19 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc,
start = start_mgr << PAGE_SHIFT; start = start_mgr << PAGE_SHIFT;
end = (last_mgr + 1) << PAGE_SHIFT; end = (last_mgr + 1) << PAGE_SHIFT;
r = amdgpu_amdkfd_reserve_mem_limit(node->adev,
prange->npages * PAGE_SIZE,
KFD_IOC_ALLOC_MEM_FLAGS_VRAM,
node->xcp ? node->xcp->id : 0);
if (r) {
dev_dbg(node->adev->dev, "failed to reserve VRAM, r: %ld\n", r);
return -ENOSPC;
}
r = svm_range_vram_node_new(node, prange, true); r = svm_range_vram_node_new(node, prange, true);
if (r) { if (r) {
dev_dbg(node->adev->dev, "fail %ld to alloc vram\n", r); dev_dbg(node->adev->dev, "fail %ld to alloc vram\n", r);
return r; goto out;
} }
ttm_res_offset = (start_mgr - prange->start + prange->offset) << PAGE_SHIFT; ttm_res_offset = (start_mgr - prange->start + prange->offset) << PAGE_SHIFT;
...@@ -545,6 +554,11 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc, ...@@ -545,6 +554,11 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc,
svm_range_vram_node_free(prange); svm_range_vram_node_free(prange);
} }
out:
amdgpu_amdkfd_unreserve_mem_limit(node->adev,
prange->npages * PAGE_SIZE,
KFD_IOC_ALLOC_MEM_FLAGS_VRAM,
node->xcp ? node->xcp->id : 0);
return r < 0 ? r : 0; return r < 0 ? r : 0;
} }
......
...@@ -3426,7 +3426,7 @@ svm_range_trigger_migration(struct mm_struct *mm, struct svm_range *prange, ...@@ -3426,7 +3426,7 @@ svm_range_trigger_migration(struct mm_struct *mm, struct svm_range *prange,
mm, KFD_MIGRATE_TRIGGER_PREFETCH); mm, KFD_MIGRATE_TRIGGER_PREFETCH);
*migrated = !r; *migrated = !r;
return r; return 0;
} }
int svm_range_schedule_evict_svm_bo(struct amdgpu_amdkfd_fence *fence) int svm_range_schedule_evict_svm_bo(struct amdgpu_amdkfd_fence *fence)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment