Skip to contentSkip to conversation

drm/ttm: Fix the memory delay free issue

PATCH In review Emily Deng 3 participants 8 messages Jul 10, 2019 – Jul 15, 2019 7 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Emily Deng

author
#0 lore raw

PATCH 1/1 drm/ttm: Fix the memory delay free issue

For vulkan cts allocation test cases, they will create a series of bos, and then free them. As it has lots of alloction test cases with the same vm, as per vm bo feature enable, all of those bos' resv are the same. But the bo free is quite slow, as they use the same resv object, for every time, free a bo,
it will check the resv whether signal, if it signal, then will free it. But as the test cases will continue to create bo, and the resv fence is increasing. So the free is more slower than creating. It will cause memory exhausting.

Method:
When the resv signal, release all the bos which are use the same resv object.

---
 drivers/gpu/drm/ttm/ttm_bo.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +24 -5
index f9a3d4c..57ec59b 100644
@@ -543,6 +543,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
 {
 	struct ttm_bo_global *glob = bo->bdev->glob;
 	struct reservation_object *resv;
+	struct ttm_buffer_object *resv_bo, *resv_bo_next;
 	int ret;
 
 	if (unlikely(list_empty(&bo->ddestroy)))
@@ -566,10 +567,14 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
 							   interruptible,
 							   30 * HZ);
 
-		if (lret < 0)
+		if (lret < 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
 			return lret;
-		else if (lret == 0)
+		}
+		else if (lret == 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
 			return -EBUSY;
+		}
 
 		spin_lock(&glob->lru_lock);
 		if (unlock_resv && !kcl_reservation_object_trylock(bo->resv)) {
@@ -582,6 +587,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
 			 * here.
 			 */
 			spin_unlock(&glob->lru_lock);
+			kref_put(&bo->list_kref, ttm_bo_release_list);
 			return 0;
 		}
 		ret = 0;
@@ -591,15 +597,29 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
 		if (unlock_resv)
 			kcl_reservation_object_unlock(bo->resv);
 		spin_unlock(&glob->lru_lock);
+		kref_put(&bo->list_kref, ttm_bo_release_list);
 		return ret;
 	}
 
 	ttm_bo_del_from_lru(bo);
 	list_del_init(&bo->ddestroy);
 	kref_put(&bo->list_kref, ttm_bo_ref_bug);
-
 	spin_unlock(&glob->lru_lock);
 	ttm_bo_cleanup_memtype_use(bo);
+	kref_put(&bo->list_kref, ttm_bo_release_list);
+
+	spin_lock(&glob->lru_lock);
+	list_for_each_entry_safe(resv_bo, resv_bo_next, &bo->bdev->ddestroy, ddestroy) {
+		if (resv_bo->resv == bo->resv) {
+			ttm_bo_del_from_lru(resv_bo);
+			list_del_init(&resv_bo->ddestroy);
+			spin_unlock(&glob->lru_lock);
+			ttm_bo_cleanup_memtype_use(resv_bo);
+			kref_put(&resv_bo->list_kref, ttm_bo_release_list);
+			spin_lock(&glob->lru_lock);
+		}
+	}
+	spin_unlock(&glob->lru_lock);
 
 	if (unlock_resv)
 		kcl_reservation_object_unlock(bo->resv);
@@ -639,9 +659,8 @@ static bool ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all)
 			ttm_bo_cleanup_refs(bo, false, !remove_all, true);
 		} else {
 			spin_unlock(&glob->lru_lock);
+			kref_put(&bo->list_kref, ttm_bo_release_list);
 		}
-
-		kref_put(&bo->list_kref, ttm_bo_release_list);
 		spin_lock(&glob->lru_lock);
 	}
 	list_splice_tail(&removed, &bdev->ddestroy);
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1562750971-1628-1-git-send-email-Emily.Deng-5C7GfCeVMHo@public.gmane.org

#2 lore raw

It doesn't make sense that freeing BO still uses per-vm resv.

I remember when BO is in release list, its resv will be from per-vm resv copy. Could you check it?

-David

Quoted 86 lines · Emily Deng

For vulkan cts allocation test cases, they will create a series of bos, and then free them. As it has lots of alloction test cases with the same vm, as per vm bo feature enable, all of those bos' resv are the same. But the bo free is quite slow, as they use the same resv object, for every time, free a bo,
it will check the resv whether signal, if it signal, then will free it. But as the test cases will continue to create bo, and the resv fence is increasing. So the free is more slower than creating. It will cause memory exhausting.

Method:
When the resv signal, release all the bos which are use the same resv object.

---
  drivers/gpu/drm/ttm/ttm_bo.c | 29 ++++++++++++++++++++++++-----
  1 file changed, 24 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +23 -3
index f9a3d4c..57ec59b 100644
@@ -543,6 +543,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
  {
  	struct ttm_bo_global *glob = bo->bdev->glob;
  	struct reservation_object *resv;
+	struct ttm_buffer_object *resv_bo, *resv_bo_next;
  	int ret;
 
  	if (unlikely(list_empty(&bo->ddestroy)))
@@ -566,10 +567,14 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
  							   interruptible,
  							   30 * HZ);
 
