diff mbox

[1/2] drm/ttm: Don't add swapped BOs to swap-LRU list

Message ID 1516294577-29078-1-git-send-email-Felix.Kuehling@amd.com (mailing list archive)
State New, archived
Headers show

Commit Message

Felix Kuehling Jan. 18, 2018, 4:56 p.m. UTC
A BO that's already swapped would be added back to the swap-LRU list
for example if its validation failed under high memory pressure. This
could later lead to swapping it out again and leaking previous swap
storage.

This commit adds a condition to prevent that from happening.

v2: Check page_flags instead of swap_storage

Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Christian König Jan. 18, 2018, 6:09 p.m. UTC | #1
Am 18.01.2018 um 17:56 schrieb Felix Kuehling:
> A BO that's already swapped would be added back to the swap-LRU list
> for example if its validation failed under high memory pressure. This
> could later lead to swapping it out again and leaking previous swap
> storage.
>
> This commit adds a condition to prevent that from happening.
>
> v2: Check page_flags instead of swap_storage
>
> Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>

Reviewed-by: Christian König <christian.koenig@amd.com> for both.

> ---
>   drivers/gpu/drm/ttm/ttm_bo.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 2eb71ff..62518b6 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -170,7 +170,8 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
>   		list_add_tail(&bo->lru, &man->lru[bo->priority]);
>   		kref_get(&bo->list_kref);
>   
> -		if (bo->ttm && !(bo->ttm->page_flags & TTM_PAGE_FLAG_SG)) {
> +		if (bo->ttm && !(bo->ttm->page_flags &
> +				 (TTM_PAGE_FLAG_SG | TTM_PAGE_FLAG_SWAPPED))) {
>   			list_add_tail(&bo->swap,
>   				      &bo->glob->swap_lru[bo->priority]);
>   			kref_get(&bo->list_kref);
Felix Kuehling Jan. 18, 2018, 9:12 p.m. UTC | #2
On 2018-01-18 01:09 PM, Christian König wrote:
> Am 18.01.2018 um 17:56 schrieb Felix Kuehling:
>> A BO that's already swapped would be added back to the swap-LRU list
>> for example if its validation failed under high memory pressure. This
>> could later lead to swapping it out again and leaking previous swap
>> storage.
>>
>> This commit adds a condition to prevent that from happening.
>>
>> v2: Check page_flags instead of swap_storage
>>
>> Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
>
> Reviewed-by: Christian König <christian.koenig@amd.com> for both.

Thanks. I pushed them to amd-staging-drm-next. I think patch 1 should
also go to -fixes. Alex?

Regards,
  Felix

>
>> ---
>>   drivers/gpu/drm/ttm/ttm_bo.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>> index 2eb71ff..62518b6 100644
>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>> @@ -170,7 +170,8 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
>>           list_add_tail(&bo->lru, &man->lru[bo->priority]);
>>           kref_get(&bo->list_kref);
>>   -        if (bo->ttm && !(bo->ttm->page_flags & TTM_PAGE_FLAG_SG)) {
>> +        if (bo->ttm && !(bo->ttm->page_flags &
>> +                 (TTM_PAGE_FLAG_SG | TTM_PAGE_FLAG_SWAPPED))) {
>>               list_add_tail(&bo->swap,
>>                         &bo->glob->swap_lru[bo->priority]);
>>               kref_get(&bo->list_kref);
>
Alex Deucher Jan. 18, 2018, 9:15 p.m. UTC | #3

diff mbox

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 2eb71ff..62518b6 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -170,7 +170,8 @@  void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
 		list_add_tail(&bo->lru, &man->lru[bo->priority]);
 		kref_get(&bo->list_kref);
 
-		if (bo->ttm && !(bo->ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		if (bo->ttm && !(bo->ttm->page_flags &
+				 (TTM_PAGE_FLAG_SG | TTM_PAGE_FLAG_SWAPPED))) {
 			list_add_tail(&bo->swap,
 				      &bo->glob->swap_lru[bo->priority]);
 			kref_get(&bo->list_kref);