[2/2] mm/migrate_device: further convert migrate_device_finalize() to folios

Message ID 20240214202055.77776-2-sidhartha.kumar@oracle.com
State New
Headers
Series [1/2] mm/migrate_device: further convert migrate_device_unmap() to folios |

Commit Message

Sidhartha Kumar Feb. 14, 2024, 8:20 p.m. UTC
  Use folio api functions from the already defined src and dst folio
variables.

Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
 mm/migrate_device.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
  

Comments

Alistair Popple Feb. 14, 2024, 10:45 p.m. UTC | #1
Sidhartha Kumar <sidhartha.kumar@oracle.com> writes:

> Use folio api functions from the already defined src and dst folio
> variables.
>
> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> ---
>  mm/migrate_device.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index 9152a329b0a68..a48d5cdb28553 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -843,17 +843,17 @@ void migrate_device_finalize(unsigned long *src_pfns,
>  		remove_migration_ptes(src, dst, false);
>  		folio_unlock(src);
>  
> -		if (is_zone_device_page(page))
> -			put_page(page);
> +		if (folio_is_zone_device(src))
> +			folio_put(src);
>  		else
> -			putback_lru_page(page);
> +			folio_putback_lru(src);
>  
>  		if (newpage != page) {
> -			unlock_page(newpage);
> -			if (is_zone_device_page(newpage))
> -				put_page(newpage);

Defining migrate_pfn_to_folio() would also allow the removal of the
newpage and page variables entirely which I think would make this
clearer.

As an aside is there any motivation for making these changes other than
as a general cleanup? I ask only because I have been looking at allowing
device pages with order > 0 so have some of these clean-ups in a local
tree as they're a pre-requisite for that.

 - Alistair

> +			folio_unlock(dst);
> +			if (folio_is_zone_device(dst))
> +				folio_put(dst);
>  			else
> -				putback_lru_page(newpage);
> +				folio_putback_lru(dst);
>  		}
>  	}
>  }
  
Sidhartha Kumar Feb. 14, 2024, 11:10 p.m. UTC | #2
On 2/14/24 2:45 PM, Alistair Popple wrote:
> 
> Sidhartha Kumar <sidhartha.kumar@oracle.com> writes:
> 
>> Use folio api functions from the already defined src and dst folio
>> variables.
>>
>> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
>> ---
>>   mm/migrate_device.c | 14 +++++++-------
>>   1 file changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
>> index 9152a329b0a68..a48d5cdb28553 100644
>> --- a/mm/migrate_device.c
>> +++ b/mm/migrate_device.c
>> @@ -843,17 +843,17 @@ void migrate_device_finalize(unsigned long *src_pfns,
>>   		remove_migration_ptes(src, dst, false);
>>   		folio_unlock(src);
>>   
>> -		if (is_zone_device_page(page))
>> -			put_page(page);
>> +		if (folio_is_zone_device(src))
>> +			folio_put(src);
>>   		else
>> -			putback_lru_page(page);
>> +			folio_putback_lru(src);
>>   
>>   		if (newpage != page) {
>> -			unlock_page(newpage);
>> -			if (is_zone_device_page(newpage))
>> -				put_page(newpage);
> 
> Defining migrate_pfn_to_folio() would also allow the removal of the
> newpage and page variables entirely which I think would make this
> clearer.
> 
> As an aside is there any motivation for making these changes other than
> as a general cleanup? I ask only because I have been looking at allowing
> device pages with order > 0 so have some of these clean-ups in a local
> tree as they're a pre-requisite for that.
> 
>   - Alistair
> 

Hello,

The motivation is just general cleanup. In folio-compat.c I saw that 
putback_lru_page() does not have much users left so I could convert them and 
then just get rid of putback_lru_page(). Should I still continue with a v2 that 
will include defining a migrate_pfn_to_folio() or wait for your clean-ups?

Thanks,
Sid

>> +			folio_unlock(dst);
>> +			if (folio_is_zone_device(dst))
>> +				folio_put(dst);
>>   			else
>> -				putback_lru_page(newpage);
>> +				folio_putback_lru(dst);
>>   		}
>>   	}
>>   }
>
  
Alistair Popple Feb. 15, 2024, 12:58 a.m. UTC | #3
Sidhartha Kumar <sidhartha.kumar@oracle.com> writes:

> On 2/14/24 2:45 PM, Alistair Popple wrote:
>> Sidhartha Kumar <sidhartha.kumar@oracle.com> writes:
>> 
>>> Use folio api functions from the already defined src and dst folio
>>> variables.
>>>
>>> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
>>> ---
>>>   mm/migrate_device.c | 14 +++++++-------
>>>   1 file changed, 7 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
>>> index 9152a329b0a68..a48d5cdb28553 100644
>>> --- a/mm/migrate_device.c
>>> +++ b/mm/migrate_device.c
>>> @@ -843,17 +843,17 @@ void migrate_device_finalize(unsigned long *src_pfns,
>>>   		remove_migration_ptes(src, dst, false);
>>>   		folio_unlock(src);
>>>   -		if (is_zone_device_page(page))
>>> -			put_page(page);
>>> +		if (folio_is_zone_device(src))
>>> +			folio_put(src);
>>>   		else
>>> -			putback_lru_page(page);
>>> +			folio_putback_lru(src);
>>>     		if (newpage != page) {
>>> -			unlock_page(newpage);
>>> -			if (is_zone_device_page(newpage))
>>> -				put_page(newpage);
>> Defining migrate_pfn_to_folio() would also allow the removal of the
>> newpage and page variables entirely which I think would make this
>> clearer.
>> As an aside is there any motivation for making these changes other
>> than
>> as a general cleanup? I ask only because I have been looking at allowing
>> device pages with order > 0 so have some of these clean-ups in a local
>> tree as they're a pre-requisite for that.
>>   - Alistair
>> 
>
> Hello,
>
> The motivation is just general cleanup. In folio-compat.c I saw that
> putback_lru_page() does not have much users left so I could convert
> them and then just get rid of putback_lru_page(). Should I still
> continue with a v2 that will include defining a migrate_pfn_to_folio()
> or wait for your clean-ups?

No, don't wait for mine. Please continue with defining
migrate_pfn_to_folio() for v2, I was just curious in case you had some
larger goal in mind.

Thanks.

 - Alistair

> Thanks,
> Sid
>
>>> +			folio_unlock(dst);
>>> +			if (folio_is_zone_device(dst))
>>> +				folio_put(dst);
>>>   			else
>>> -				putback_lru_page(newpage);
>>> +				folio_putback_lru(dst);
>>>   		}
>>>   	}
>>>   }
>>
  

Patch

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index 9152a329b0a68..a48d5cdb28553 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -843,17 +843,17 @@  void migrate_device_finalize(unsigned long *src_pfns,
 		remove_migration_ptes(src, dst, false);
 		folio_unlock(src);
 
-		if (is_zone_device_page(page))
-			put_page(page);
+		if (folio_is_zone_device(src))
+			folio_put(src);
 		else
-			putback_lru_page(page);
+			folio_putback_lru(src);
 
 		if (newpage != page) {
-			unlock_page(newpage);
-			if (is_zone_device_page(newpage))
-				put_page(newpage);
+			folio_unlock(dst);
+			if (folio_is_zone_device(dst))
+				folio_put(dst);
 			else
-				putback_lru_page(newpage);
+				folio_putback_lru(dst);
 		}
 	}
 }