-		if (lret < 0)
+		if (lret < 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
  			return lret;
-		else if (lret == 0)
+		}
+		else if (lret == 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
  			return -EBUSY;
+		}
 
  		spin_lock(&glob->lru_lock);
  		if (unlock_resv && !kcl_reservation_object_trylock(bo->resv)) {
@@ -582,6 +587,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
  			 * here.
  			 */
  			spin_unlock(&glob->lru_lock);
+			kref_put(&bo->list_kref, ttm_bo_release_list);
  			return 0;
  		}
  		ret = 0;
@@ -591,15 +597,29 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
  		if (unlock_resv)
  			kcl_reservation_object_unlock(bo->resv);
  		spin_unlock(&glob->lru_lock);
+		kref_put(&bo->list_kref, ttm_bo_release_list);
  		return ret;
  	}
 
  	ttm_bo_del_from_lru(bo);
  	list_del_init(&bo->ddestroy);
  	kref_put(&bo->list_kref, ttm_bo_ref_bug);
-
  	spin_unlock(&glob->lru_lock);
  	ttm_bo_cleanup_memtype_use(bo);
+	kref_put(&bo->list_kref, ttm_bo_release_list);
+
+	spin_lock(&glob->lru_lock);
+	list_for_each_entry_safe(resv_bo, resv_bo_next, &bo->bdev->ddestroy, ddestroy) {
+		if (resv_bo->resv == bo->resv) {
+			ttm_bo_del_from_lru(resv_bo);
+			list_del_init(&resv_bo->ddestroy);
+			spin_unlock(&glob->lru_lock);
+			ttm_bo_cleanup_memtype_use(resv_bo);
+			kref_put(&resv_bo->list_kref, ttm_bo_release_list);
+			spin_lock(&glob->lru_lock);
+		}
+	}
+	spin_unlock(&glob->lru_lock);
 
  	if (unlock_resv)
  		kcl_reservation_object_unlock(bo->resv);

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all) · line 666

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -2
@@ -639,9 +659,8 @@ static bool ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all)
  			ttm_bo_cleanup_refs(bo, false, !remove_all, true);
  		} else {
  			spin_unlock(&glob->lru_lock);
+			kref_put(&bo->list_kref, ttm_bo_release_list);
  		}
-
-		kref_put(&bo->list_kref, ttm_bo_release_list);
  		spin_lock(&glob->lru_lock);
  	}
  	list_splice_tail(&removed, &bdev->ddestroy);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): a9974a9a-37b2-2310-4073-94eef570f37c-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Hi David,
You are right, it will copy per-vm resv.
But currently, it still has the delay free issue which non per vm bo doesn't has. Maybe it already has new fences append to this resv object before copy.

Hi Christian,
Do you have any suggestion about this? For per vm bo, it seems always delay to free the ttm bo.

Best wishes
Emily Deng

Quoted 108 lines

-----Original Message-----
From: Zhou, David(ChunMing) <[email protected]>
Sent: Wednesday, July 10, 2019 9:28 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

It doesn't make sense that freeing BO still uses per-vm resv.

I remember when BO is in release list, its resv will be from per-vm resv copy. Could you check it?

-David

Quoted 7 lines · Emily Deng

For vulkan cts allocation test cases, they will create a series of bos, and then free them. As it has lots of alloction test cases with the same vm, as per vm bo feature enable, all of those bos' resv are the same. But the bo free is quite slow, as they use the same resv object, for every time, free a bo, it will check the resv whether signal, if it signal, then will free it. But as the test cases will continue to create bo, and the resv fence is increasing. So the free is more

slower than creating. It will cause memory exhausting.

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 15 lines

Method:
When the resv signal, release all the bos which are use the same resv object.

---
  drivers/gpu/drm/ttm/ttm_bo.c | 29 ++++++++++++++++++++++++-----
  1 file changed, 24 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/ttm/ttm_bo.c index f9a3d4c..57ec59b 100644

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -543,6 +543,7 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
  {
  	struct ttm_bo_global *glob = bo->bdev->glob;
  	struct reservation_object *resv;
+	struct ttm_buffer_object *resv_bo, *resv_bo_next;
  	int ret;
 
  	if (unlikely(list_empty(&bo->ddestroy)))
@@ -566,10 +567,14 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

Quoted 6 lines
drivers/gpu/drm/ttm/ttm_bo.c +2 -1
  							   interruptible,
  							   30 * HZ);
 
-		if (lret < 0)
+		if (lret < 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +4 -1
  			return lret;
-		else if (lret == 0)
+		}
+		else if (lret == 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
  			return -EBUSY;
+		}
 
  		spin_lock(&glob->lru_lock);
  		if (unlock_resv && !kcl_reservation_object_trylock(bo->resv))

{ @@

Quoted 1 line

-582,6 +587,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object

*bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines

* here.
*/
spin_unlock(&glob->lru_lock);

drivers/gpu/drm/ttm/ttm_bo.c +1 -0
+			kref_put(&bo->list_kref, ttm_bo_release_list);
  			return 0;
  		}
  		ret = 0;
@@ -591,15 +597,29 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct

Quoted 32 lines
drivers/gpu/drm/ttm/ttm_bo.c +15 -1
  		if (unlock_resv)
  			kcl_reservation_object_unlock(bo->resv);
  		spin_unlock(&glob->lru_lock);
+		kref_put(&bo->list_kref, ttm_bo_release_list);
  		return ret;
  	}
 
  	ttm_bo_del_from_lru(bo);
  	list_del_init(&bo->ddestroy);
  	kref_put(&bo->list_kref, ttm_bo_ref_bug);
