diff mbox series

[v2,09/10] mm: migrate_device: use more folio in migrate_device_unmap()

Message ID 20240425084028.3888403-10-wangkefeng.wang@huawei.com (mailing list archive)
State New
Headers show
Series mm: remove isolate_lru_page() and isolate_movable_page() | expand

Commit Message

Kefeng Wang April 25, 2024, 8:40 a.m. UTC
The page for migrate_device_unmap() already has a reference, so it is
safe to convert the page to folio to save a few calls to compound_head(),
which removes the last isolate_lru_page() call.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/migrate_device.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

David Hildenbrand April 25, 2024, 9:31 a.m. UTC | #1
On 25.04.24 10:40, Kefeng Wang wrote:
> The page for migrate_device_unmap() already has a reference, so it is
> safe to convert the page to folio to save a few calls to compound_head(),
> which removes the last isolate_lru_page() call.
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>   mm/migrate_device.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index a68616c1965f..423d71ad736a 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -379,33 +379,33 @@ static unsigned long migrate_device_unmap(unsigned long *src_pfns,
>   			continue;
>   		}
>   
> +		folio = page_folio(page);
>   		/* ZONE_DEVICE pages are not on LRU */
> -		if (!is_zone_device_page(page)) {
> -			if (!PageLRU(page) && allow_drain) {
> +		if (!folio_is_zone_device(folio)) {
> +			if (!folio_test_lru(folio) && allow_drain) {
>   				/* Drain CPU's lru cache */
>   				lru_add_drain_all();
>   				allow_drain = false;
>   			}
>   
> -			if (!isolate_lru_page(page)) {
> +			if (!folio_isolate_lru(folio)) {
>   				src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
>   				restore++;
>   				continue;
>   			}
>   
>   			/* Drop the reference we took in collect */
> -			put_page(page);
> +			folio_put(folio);
>   		}
>   
> -		folio = page_folio(page);
>   		if (folio_mapped(folio))
>   			try_to_migrate(folio, 0);
>   
>   		if (page_mapped(page) ||

folio_mapped(), just as above
Kefeng Wang April 25, 2024, 11:05 a.m. UTC | #2
On 2024/4/25 17:31, David Hildenbrand wrote:
> On 25.04.24 10:40, Kefeng Wang wrote:
>> The page for migrate_device_unmap() already has a reference, so it is
>> safe to convert the page to folio to save a few calls to compound_head(),
>> which removes the last isolate_lru_page() call.
>>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>> ---
>>   mm/migrate_device.c | 16 ++++++++--------
>>   1 file changed, 8 insertions(+), 8 deletions(-)
>>
>> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
>> index a68616c1965f..423d71ad736a 100644
>> --- a/mm/migrate_device.c
>> +++ b/mm/migrate_device.c
>> @@ -379,33 +379,33 @@ static unsigned long 
>> migrate_device_unmap(unsigned long *src_pfns,
>>               continue;
>>           }
>> +        folio = page_folio(page);
>>           /* ZONE_DEVICE pages are not on LRU */
>> -        if (!is_zone_device_page(page)) {
>> -            if (!PageLRU(page) && allow_drain) {
>> +        if (!folio_is_zone_device(folio)) {
>> +            if (!folio_test_lru(folio) && allow_drain) {
>>                   /* Drain CPU's lru cache */
>>                   lru_add_drain_all();
>>                   allow_drain = false;
>>               }
>> -            if (!isolate_lru_page(page)) {
>> +            if (!folio_isolate_lru(folio)) {
>>                   src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
>>                   restore++;
>>                   continue;
>>               }
>>               /* Drop the reference we took in collect */
>> -            put_page(page);
>> +            folio_put(folio);
>>           }
>> -        folio = page_folio(page);
>>           if (folio_mapped(folio))
>>               try_to_migrate(folio, 0);
>>           if (page_mapped(page) ||
> 
> folio_mapped(), just as above

ah, don't know why missing this one, will fix, thanks.

>
diff mbox series

Patch

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index a68616c1965f..423d71ad736a 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -379,33 +379,33 @@  static unsigned long migrate_device_unmap(unsigned long *src_pfns,
 			continue;
 		}
 
+		folio = page_folio(page);
 		/* ZONE_DEVICE pages are not on LRU */
-		if (!is_zone_device_page(page)) {
-			if (!PageLRU(page) && allow_drain) {
+		if (!folio_is_zone_device(folio)) {
+			if (!folio_test_lru(folio) && allow_drain) {
 				/* Drain CPU's lru cache */
 				lru_add_drain_all();
 				allow_drain = false;
 			}
 
-			if (!isolate_lru_page(page)) {
+			if (!folio_isolate_lru(folio)) {
 				src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
 				restore++;
 				continue;
 			}
 
 			/* Drop the reference we took in collect */
-			put_page(page);
+			folio_put(folio);
 		}
 
-		folio = page_folio(page);
 		if (folio_mapped(folio))
 			try_to_migrate(folio, 0);
 
 		if (page_mapped(page) ||
 		    !migrate_vma_check_page(page, fault_page)) {
-			if (!is_zone_device_page(page)) {
-				get_page(page);
-				putback_lru_page(page);
+			if (!folio_is_zone_device(folio)) {
+				folio_get(folio);
+				folio_putback_lru(folio);
 			}
 
 			src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;