From: Matthew Brost <matthew.brost@intel.com>
To: Francois Dugast <francois.dugast@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v2 3/6] drm/pagemap: DMA map folios when possible
Date: Fri, 25 Jul 2025 14:54:22 -0700 [thread overview]
Message-ID: <aIP9Dnp+Ey7snc26@lstrano-desk.jf.intel.com> (raw)
In-Reply-To: <20250725154011.2807655-4-francois.dugast@intel.com>
On Fri, Jul 25, 2025 at 05:39:27PM +0200, Francois Dugast wrote:
> If the page is part of a folio, DMA map the whole folio at once instead of
> mapping individual pages one after the other. For example if 2MB folios
> are used instead of 4KB pages, this reduces the number of DMA mappings by
> 512.
>
> The folio order (and consequently, the size) is persisted in the struct
> drm_pagemap_device_addr to be available at the time of unmapping.
>
> v2:
> - Initialize order variable (Matthew Brost)
> - Set proto and dir for completeness (Matthew Brost)
> - Do not populate drm_pagemap_addr, document it (Matthew Brost)
> - Add and use macro NR_PAGES(order) (Matthew Brost)
>
> Signed-off-by: Francois Dugast <francois.dugast@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
> ---
> drivers/gpu/drm/drm_pagemap.c | 25 ++++++++++++++++++-------
> include/drm/drm_pagemap.h | 10 ++++++++--
> 2 files changed, 26 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_pagemap.c b/drivers/gpu/drm/drm_pagemap.c
> index de320aeed812..b6f5d3a8e445 100644
> --- a/drivers/gpu/drm/drm_pagemap.c
> +++ b/drivers/gpu/drm/drm_pagemap.c
> @@ -222,22 +222,30 @@ static int drm_pagemap_migrate_map_pages(struct device *dev,
> {
> unsigned long i;
>
> - for (i = 0; i < npages; ++i) {
> + for (i = 0; i < npages;) {
> struct page *page = migrate_pfn_to_page(migrate_pfn[i]);
> dma_addr_t dma_addr;
> + struct folio *folio;
> + unsigned int order = 0;
>
> if (!page)
> - continue;
> + goto next;
>
> if (WARN_ON_ONCE(is_zone_device_page(page)))
> return -EFAULT;
>
> - dma_addr = dma_map_page(dev, page, 0, PAGE_SIZE, dir);
> + folio = page_folio(page);
> + order = folio_order(folio);
> +
> + dma_addr = dma_map_page(dev, page, 0, page_size(page), dir);
> if (dma_mapping_error(dev, dma_addr))
> return -EFAULT;
>
> pagemap_addr[i] = drm_pagemap_addr_encode(
> - dma_addr, DRM_INTERCONNECT_SYSTEM, 0, dir);
> + dma_addr, DRM_INTERCONNECT_SYSTEM, order, dir);
> +
> +next:
> + i += NR_PAGES(order);
> }
>
> return 0;
> @@ -261,11 +269,14 @@ static void drm_pagemap_migrate_unmap_pages(struct device *dev,
> {
> unsigned long i;
>
> - for (i = 0; i < npages; ++i) {
> + for (i = 0; i < npages;) {
> if (!pagemap_addr[i].addr || dma_mapping_error(dev, pagemap_addr[i].addr))
> - continue;
> + goto next;
> +
> + dma_unmap_page(dev, pagemap_addr[i].addr, PAGE_SIZE << pagemap_addr[i].order, dir);
>
> - dma_unmap_page(dev, pagemap_addr[i].addr, PAGE_SIZE, dir);
> +next:
> + i += NR_PAGES(pagemap_addr[i].order);
> }
> }
>
> diff --git a/include/drm/drm_pagemap.h b/include/drm/drm_pagemap.h
> index 1d5919a99139..ef18d98dbc7e 100644
> --- a/include/drm/drm_pagemap.h
> +++ b/include/drm/drm_pagemap.h
> @@ -6,6 +6,8 @@
> #include <linux/hmm.h>
> #include <linux/types.h>
>
> +#define NR_PAGES(order) (1U << order)
> +
> struct drm_pagemap;
> struct drm_pagemap_zdd;
> struct device;
> @@ -173,7 +175,9 @@ struct drm_pagemap_devmem_ops {
> * @pagemap_addr: Pointer to array of DMA information (source)
> * @npages: Number of pages to copy
> *
> - * Copy pages to device memory.
> + * Copy pages to device memory. If the order of a @pagemap_addr entry
> + * is greater than 0, the entry is populated but subsequent entries
> + * within the range of that order are not populated.
> *
> * Return: 0 on success, a negative error code on failure.
> */
> @@ -187,7 +191,9 @@ struct drm_pagemap_devmem_ops {
> * @pagemap_addr: Pointer to array of DMA information (destination)
> * @npages: Number of pages to copy
> *
> - * Copy pages to system RAM.
> + * Copy pages to system RAM. If the order of a @pagemap_addr entry
> + * is greater than 0, the entry is populated but subsequent entries
> + * within the range of that order are not populated.
> *
> * Return: 0 on success, a negative error code on failure.
> */
> --
> 2.43.0
>
next prev parent reply other threads:[~2025-07-25 21:52 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-25 15:39 [PATCH v2 0/6] Prepare GPU SVM for migration of THP Francois Dugast
2025-07-25 15:39 ` [PATCH v2 1/6] drm/pagemap: Rename drm_pagemap_device_addr to drm_pagemap_addr Francois Dugast
2025-07-25 21:46 ` Matthew Brost
2025-07-25 15:39 ` [PATCH v2 2/6] drm/pagemap: Use struct drm_pagemap_addr in mapping and copy functions Francois Dugast
2025-07-25 21:52 ` Matthew Brost
2025-07-25 15:39 ` [PATCH v2 3/6] drm/pagemap: DMA map folios when possible Francois Dugast
2025-07-25 21:54 ` Matthew Brost [this message]
2025-07-25 15:39 ` [PATCH v2 4/6] drm/pagemap: Allocate " Francois Dugast
2025-07-25 21:43 ` Matthew Brost
2025-07-28 10:18 ` Francois Dugast
2025-07-29 6:15 ` Matthew Brost
2025-07-25 15:39 ` [PATCH v2 5/6] drm/xe/migrate: Populate struct drm_pagemap_addr array Francois Dugast
2025-07-25 23:04 ` Matthew Brost
2025-07-25 15:39 ` [PATCH v2 6/6] drm/xe/svm: Migrate folios when possible Francois Dugast
2025-07-25 23:14 ` Matthew Brost
2025-07-28 14:10 ` Francois Dugast
2025-07-28 20:09 ` Matthew Brost
2025-07-28 21:15 ` Matthew Brost
2025-07-25 16:30 ` ✗ CI.checkpatch: warning for Prepare GPU SVM for migration of THP (rev2) Patchwork
2025-07-25 16:31 ` ✓ CI.KUnit: success " Patchwork
2025-07-25 17:29 ` ✓ Xe.CI.BAT: " Patchwork
2025-07-25 19:02 ` ✗ Xe.CI.Full: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aIP9Dnp+Ey7snc26@lstrano-desk.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=francois.dugast@intel.com \
--cc=intel-xe@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.