-
  	spin_unlock(&glob->lru_lock);
  	ttm_bo_cleanup_memtype_use(bo);
+	kref_put(&bo->list_kref, ttm_bo_release_list);
+
+	spin_lock(&glob->lru_lock);
+	list_for_each_entry_safe(resv_bo, resv_bo_next, &bo->bdev-
 ddestroy, ddestroy) {
+		if (resv_bo->resv == bo->resv) {
+			ttm_bo_del_from_lru(resv_bo);
+			list_del_init(&resv_bo->ddestroy);
+			spin_unlock(&glob->lru_lock);
+			ttm_bo_cleanup_memtype_use(resv_bo);
+			kref_put(&resv_bo->list_kref, ttm_bo_release_list);
+			spin_lock(&glob->lru_lock);
+		}
+	}
+	spin_unlock(&glob->lru_lock);
 
  	if (unlock_resv)
  		kcl_reservation_object_unlock(bo->resv);
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -639,9 +659,8 @@ static bool ttm_bo_delayed_delete(struct

ttm_bo_device *bdev, bool remove_all)

Quoted 10 lines

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all) · line 666

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -2
  			ttm_bo_cleanup_refs(bo, false, !remove_all, true);
  		} else {
  			spin_unlock(&glob->lru_lock);
+			kref_put(&bo->list_kref, ttm_bo_release_list);
  		}
-
-		kref_put(&bo->list_kref, ttm_bo_release_list);
  		spin_lock(&glob->lru_lock);
  	}
  	list_splice_tail(&removed, &bdev->ddestroy);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): MN2PR12MB297593776F81FE032B2145218FCF0-rweVpJHSKToFlvJWC7EAqwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#6 lore raw

Hi guys,

Quoted 1 line

Do you have any suggestion about this? For per vm bo, it seems always delay to free the ttm bo.

Yeah, and that is correct behavior.

Since we don't know who is using a per-vm BO we need to wait for all command submissions in flight when it is freed.

For this we copy the current state of the shared reservation object into the private one in ttm_bo_individualize_resv.

Regards,
Christian.

Am 15.07.19 um 08:49 schrieb Deng, Emily:

Quoted 116 lines

Hi David,
You are right, it will copy per-vm resv.
But currently, it still has the delay free issue which non per vm bo doesn't has. Maybe it already has new fences append to this resv object before copy.

Hi Christian,
Do you have any suggestion about this? For per vm bo, it seems always delay to free the ttm bo.

Best wishes
Emily Deng

Quoted 107 lines

-----Original Message-----
From: Zhou, David(ChunMing) <[email protected]>
Sent: Wednesday, July 10, 2019 9:28 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

It doesn't make sense that freeing BO still uses per-vm resv.

I remember when BO is in release list, its resv will be from per-vm resv copy. Could you check it?

-David

Quoted 7 lines · Emily Deng

For vulkan cts allocation test cases, they will create a series of bos, and then free them. As it has lots of alloction test cases with the same vm, as per vm bo feature enable, all of those bos' resv are the same. But the bo free is quite slow, as they use the same resv object, for every time, free a bo, it will check the resv whether signal, if it signal, then will free it. But as the test cases will continue to create bo, and the resv fence is increasing. So the free is more

slower than creating. It will cause memory exhausting.

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 14 lines

Method:
When the resv signal, release all the bos which are use the same resv object.

---
   drivers/gpu/drm/ttm/ttm_bo.c | 29 ++++++++++++++++++++++++-----
   1 file changed, 24 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/ttm/ttm_bo.c index f9a3d4c..57ec59b 100644

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -543,6 +543,7 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
   {
   	struct ttm_bo_global *glob = bo->bdev->glob;
   	struct reservation_object *resv;
+	struct ttm_buffer_object *resv_bo, *resv_bo_next;
   	int ret;
 
   	if (unlikely(list_empty(&bo->ddestroy)))
@@ -566,10 +567,14 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

Quoted 6 lines
drivers/gpu/drm/ttm/ttm_bo.c +2 -1
   							   interruptible,
   							   30 * HZ);
 
-		if (lret < 0)
+		if (lret < 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +4 -1
   			return lret;
-		else if (lret == 0)
+		}
+		else if (lret == 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
   			return -EBUSY;
+		}
 
   		spin_lock(&glob->lru_lock);
   		if (unlock_resv && !kcl_reservation_object_trylock(bo->resv))

{ @@

Quoted 1 line

-582,6 +587,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object

*bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines
   			 * here.
   			 */
   			spin_unlock(&glob->lru_lock);
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
+			kref_put(&bo->list_kref, ttm_bo_release_list);
   			return 0;
   		}
   		ret = 0;
@@ -591,15 +597,29 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct

Quoted 32 lines
drivers/gpu/drm/ttm/ttm_bo.c +15 -1
   		if (unlock_resv)
   			kcl_reservation_object_unlock(bo->resv);
   		spin_unlock(&glob->lru_lock);
+		kref_put(&bo->list_kref, ttm_bo_release_list);
   		return ret;
   	}
 
   	ttm_bo_del_from_lru(bo);
   	list_del_init(&bo->ddestroy);
   	kref_put(&bo->list_kref, ttm_bo_ref_bug);
-
   	spin_unlock(&glob->lru_lock);
   	ttm_bo_cleanup_memtype_use(bo);
