diff mbox series

[4/6] mm: migrate_device: use more folio in migrate_device_finalize()

Message ID 20240826065814.1336616-5-wangkefeng.wang@huawei.com (mailing list archive)
State New
Headers show
Series mm: finish isolate/putback_lru_page() | expand

Commit Message

Kefeng Wang Aug. 26, 2024, 6:58 a.m. UTC
Saves a couple of calls to compound_head() and remove last two callers
of putback_lru_page().

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

Comments

Vishal Moola Aug. 26, 2024, 5:53 p.m. UTC | #1
On Mon, Aug 26, 2024 at 02:58:12PM +0800, Kefeng Wang wrote:
> Saves a couple of calls to compound_head() and remove last two callers
> of putback_lru_page().
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Alistair Popple Aug. 27, 2024, 5:48 a.m. UTC | #2
Kefeng Wang <wangkefeng.wang@huawei.com> writes:

> Saves a couple of calls to compound_head() and remove last two callers
> of putback_lru_page().
>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>  mm/migrate_device.c | 41 ++++++++++++++++++++++-------------------
>  1 file changed, 22 insertions(+), 19 deletions(-)
>
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index b49f4956617a..6ea3d055f520 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -815,42 +815,45 @@ void migrate_device_finalize(unsigned long *src_pfns,
>  	unsigned long i;
>  
>  	for (i = 0; i < npages; i++) {
> -		struct folio *dst, *src;
> +		struct folio *dst = NULL, *src = NULL;
>  		struct page *newpage = migrate_pfn_to_page(dst_pfns[i]);
>  		struct page *page = migrate_pfn_to_page(src_pfns[i]);

We could probably simplify this even further with a
migrate_pfn_to_folio() function. I'm still working on extending
ZONE_DEVICE to support higher order folios though (held up fixing
refcounts) so this can wait until then.

Reviewed-by: Alistair Popple <apopple@nvidia.com>

>  
> +		if (newpage)
> +			dst = page_folio(newpage);
> +
>  		if (!page) {
> -			if (newpage) {
> -				unlock_page(newpage);
> -				put_page(newpage);
> +			if (dst) {
> +				folio_unlock(dst);
> +				folio_put(dst);
>  			}
>  			continue;
>  		}
>  
> -		if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !newpage) {
> -			if (newpage) {
> -				unlock_page(newpage);
> -				put_page(newpage);
> +		src = page_folio(page);
> +
> +		if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !dst) {
> +			if (dst) {
> +				folio_unlock(dst);
> +				folio_put(dst);
>  			}
> -			newpage = page;
> +			dst = src;
>  		}
>  
> -		src = page_folio(page);
> -		dst = page_folio(newpage);
>  		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);
> +		if (dst != src) {
> +			folio_unlock(dst);
> +			if (folio_is_zone_device(dst))
> +				folio_put(dst);
>  			else
> -				putback_lru_page(newpage);
> +				folio_putback_lru(dst);
>  		}
>  	}
>  }
diff mbox series

Patch

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index b49f4956617a..6ea3d055f520 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -815,42 +815,45 @@  void migrate_device_finalize(unsigned long *src_pfns,
 	unsigned long i;
 
 	for (i = 0; i < npages; i++) {
-		struct folio *dst, *src;
+		struct folio *dst = NULL, *src = NULL;
 		struct page *newpage = migrate_pfn_to_page(dst_pfns[i]);
 		struct page *page = migrate_pfn_to_page(src_pfns[i]);
 
+		if (newpage)
+			dst = page_folio(newpage);
+
 		if (!page) {
-			if (newpage) {
-				unlock_page(newpage);
-				put_page(newpage);
+			if (dst) {
+				folio_unlock(dst);
+				folio_put(dst);
 			}
 			continue;
 		}
 
-		if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !newpage) {
-			if (newpage) {
-				unlock_page(newpage);
-				put_page(newpage);
+		src = page_folio(page);
+
+		if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !dst) {
+			if (dst) {
+				folio_unlock(dst);
+				folio_put(dst);
 			}
-			newpage = page;
+			dst = src;
 		}
 
-		src = page_folio(page);
-		dst = page_folio(newpage);
 		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);
+		if (dst != src) {
+			folio_unlock(dst);
+			if (folio_is_zone_device(dst))
+				folio_put(dst);
 			else
-				putback_lru_page(newpage);
+				folio_putback_lru(dst);
 		}
 	}
 }