<div dir="ltr"><div>A better flag name would be:</div><div>AMDGPU_GEM_CREATE_BEST_PLACEMENT_OR_DISCARD</div><div><br></div><div>Marek<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 10, 2022 at 4:13 PM Marek Olšák <<a href="mailto:maraeo@gmail.com">maraeo@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Does this really guarantee VRAM placement? The code doesn't say anything about that.</div><div><br></div><div>Marek<br></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 6, 2022 at 7:23 AM Christian König <<a href="mailto:ckoenig.leichtzumerken@gmail.com" target="_blank">ckoenig.leichtzumerken@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Add a AMDGPU_GEM_CREATE_DISCARDABLE flag to note that the content of a BO<br>
doesn't needs to be preserved during eviction.<br>
<br>
KFD was already using a similar functionality for SVM BOs so replace the<br>
internal flag with the new UAPI.<br>
<br>
Only compile tested!<br>
<br>
Signed-off-by: Christian König <<a href="mailto:christian.koenig@amd.com" target="_blank">christian.koenig@amd.com</a>><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 4 ++--<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 1 +<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 -<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-<br>
drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 +-<br>
include/uapi/drm/amdgpu_drm.h | 4 ++++<br>
6 files changed, 9 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
index 2e16484bf606..bf97d8f07f57 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
@@ -302,8 +302,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,<br>
AMDGPU_GEM_CREATE_VRAM_CLEARED |<br>
AMDGPU_GEM_CREATE_VM_ALWAYS_VALID |<br>
AMDGPU_GEM_CREATE_EXPLICIT_SYNC |<br>
- AMDGPU_GEM_CREATE_ENCRYPTED))<br>
-<br>
+ AMDGPU_GEM_CREATE_ENCRYPTED |<br>
+ AMDGPU_GEM_CREATE_DISCARDABLE))<br>
return -EINVAL;<br>
<br>
/* reject invalid gem domains */<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
index 8b7ee1142d9a..1944ef37a61e 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
@@ -567,6 +567,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,<br>
bp->domain;<br>
bo->allowed_domains = bo->preferred_domains;<br>
if (bp->type != ttm_bo_type_kernel &&<br>
+ !(bp->flags & AMDGPU_GEM_CREATE_DISCARDABLE) &&<br>
bo->allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)<br>
bo->allowed_domains |= AMDGPU_GEM_DOMAIN_GTT;<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h<br>
index 4c9cbdc66995..147b79c10cbb 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h<br>
@@ -41,7 +41,6 @@<br>
<br>
/* BO flag to indicate a KFD userptr BO */<br>
#define AMDGPU_AMDKFD_CREATE_USERPTR_BO (1ULL << 63)<br>
-#define AMDGPU_AMDKFD_CREATE_SVM_BO (1ULL << 62)<br>
<br>
#define to_amdgpu_bo_user(abo) container_of((abo), struct amdgpu_bo_user, bo)<br>
#define to_amdgpu_bo_vm(abo) container_of((abo), struct amdgpu_bo_vm, bo)<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
index 41d6f604813d..ba3221a25e75 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
@@ -117,7 +117,7 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,<br>
}<br>
<br>
abo = ttm_to_amdgpu_bo(bo);<br>
- if (abo->flags & AMDGPU_AMDKFD_CREATE_SVM_BO) {<br>
+ if (abo->flags & AMDGPU_GEM_CREATE_DISCARDABLE) {<br>
placement->num_placement = 0;<br>
placement->num_busy_placement = 0;<br>
return;<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<br>
index 5ed8d9b549a4..835b5187f0b8 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<br>
@@ -531,7 +531,7 @@ svm_range_vram_node_new(struct amdgpu_device *adev, struct svm_range *prange,<br>
bp.domain = AMDGPU_GEM_DOMAIN_VRAM;<br>
bp.flags = AMDGPU_GEM_CREATE_NO_CPU_ACCESS;<br>
bp.flags |= clear ? AMDGPU_GEM_CREATE_VRAM_CLEARED : 0;<br>
- bp.flags |= AMDGPU_AMDKFD_CREATE_SVM_BO;<br>
+ bp.flags |= AMDGPU_GEM_CREATE_DISCARDABLE;<br>
bp.type = ttm_bo_type_device;<br>
bp.resv = NULL;<br>
<br>
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h<br>
index 9a1d210d135d..57b9d8f0133a 100644<br>
--- a/include/uapi/drm/amdgpu_drm.h<br>
+++ b/include/uapi/drm/amdgpu_drm.h<br>
@@ -140,6 +140,10 @@ extern "C" {<br>
* not require GTT memory accounting<br>
*/<br>
#define AMDGPU_GEM_CREATE_PREEMPTIBLE (1 << 11)<br>
+/* Flag that BO can be discarded under memory pressure without keeping the<br>
+ * content.<br>
+ */<br>
+#define AMDGPU_GEM_CREATE_DISCARDABLE (1 << 12)<br>
<br>
struct drm_amdgpu_gem_create_in {<br>
/** the requested memory size */<br>
-- <br>
2.25.1<br>
<br>
</blockquote></div>
</blockquote></div>