+	kref_put(&bo->list_kref, ttm_bo_release_list);
+
+	spin_lock(&glob->lru_lock);
+	list_for_each_entry_safe(resv_bo, resv_bo_next, &bo->bdev-
 ddestroy, ddestroy) {
+		if (resv_bo->resv == bo->resv) {
+			ttm_bo_del_from_lru(resv_bo);
+			list_del_init(&resv_bo->ddestroy);
+			spin_unlock(&glob->lru_lock);
+			ttm_bo_cleanup_memtype_use(resv_bo);
+			kref_put(&resv_bo->list_kref, ttm_bo_release_list);
+			spin_lock(&glob->lru_lock);
+		}
+	}
+	spin_unlock(&glob->lru_lock);
 
   	if (unlock_resv)
   		kcl_reservation_object_unlock(bo->resv);
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -639,9 +659,8 @@ static bool ttm_bo_delayed_delete(struct

ttm_bo_device *bdev, bool remove_all)

Quoted 10 lines
Quoted 10 lines

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all) · line 666

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -2
   			ttm_bo_cleanup_refs(bo, false, !remove_all, true);
   		} else {
   			spin_unlock(&glob->lru_lock);
+			kref_put(&bo->list_kref, ttm_bo_release_list);
   		}
-
-		kref_put(&bo->list_kref, ttm_bo_release_list);
   		spin_lock(&glob->lru_lock);
   	}
   	list_splice_tail(&removed, &bdev->ddestroy);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 550628f4-eb76-23aa-bc33-e9841e6d017b-5C7GfCeVMHo@public.gmane.org

#8 lore raw

Hi Christian,
As has this behavior, when test vulkan cts allocation test, it will exhausting the memory, and cause out of memory. Do you think we don't need to fix it?

Best wishes
Emily Deng

Quoted 144 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, July 15, 2019 5:31 PM
To: Deng, Emily <[email protected]>; Zhou, David(ChunMing) <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

Hi guys,

Quoted 1 line

Do you have any suggestion about this? For per vm bo, it seems always

delay to free the ttm bo.
Yeah, and that is correct behavior.

Since we don't know who is using a per-vm BO we need to wait for all command submissions in flight when it is freed.

For this we copy the current state of the shared reservation object into the private one in ttm_bo_individualize_resv.

Regards,
Christian.

Am 15.07.19 um 08:49 schrieb Deng, Emily:

Quoted 3 lines

Hi David,
You are right, it will copy per-vm resv.
But currently, it still has the delay free issue which non per vm bo doesn't

has. Maybe it already has new fences append to this resv object before copy.

Quoted 3 lines

Hi Christian,
Do you have any suggestion about this? For per vm bo, it seems always

delay to free the ttm bo.

Quoted 112 lines

Best wishes
Emily Deng

Quoted 109 lines

-----Original Message-----
From: Zhou, David(ChunMing) <[email protected]>
Sent: Wednesday, July 10, 2019 9:28 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

It doesn't make sense that freeing BO still uses per-vm resv.

I remember when BO is in release list, its resv will be from per-vm resv copy. Could you check it?

-David

Quoted 8 lines · Emily Deng

For vulkan cts allocation test cases, they will create a series of bos, and then free them. As it has lots of alloction test cases with the same vm, as per vm bo feature enable, all of those bos' resv are the same. But the bo free is quite slow, as they use the same resv object, for every time, free a bo, it will check the resv whether signal, if it signal, then will free it. But as the test cases will continue to create bo, and the resv fence is increasing. So the free is more

slower than creating. It will cause memory exhausting.

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 14 lines

Method:
When the resv signal, release all the bos which are use the same resv object.

---
   drivers/gpu/drm/ttm/ttm_bo.c | 29 ++++++++++++++++++++++++-----
   1 file changed, 24 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/ttm/ttm_bo.c index f9a3d4c..57ec59b 100644

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -543,6 +543,7 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
   {
   	struct ttm_bo_global *glob = bo->bdev->glob;
   	struct reservation_object *resv;
+	struct ttm_buffer_object *resv_bo, *resv_bo_next;
   	int ret;
 
   	if (unlikely(list_empty(&bo->ddestroy)))
@@ -566,10 +567,14 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

Quoted 6 lines
drivers/gpu/drm/ttm/ttm_bo.c +2 -1
   							   interruptible,
   							   30 * HZ);
 
-		if (lret < 0)
+		if (lret < 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct · line 580

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +4 -1
   			return lret;
-		else if (lret == 0)
+		}
+		else if (lret == 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
   			return -EBUSY;
+		}
 
   		spin_lock(&glob->lru_lock);
   		if (unlock_resv && !kcl_reservation_object_trylock(bo->resv))

{ @@

Quoted 2 lines

-582,6 +587,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object

*bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines
   			 * here.
   			 */
   			spin_unlock(&glob->lru_lock);
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
+			kref_put(&bo->list_kref, ttm_bo_release_list);
   			return 0;
   		}
   		ret = 0;
@@ -591,15 +597,29 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct

Quoted 32 lines
drivers/gpu/drm/ttm/ttm_bo.c +15 -1
   		if (unlock_resv)
   			kcl_reservation_object_unlock(bo->resv);
   		spin_unlock(&glob->lru_lock);
+		kref_put(&bo->list_kref, ttm_bo_release_list);
   		return ret;
   	}
 
   	ttm_bo_del_from_lru(bo);
   	list_del_init(&bo->ddestroy);
   	kref_put(&bo->list_kref, ttm_bo_ref_bug);
