dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/ttm: stop always moving BOs on the LRU on page fault
@ 2019-01-11 13:15 Christian König
  2019-01-11 14:15 ` Michel Dänzer
       [not found] ` <20190111131525.1269-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Christian König @ 2019-01-11 13:15 UTC (permalink / raw)
  To: dri-devel; +Cc: amd-gfx

Move the BO on the LRU only when it is actually moved by a DMA
operation.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/ttm/ttm_bo_vm.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index a1d977fbade5..e86a29a1e51f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -71,7 +71,7 @@ static vm_fault_t ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,
 		ttm_bo_get(bo);
 		up_read(&vmf->vma->vm_mm->mmap_sem);
 		(void) dma_fence_wait(bo->moving, true);
-		ttm_bo_unreserve(bo);
+		reservation_object_unlock(bo->resv);
 		ttm_bo_put(bo);
 		goto out_unlock;
 	}
@@ -131,11 +131,7 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
 	 * for reserve, and if it fails, retry the fault after waiting
 	 * for the buffer to become unreserved.
 	 */
-	err = ttm_bo_reserve(bo, true, true, NULL);
-	if (unlikely(err != 0)) {
-		if (err != -EBUSY)
-			return VM_FAULT_NOPAGE;
-
+	if (unlikely(!reservation_object_trylock(bo->resv))) {
 		if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
 			if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
 				ttm_bo_get(bo);
@@ -165,6 +161,8 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
 	}
 
 	if (bdev->driver->fault_reserve_notify) {
+		struct dma_fence *moving = dma_fence_get(bo->moving);
+
 		err = bdev->driver->fault_reserve_notify(bo);
 		switch (err) {
 		case 0:
@@ -177,6 +175,13 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
 			ret = VM_FAULT_SIGBUS;
 			goto out_unlock;
 		}
+
+		if (bo->moving != moving) {
+			spin_lock(&bdev->glob->lru_lock);
+			ttm_bo_move_to_lru_tail(bo, NULL);
+			spin_unlock(&bdev->glob->lru_lock);
+		}
+		dma_fence_put(moving);
 	}
 
 	/*
@@ -291,7 +296,7 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
 out_io_unlock:
 	ttm_mem_io_unlock(man);
 out_unlock:
-	ttm_bo_unreserve(bo);
+	reservation_object_unlock(bo->resv);
 	return ret;
 }
 
-- 
2.14.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm/ttm: stop always moving BOs on the LRU on page fault
  2019-01-11 13:15 [PATCH] drm/ttm: stop always moving BOs on the LRU on page fault Christian König
@ 2019-01-11 14:15 ` Michel Dänzer
       [not found] ` <20190111131525.1269-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Michel Dänzer @ 2019-01-11 14:15 UTC (permalink / raw)
  To: Christian König; +Cc: amd-gfx, dri-devel

On 2019-01-11 2:15 p.m., Christian König wrote:
> Move the BO on the LRU only when it is actually moved by a DMA
> operation.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm/ttm: stop always moving BOs on the LRU on page fault
       [not found] ` <20190111131525.1269-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2019-01-11 14:17   ` Michel Dänzer
       [not found]     ` <ed9615c4-99be-c690-6ea0-bbe3e107bab3-otUistvHUpPR7s880joybQ@public.gmane.org>
  2019-01-14  7:06   ` zhoucm1
  1 sibling, 1 reply; 6+ messages in thread
From: Michel Dänzer @ 2019-01-11 14:17 UTC (permalink / raw)
  To: Christian König
  Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 2019-01-11 2:15 p.m., Christian König wrote:
> Move the BO on the LRU only when it is actually moved by a DMA
> operation.
> 
> [...]
> 
> @@ -177,6 +175,13 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
>  			ret = VM_FAULT_SIGBUS;
>  			goto out_unlock;
>  		}
> +
> +		if (bo->moving != moving) {

Hmm, could a driver just update the existing fence instead of attaching
a new one?


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm/ttm: stop always moving BOs on the LRU on page fault
       [not found]     ` <ed9615c4-99be-c690-6ea0-bbe3e107bab3-otUistvHUpPR7s880joybQ@public.gmane.org>
@ 2019-01-11 19:12       ` Christian König
       [not found]         ` <810303e7-d1bd-1e04-4e73-33d8202b2a05-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Christian König @ 2019-01-11 19:12 UTC (permalink / raw)
  To: Michel Dänzer
  Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 11.01.19 um 15:17 schrieb Michel Dänzer:
> On 2019-01-11 2:15 p.m., Christian König wrote:
>> Move the BO on the LRU only when it is actually moved by a DMA
>> operation.
>>
>> [...]
>>
>> @@ -177,6 +175,13 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
>>   			ret = VM_FAULT_SIGBUS;
>>   			goto out_unlock;
>>   		}
>> +
>> +		if (bo->moving != moving) {
> Hmm, could a driver just update the existing fence instead of attaching
> a new one?

Mhm, not as far as I know. That would violate similar checks elsewhere.

Christian.
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm/ttm: stop always moving BOs on the LRU on page fault
       [not found] ` <20190111131525.1269-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2019-01-11 14:17   ` Michel Dänzer
@ 2019-01-14  7:06   ` zhoucm1
  1 sibling, 0 replies; 6+ messages in thread
From: zhoucm1 @ 2019-01-14  7:06 UTC (permalink / raw)
  To: Christian König, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: David1.Zhou-5C7GfCeVMHo, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



On 2019年01月11日 21:15, Christian König wrote:
> Move the BO on the LRU only when it is actually moved by a DMA
> operation.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
Tested-And-Reviewed-by: Chunming Zhou <david1.zhou@amd.com>

I just sent lru_notify  v2 patches, please review them. With yours and 
mine, the OOM issue is fixed without negative effect.

-David
> ---
>   drivers/gpu/drm/ttm/ttm_bo_vm.c | 19 ++++++++++++-------
>   1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> index a1d977fbade5..e86a29a1e51f 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> @@ -71,7 +71,7 @@ static vm_fault_t ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,
>   		ttm_bo_get(bo);
>   		up_read(&vmf->vma->vm_mm->mmap_sem);
>   		(void) dma_fence_wait(bo->moving, true);
> -		ttm_bo_unreserve(bo);
> +		reservation_object_unlock(bo->resv);
>   		ttm_bo_put(bo);
>   		goto out_unlock;
>   	}
> @@ -131,11 +131,7 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
>   	 * for reserve, and if it fails, retry the fault after waiting
>   	 * for the buffer to become unreserved.
>   	 */
> -	err = ttm_bo_reserve(bo, true, true, NULL);
> -	if (unlikely(err != 0)) {
> -		if (err != -EBUSY)
> -			return VM_FAULT_NOPAGE;
> -
> +	if (unlikely(!reservation_object_trylock(bo->resv))) {
>   		if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
>   			if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
>   				ttm_bo_get(bo);
> @@ -165,6 +161,8 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
>   	}
>   
>   	if (bdev->driver->fault_reserve_notify) {
> +		struct dma_fence *moving = dma_fence_get(bo->moving);
> +
>   		err = bdev->driver->fault_reserve_notify(bo);
>   		switch (err) {
>   		case 0:
> @@ -177,6 +175,13 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
>   			ret = VM_FAULT_SIGBUS;
>   			goto out_unlock;
>   		}
> +
> +		if (bo->moving != moving) {
> +			spin_lock(&bdev->glob->lru_lock);
> +			ttm_bo_move_to_lru_tail(bo, NULL);
> +			spin_unlock(&bdev->glob->lru_lock);
> +		}
> +		dma_fence_put(moving);
>   	}
>   
>   	/*
> @@ -291,7 +296,7 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
>   out_io_unlock:
>   	ttm_mem_io_unlock(man);
>   out_unlock:
> -	ttm_bo_unreserve(bo);
> +	reservation_object_unlock(bo->resv);
>   	return ret;
>   }
>   

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm/ttm: stop always moving BOs on the LRU on page fault
       [not found]         ` <810303e7-d1bd-1e04-4e73-33d8202b2a05-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2019-01-14 16:27           ` Michel Dänzer
  0 siblings, 0 replies; 6+ messages in thread
From: Michel Dänzer @ 2019-01-14 16:27 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo
  Cc: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 2019-01-11 8:12 p.m., Christian König wrote:
> Am 11.01.19 um 15:17 schrieb Michel Dänzer:
>> On 2019-01-11 2:15 p.m., Christian König wrote:
>>> Move the BO on the LRU only when it is actually moved by a DMA
>>> operation.
>>>
>>> [...]
>>>
>>> @@ -177,6 +175,13 @@ static vm_fault_t ttm_bo_vm_fault(struct
>>> vm_fault *vmf)
>>>               ret = VM_FAULT_SIGBUS;
>>>               goto out_unlock;
>>>           }
>>> +
>>> +        if (bo->moving != moving) {
>> Hmm, could a driver just update the existing fence instead of attaching
>> a new one?
> 
> Mhm, not as far as I know. That would violate similar checks elsewhere.

Makes sense, my R-b stands.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-01-14 16:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-11 13:15 [PATCH] drm/ttm: stop always moving BOs on the LRU on page fault Christian König
2019-01-11 14:15 ` Michel Dänzer
     [not found] ` <20190111131525.1269-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2019-01-11 14:17   ` Michel Dänzer
     [not found]     ` <ed9615c4-99be-c690-6ea0-bbe3e107bab3-otUistvHUpPR7s880joybQ@public.gmane.org>
2019-01-11 19:12       ` Christian König
     [not found]         ` <810303e7-d1bd-1e04-4e73-33d8202b2a05-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-01-14 16:27           ` Michel Dänzer
2019-01-14  7:06   ` zhoucm1

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox