]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/pagemap: Unlock and put folios when possible
authorFrancois Dugast <francois.dugast@intel.com>
Thu, 12 Mar 2026 19:20:11 +0000 (20:20 +0100)
committerMatthew Brost <matthew.brost@intel.com>
Sat, 14 Mar 2026 01:12:06 +0000 (18:12 -0700)
If the page is part of a folio, unlock and put the whole folio at once
instead of individual pages one after the other. This will reduce the
amount of operations once device THP are in use.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: linux-mm@kvack.org
Suggested-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Francois Dugast <francois.dugast@intel.com>
Reviewed-by: Balbir Singh <balbirs@nvidia.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Link: https://patch.msgid.link/20260312192126.2024853-2-francois.dugast@intel.com
drivers/gpu/drm/drm_pagemap.c

index 862675ac5bb2104816304499a09f5ce626861a97..f453a12b6a8e45b2793170d078e92fcd088156a0 100644 (file)
@@ -154,15 +154,15 @@ static void drm_pagemap_zdd_put(struct drm_pagemap_zdd *zdd)
 }
 
 /**
- * drm_pagemap_migration_unlock_put_page() - Put a migration page
- * @page: Pointer to the page to put
+ * drm_pagemap_migration_unlock_put_folio() - Put a migration folio
+ * @folio: Pointer to the folio to put
  *
- * This function unlocks and puts a page.
+ * This function unlocks and puts a folio.
  */
-static void drm_pagemap_migration_unlock_put_page(struct page *page)
+static void drm_pagemap_migration_unlock_put_folio(struct folio *folio)
 {
-       unlock_page(page);
-       put_page(page);
+       folio_unlock(folio);
+       folio_put(folio);
 }
 
 /**
@@ -177,15 +177,23 @@ static void drm_pagemap_migration_unlock_put_pages(unsigned long npages,
 {
        unsigned long i;
 
-       for (i = 0; i < npages; ++i) {
+       for (i = 0; i < npages;) {
                struct page *page;
+               struct folio *folio;
+               unsigned int order = 0;
 
                if (!migrate_pfn[i])
-                       continue;
+                       goto next;
 
                page = migrate_pfn_to_page(migrate_pfn[i]);
-               drm_pagemap_migration_unlock_put_page(page);
+               folio = page_folio(page);
+               order = folio_order(folio);
+
+               drm_pagemap_migration_unlock_put_folio(folio);
                migrate_pfn[i] = 0;
+
+next:
+               i += NR_PAGES(order);
        }
 }