-
   	spin_unlock(&glob->lru_lock);
   	ttm_bo_cleanup_memtype_use(bo);
+	kref_put(&bo->list_kref, ttm_bo_release_list);
+
+	spin_lock(&glob->lru_lock);
+	list_for_each_entry_safe(resv_bo, resv_bo_next, &bo->bdev-
 ddestroy, ddestroy) {
+		if (resv_bo->resv == bo->resv) {
+			ttm_bo_del_from_lru(resv_bo);
+			list_del_init(&resv_bo->ddestroy);
+			spin_unlock(&glob->lru_lock);
+			ttm_bo_cleanup_memtype_use(resv_bo);
+			kref_put(&resv_bo->list_kref, ttm_bo_release_list);
+			spin_lock(&glob->lru_lock);
+		}
+	}
+	spin_unlock(&glob->lru_lock);
 
   	if (unlock_resv)
   		kcl_reservation_object_unlock(bo->resv);
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -639,9 +659,8 @@ static bool ttm_bo_delayed_delete(struct

ttm_bo_device *bdev, bool remove_all)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct · line 666

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -2
   			ttm_bo_cleanup_refs(bo, false, !remove_all, true);
   		} else {
   			spin_unlock(&glob->lru_lock);
+			kref_put(&bo->list_kref, ttm_bo_release_list);
   		}
-
-		kref_put(&bo->list_kref, ttm_bo_release_list);
   		spin_lock(&glob->lru_lock);
   	}
   	list_splice_tail(&removed, &bdev->ddestroy);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): MN2PR12MB2975EA6482B987399797B0328FCF0-rweVpJHSKToFlvJWC7EAqwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#10 lore raw
Quoted 1 line

Do you think we don't need to fix it?

No, when the application is exhausting memory then we can't expect anything else here.

See memory freeing is always delayed until it isn't used any more or when the process is killed after access is prevented (by clearing page tables for example).

What we could do is maybe look into why we don't block until the memory is freed during command submission, but apart from that this sounds like perfectly expected behavior.

Regards,
Christian.

Am 15.07.19 um 11:34 schrieb Deng, Emily:

Quoted 147 lines

Hi Christian,
As has this behavior, when test vulkan cts allocation test, it will exhausting the memory, and cause out of memory. Do you think we don't need to fix it?

Best wishes
Emily Deng

Quoted 142 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, July 15, 2019 5:31 PM
To: Deng, Emily <[email protected]>; Zhou, David(ChunMing) <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

Hi guys,

Quoted 1 line

Do you have any suggestion about this? For per vm bo, it seems always

delay to free the ttm bo.
Yeah, and that is correct behavior.

Since we don't know who is using a per-vm BO we need to wait for all command submissions in flight when it is freed.

For this we copy the current state of the shared reservation object into the private one in ttm_bo_individualize_resv.

Regards,
Christian.

Am 15.07.19 um 08:49 schrieb Deng, Emily:

Quoted 3 lines

Hi David,
You are right, it will copy per-vm resv.
But currently, it still has the delay free issue which non per vm bo doesn't

has. Maybe it already has new fences append to this resv object before copy.

Quoted 2 lines

Hi Christian,
Do you have any suggestion about this? For per vm bo, it seems always

delay to free the ttm bo.

Quoted 111 lines

Best wishes
Emily Deng

Quoted 109 lines

-----Original Message-----
From: Zhou, David(ChunMing) <[email protected]>
Sent: Wednesday, July 10, 2019 9:28 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

It doesn't make sense that freeing BO still uses per-vm resv.

I remember when BO is in release list, its resv will be from per-vm resv copy. Could you check it?

-David

Quoted 8 lines · Emily Deng

For vulkan cts allocation test cases, they will create a series of bos, and then free them. As it has lots of alloction test cases with the same vm, as per vm bo feature enable, all of those bos' resv are the same. But the bo free is quite slow, as they use the same resv object, for every time, free a bo, it will check the resv whether signal, if it signal, then will free it. But as the test cases will continue to create bo, and the resv fence is increasing. So the free is more

slower than creating. It will cause memory exhausting.

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 14 lines

Method:
When the resv signal, release all the bos which are use the same resv object.

---
    drivers/gpu/drm/ttm/ttm_bo.c | 29 ++++++++++++++++++++++++-----
    1 file changed, 24 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/ttm/ttm_bo.c index f9a3d4c..57ec59b 100644

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -543,6 +543,7 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
    {
    	struct ttm_bo_global *glob = bo->bdev->glob;
    	struct reservation_object *resv;
+	struct ttm_buffer_object *resv_bo, *resv_bo_next;
    	int ret;
 
    	if (unlikely(list_empty(&bo->ddestroy)))
@@ -566,10 +567,14 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

Quoted 6 lines
drivers/gpu/drm/ttm/ttm_bo.c +2 -1
    							   interruptible,
    							   30 * HZ);
 
-		if (lret < 0)
+		if (lret < 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct · line 580

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +4 -1
    			return lret;
-		else if (lret == 0)
+		}
+		else if (lret == 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
    			return -EBUSY;
+		}
 
    		spin_lock(&glob->lru_lock);
    		if (unlock_resv && !kcl_reservation_object_trylock(bo->resv))

{ @@

Quoted 2 lines

-582,6 +587,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object

*bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines
    			 * here.
    			 */
    			spin_unlock(&glob->lru_lock);
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
+			kref_put(&bo->list_kref, ttm_bo_release_list);
    			return 0;
    		}
    		ret = 0;
@@ -591,15 +597,29 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct

Quoted 32 lines
drivers/gpu/drm/ttm/ttm_bo.c +15 -1
    		if (unlock_resv)
    			kcl_reservation_object_unlock(bo->resv);
    		spin_unlock(&glob->lru_lock);
+		kref_put(&bo->list_kref, ttm_bo_release_list);
    		return ret;
    	}
 
    	ttm_bo_del_from_lru(bo);
    	list_del_init(&bo->ddestroy);
    	kref_put(&bo->list_kref, ttm_bo_ref_bug);
-
    	spin_unlock(&glob->lru_lock);
    	ttm_bo_cleanup_memtype_use(bo);
+	kref_put(&bo->list_kref, ttm_bo_release_list);
+
+	spin_lock(&glob->lru_lock);
+	list_for_each_entry_safe(resv_bo, resv_bo_next, &bo->bdev-
 ddestroy, ddestroy) {
+		if (resv_bo->resv == bo->resv) {
+			ttm_bo_del_from_lru(resv_bo);
+			list_del_init(&resv_bo->ddestroy);
+			spin_unlock(&glob->lru_lock);
+			ttm_bo_cleanup_memtype_use(resv_bo);
+			kref_put(&resv_bo->list_kref, ttm_bo_release_list);
+			spin_lock(&glob->lru_lock);
+		}
+	}
+	spin_unlock(&glob->lru_lock);
 
    	if (unlock_resv)
    		kcl_reservation_object_unlock(bo->resv);
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -639,9 +659,8 @@ static bool ttm_bo_delayed_delete(struct

ttm_bo_device *bdev, bool remove_all)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct · line 666

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -2
    			ttm_bo_cleanup_refs(bo, false, !remove_all, true);
    		} else {
    			spin_unlock(&glob->lru_lock);
+			kref_put(&bo->list_kref, ttm_bo_release_list);
    		}
-
-		kref_put(&bo->list_kref, ttm_bo_release_list);
    		spin_lock(&glob->lru_lock);
    	}
    	list_splice_tail(&removed, &bdev->ddestroy);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): a9deb404-6041-299e-60fc-d2356b729664-5C7GfCeVMHo@public.gmane.org

#12 lore raw

Hi Christian,
Do you think we could free all those bos those are in current destroy list when the current resv is signal in ttm_bo_cleanup_refs?

Best wishes
Emily Deng

Quoted 183 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, July 15, 2019 5:41 PM
To: Deng, Emily <[email protected]>; Zhou, David(ChunMing) <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

Quoted 1 line

Do you think we don't need to fix it?

No, when the application is exhausting memory then we can't expect anything else here.

See memory freeing is always delayed until it isn't used any more or when the process is killed after access is prevented (by clearing page tables for example).

What we could do is maybe look into why we don't block until the memory is freed during command submission, but apart from that this sounds like perfectly expected behavior.

Regards,
Christian.

Am 15.07.19 um 11:34 schrieb Deng, Emily:

Quoted 2 lines

Hi Christian,
As has this behavior, when test vulkan cts allocation test, it will

exhausting the memory, and cause out of memory. Do you think we don't need to fix it?

Quoted 33 lines

Best wishes
Emily Deng

Quoted 30 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, July 15, 2019 5:31 PM
To: Deng, Emily <[email protected]>; Zhou, David(ChunMing) <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

Hi guys,

Quoted 2 lines

Do you have any suggestion about this? For per vm bo, it seems always

delay to free the ttm bo.
Yeah, and that is correct behavior.

Since we don't know who is using a per-vm BO we need to wait for all command submissions in flight when it is freed.

For this we copy the current state of the shared reservation object into the private one in ttm_bo_individualize_resv.

Regards,
Christian.

Am 15.07.19 um 08:49 schrieb Deng, Emily:

Quoted 4 lines

Hi David,
You are right, it will copy per-vm resv.
But currently, it still has the delay free issue which non
per vm bo doesn't

has. Maybe it already has new fences append to this resv object before

copy.

Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hi Christian,
Do you have any suggestion about this? For per vm bo, it seems
always

delay to free the ttm bo.

Quoted 6 lines

Best wishes
Emily Deng

Quoted 4 lines

-----Original Message-----
From: Zhou, David(ChunMing) <[email protected]>
Sent: Wednesday, July 10, 2019 9:28 PM
To: Deng, Emily <[email protected]>; amd-

[email protected]

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

It doesn't make sense that freeing BO still uses per-vm resv.

I remember when BO is in release list, its resv will be from per-vm resv

copy.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Could you check it?

-David

Quoted 8 lines · Emily Deng

For vulkan cts allocation test cases, they will create a series of bos, and then free them. As it has lots of alloction test cases with the same vm, as per vm bo feature enable, all of those bos' resv are the same. But the bo free is quite slow, as they use the same resv object, for every time, free a bo, it will check the resv whether signal, if it signal, then will free it. But as the test cases will continue to create bo, and the resv fence is increasing. So the free is more

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

slower than creating. It will cause memory exhausting.

Quoted 7 lines

Method:
When the resv signal, release all the bos which are use the same resv object.

---
    drivers/gpu/drm/ttm/ttm_bo.c | 29 ++++++++++++++++++++++++----

-

Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 7 lines
    1 file changed, 24 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/ttm/ttm_bo.c index f9a3d4c..57ec59b 100644

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -543,6 +543,7 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
    {
    	struct ttm_bo_global *glob = bo->bdev->glob;
    	struct reservation_object *resv;
+	struct ttm_buffer_object *resv_bo, *resv_bo_next;
    	int ret;
 
    	if (unlikely(list_empty(&bo->ddestroy)))
@@ -566,10 +567,14 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

Quoted 16 lines
drivers/gpu/drm/ttm/ttm_bo.c +6 -2
    							   interruptible,
    							   30 * HZ);
 
-		if (lret < 0)
+		if (lret < 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
    			return lret;
-		else if (lret == 0)
+		}
+		else if (lret == 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
    			return -EBUSY;
+		}
 
    		spin_lock(&glob->lru_lock);
    		if (unlock_resv &&
Quoted 1 line

!kcl_reservation_object_trylock(bo->resv))

{ @@

Quoted 2 lines

-582,6 +587,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object

*bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines
    			 * here.
    			 */
    			spin_unlock(&glob->lru_lock);
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
+			kref_put(&bo->list_kref, ttm_bo_release_list);
    			return 0;
    		}
    		ret = 0;
@@ -591,15 +597,29 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

Quoted 16 lines
drivers/gpu/drm/ttm/ttm_bo.c +4 -1
    		if (unlock_resv)
    			kcl_reservation_object_unlock(bo->resv);
    		spin_unlock(&glob->lru_lock);
+		kref_put(&bo->list_kref, ttm_bo_release_list);
    		return ret;
    	}
 
    	ttm_bo_del_from_lru(bo);
    	list_del_init(&bo->ddestroy);
    	kref_put(&bo->list_kref, ttm_bo_ref_bug);
-
    	spin_unlock(&glob->lru_lock);
    	ttm_bo_cleanup_memtype_use(bo);
+	kref_put(&bo->list_kref, ttm_bo_release_list);
+
+	spin_lock(&glob->lru_lock);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct · line 619

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +7 -0
+	list_for_each_entry_safe(resv_bo, resv_bo_next, &bo->bdev-
 ddestroy, ddestroy) {
+		if (resv_bo->resv == bo->resv) {
+			ttm_bo_del_from_lru(resv_bo);
+			list_del_init(&resv_bo->ddestroy);
+			spin_unlock(&glob->lru_lock);
+			ttm_bo_cleanup_memtype_use(resv_bo);
+			kref_put(&resv_bo->list_kref,

ttm_bo_release_list);

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +4 -0
+			spin_lock(&glob->lru_lock);
+		}
+	}
+	spin_unlock(&glob->lru_lock);
 
    	if (unlock_resv)
    		kcl_reservation_object_unlock(bo->resv);
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -639,9 +659,8 @@ static bool ttm_bo_delayed_delete(struct

ttm_bo_device *bdev, bool remove_all)

Quoted 1 line
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
    			ttm_bo_cleanup_refs(bo, false, !remove_all,

true);

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct · line 666

Quoted 9 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -2
    		} else {
    			spin_unlock(&glob->lru_lock);
+			kref_put(&bo->list_kref, ttm_bo_release_list);
    		}
-
-		kref_put(&bo->list_kref, ttm_bo_release_list);
    		spin_lock(&glob->lru_lock);
    	}
    	list_splice_tail(&removed, &bdev->ddestroy);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): MN2PR12MB29758D1F45E8A8FEA883C4ED8FCF0-rweVpJHSKToFlvJWC7EAqwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#14 lore raw

Hi Emily,

no, we can only cleanup the current one because we don't have a reference to the other ones.

At least that's how I understand you question,
Christian.

Am 15.07.19 um 12:47 schrieb Deng, Emily:

Quoted 188 lines

Hi Christian,
Do you think we could free all those bos those are in current destroy list when the current resv is signal in ttm_bo_cleanup_refs?

Best wishes
Emily Deng

Quoted 182 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, July 15, 2019 5:41 PM
To: Deng, Emily <[email protected]>; Zhou, David(ChunMing) <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

Quoted 1 line

Do you think we don't need to fix it?

No, when the application is exhausting memory then we can't expect anything else here.

See memory freeing is always delayed until it isn't used any more or when the process is killed after access is prevented (by clearing page tables for example).

What we could do is maybe look into why we don't block until the memory is freed during command submission, but apart from that this sounds like perfectly expected behavior.

Regards,
Christian.

Am 15.07.19 um 11:34 schrieb Deng, Emily:

Quoted 2 lines

Hi Christian,
As has this behavior, when test vulkan cts allocation test, it will

exhausting the memory, and cause out of memory. Do you think we don't need to fix it?

Quoted 32 lines

Best wishes
Emily Deng

Quoted 30 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, July 15, 2019 5:31 PM
To: Deng, Emily <[email protected]>; Zhou, David(ChunMing) <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

Hi guys,

Quoted 2 lines

Do you have any suggestion about this? For per vm bo, it seems always

delay to free the ttm bo.
Yeah, and that is correct behavior.

Since we don't know who is using a per-vm BO we need to wait for all command submissions in flight when it is freed.

For this we copy the current state of the shared reservation object into the private one in ttm_bo_individualize_resv.

Regards,
Christian.

Am 15.07.19 um 08:49 schrieb Deng, Emily:

Quoted 4 lines

Hi David,
You are right, it will copy per-vm resv.
But currently, it still has the delay free issue which non
per vm bo doesn't

has. Maybe it already has new fences append to this resv object before

copy.

Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

Hi Christian,
Do you have any suggestion about this? For per vm bo, it seems
always

delay to free the ttm bo.

Quoted 6 lines

Best wishes
Emily Deng

Quoted 4 lines

-----Original Message-----
From: Zhou, David(ChunMing) <[email protected]>
Sent: Wednesday, July 10, 2019 9:28 PM
To: Deng, Emily <[email protected]>; amd-

[email protected]

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Subject: Re: [PATCH] drm/ttm: Fix the memory delay free issue

It doesn't make sense that freeing BO still uses per-vm resv.

I remember when BO is in release list, its resv will be from per-vm resv

copy.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Could you check it?

-David

Quoted 8 lines · Emily Deng

For vulkan cts allocation test cases, they will create a series of bos, and then free them. As it has lots of alloction test cases with the same vm, as per vm bo feature enable, all of those bos' resv are the same. But the bo free is quite slow, as they use the same resv object, for every time, free a bo, it will check the resv whether signal, if it signal, then will free it. But as the test cases will continue to create bo, and the resv fence is increasing. So the free is more

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

slower than creating. It will cause memory exhausting.

Quoted 7 lines

Method:
When the resv signal, release all the bos which are use the same resv object.

---
     drivers/gpu/drm/ttm/ttm_bo.c | 29 ++++++++++++++++++++++++----

-

Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 7 lines
     1 file changed, 24 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/ttm/ttm_bo.c index f9a3d4c..57ec59b 100644

drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -543,6 +543,7 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
     {
     	struct ttm_bo_global *glob = bo->bdev->glob;
     	struct reservation_object *resv;
+	struct ttm_buffer_object *resv_bo, *resv_bo_next;
     	int ret;
 
     	if (unlikely(list_empty(&bo->ddestroy)))
@@ -566,10 +567,14 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

Quoted 16 lines
drivers/gpu/drm/ttm/ttm_bo.c +6 -2
     							   interruptible,
     							   30 * HZ);
 
-		if (lret < 0)
+		if (lret < 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
     			return lret;
-		else if (lret == 0)
+		}
+		else if (lret == 0) {
+			kref_put(&bo->list_kref, ttm_bo_release_list);
     			return -EBUSY;
+		}
 
     		spin_lock(&glob->lru_lock);
     		if (unlock_resv &&
Quoted 1 line

!kcl_reservation_object_trylock(bo->resv))

{ @@

Quoted 2 lines

-582,6 +587,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object

*bo,

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct

Quoted 8 lines
     			 * here.
     			 */
     			spin_unlock(&glob->lru_lock);
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
+			kref_put(&bo->list_kref, ttm_bo_release_list);
     			return 0;
     		}
     		ret = 0;
@@ -591,15 +597,29 @@ static int ttm_bo_cleanup_refs(struct

ttm_buffer_object *bo,

Quoted 16 lines
drivers/gpu/drm/ttm/ttm_bo.c +4 -1
     		if (unlock_resv)
     			kcl_reservation_object_unlock(bo->resv);
     		spin_unlock(&glob->lru_lock);
+		kref_put(&bo->list_kref, ttm_bo_release_list);
     		return ret;
     	}
 
     	ttm_bo_del_from_lru(bo);
     	list_del_init(&bo->ddestroy);
     	kref_put(&bo->list_kref, ttm_bo_ref_bug);
-
     	spin_unlock(&glob->lru_lock);
     	ttm_bo_cleanup_memtype_use(bo);
+	kref_put(&bo->list_kref, ttm_bo_release_list);
+
+	spin_lock(&glob->lru_lock);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ttm/ttm_bo.c static int ttm_bo_cleanup_refs(struct · line 619

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +7 -0
+	list_for_each_entry_safe(resv_bo, resv_bo_next, &bo->bdev-
 ddestroy, ddestroy) {
+		if (resv_bo->resv == bo->resv) {
+			ttm_bo_del_from_lru(resv_bo);
+			list_del_init(&resv_bo->ddestroy);
+			spin_unlock(&glob->lru_lock);
+			ttm_bo_cleanup_memtype_use(resv_bo);
+			kref_put(&resv_bo->list_kref,

ttm_bo_release_list);

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c +4 -0
+			spin_lock(&glob->lru_lock);
+		}
+	}
+	spin_unlock(&glob->lru_lock);
 
     	if (unlock_resv)
     		kcl_reservation_object_unlock(bo->resv);
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
@@ -639,9 +659,8 @@ static bool ttm_bo_delayed_delete(struct

ttm_bo_device *bdev, bool remove_all)

Quoted 1 line
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
     			ttm_bo_cleanup_refs(bo, false, !remove_all,

true);

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/ttm/ttm_bo.c static bool ttm_bo_delayed_delete(struct · line 666

Quoted 9 lines
drivers/gpu/drm/ttm/ttm_bo.c +1 -2
     		} else {
     			spin_unlock(&glob->lru_lock);
+			kref_put(&bo->list_kref, ttm_bo_release_list);
     		}
-
-		kref_put(&bo->list_kref, ttm_bo_release_list);
     		spin_lock(&glob->lru_lock);
     	}
     	list_splice_tail(&removed, &bdev->ddestroy);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx