From: Matthew Brost <matthew.brost@intel.com>
To: Natalie Vock <nat@pixelcluster.dev>
Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
"Carlos Santa" <carlos.santa@intel.com>,
"Ryan Neph" <ryanneph@google.com>,
"Arun Pravin" <arunpravin.paneerselvam@amd.com>,
"Matthew Auld" <matthew.auld@intel.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
linux-kernel@vger.kernel.org,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Niranjana Vishwanathapura" <niranjana.vishwanathapura@intel.com>
Subject: Re: [PATCH v6 02/35] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper
Date: Fri, 4 Dec 2026 09:36:31 -0800 [thread overview]
Message-ID: <axL6H4s5WBi4f8NB@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <L8CKP82cTMuvUOXNlJAweQ@pixelcluster.dev>
On Fri, Dec 04, 2026 at 02:12:26PM +0100, Natalie Vock wrote:
> On Thursday, 3 December 2026 21:23 Matthew Brost wrote:
> > TTM records the allocation order of a multi-order page in page->private at
> > allocation time. For pools that do not use dma_alloc the order is stored
> > directly, while dma_alloc pools store a struct ttm_pool_dma pointer there
> > instead. Drivers that do their own DMA mapping (e.g. Xe) need the per-page
> > order to walk a populated ttm_tt one chunk at a time, but cannot rely on
> > folio_order(): TTM allocates high-order pages with alloc_pages_node()
> > without __GFP_COMP, so they are not compound and folio_order() always
> > returns 0.
>
> I'm not completely sure why this is needed?
> Is the problem that you don't know the relevant ttm_pool at the
> callsite? AFAICT Xe never sets TTM_ALLOCATION_POOL_USE_DMA_ALLOC, so
> why isn't ttm_pool_page_order enough?
>
Xe doesn't set TTM_ALLOCATION_POOL_USE_DMA_ALLOC and doesn't (easily)
have access to the TTM pool at the call site, so add a new helper to
derive the order from a page.
Eventually, we should switch to using compound pages (i.e., folios), and
this entire helper can go away. I floated a patch for that, but
Christian said there might be historical reasons why this didn't
work with KVM, if I recall correctly. Neither of us had time to
investigate whether that's true, but for what it's worth, compound pages
worked just fine in TTM/Xe.
> Besides, why can't TTM know about the IOVA-based DMA mapping?
> Managing DMA mappings for pool pages sounds like a TTM responsibility,
> is there any reason why the logic needs to be hidden from it inside Xe?
>
Ok, this is a bit of a can of worms. Let me give you some background.
When Xe had the PoC from Faith, by the time she handed it over to me and
a few others, the DMA mapping was already implemented inside Xe. I was
blissfully unaware that TTM could perform the DMA mapping itself. I only
realized that TTM had DMA-mapping support once I started working on this
series.
I also noticed that TTM performs DMA mapping in about the worst possible
way for performance: it calls dma_map_page() on each individual page,
and each call issues an IOMMU sync. Compare that to SG-based DMA mapping
or IOVA-based DMA mapping, where all IOMMU page tables are programmed
first and then a single IOMMU sync is issued. iirc when I switched
GPUSVM to use dma_iova_* vs. dma_map_page for 512 4k pages, I got
something like a 100x speedup.
I'm not going to switch Xe over to TTM-based DMA mapping and knowingly
regress performance.
Maybe we can look at making TTM's DMA-mapping implementation less
terrible in a follow-up, but that would require reworking multiple
drivers and is, in my opinion, out of scope for this series.
Matt
> Thanks,
> Natalie
>
> >
> > Expose ttm_pool_page_order_nodma(), a thin wrapper that returns the order
> > recorded in page->private. It is only valid for pages from a pool that does
> > not use dma_alloc; whether a TTM device uses dma_alloc is fixed at ttm
> > device init time, so callers know from their device configuration that this
> > helper applies. Use it from the existing internal ttm_pool_page_order() to
> > keep a single source of truth.
> >
> > v4:
> > - const struct page (Niranjana)
> >
> > Cc: Carlos Santa <carlos.santa@intel.com>
> > Cc: Ryan Neph <ryanneph@google.com>
> > Cc: Natalie Vock <nat@pixelcluster.dev>
> > Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
> > Cc: Matthew Auld <matthew.auld@intel.com>
> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Cc: Maxime Ripard <mripard@kernel.org>
> > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > Cc: David Airlie <airlied@gmail.com>
> > Cc: Simona Vetter <simona@ffwll.ch>
> > Cc: dri-devel@lists.freedesktop.org
> > Cc: linux-kernel@vger.kernel.org
> > Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> > Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> > Reviewed-by: Matthew Auld <matthew.auld@intel.com>
> > Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
> > ---
> > drivers/gpu/drm/ttm/ttm_pool.c | 25 ++++++++++++++++++++++++-
> > include/drm/ttm/ttm_pool.h | 2 ++
> > 2 files changed, 26 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> > index 16fd125d7375..c6fbcdba9bdb 100644
> > --- a/drivers/gpu/drm/ttm/ttm_pool.c
> > +++ b/drivers/gpu/drm/ttm/ttm_pool.c
> > @@ -477,6 +477,29 @@ static unsigned int ttm_pool_shrink(int nid, unsigned long num_to_free)
> > return num_pages;
> > }
> >
> > +/**
> > + * ttm_pool_page_order_nodma() - Allocation order of a non-dma_alloc TTM page
> > + * @p: The page to query.
> > + *
> > + * Return the allocation order that the TTM pool allocator recorded in
> > + * @p->private at allocation time. This only works for pages that were
> > + * allocated from a pool which does *not* use dma_alloc (i.e. pages backed by
> > + * alloc_pages_node()), where TTM stores the order directly in page->private.
> > + *
> > + * For dma_alloc pools, page->private instead holds a struct ttm_pool_dma
> > + * pointer and this helper must not be used. Whether a TTM device uses
> > + * dma_alloc is fixed at ttm device init time, so callers are expected to know
> > + * from their TTM device configuration that their pages are not dma_alloc
> > + * backed before using this helper.
> > + *
> > + * Return: The allocation order of the page.
> > + */
> > +unsigned int ttm_pool_page_order_nodma(const struct page *p)
> > +{
> > + return p->private;
> > +}
> > +EXPORT_SYMBOL(ttm_pool_page_order_nodma);
> > +
> > /* Return the allocation order based for a page */
> > static unsigned int ttm_pool_page_order(struct ttm_pool *pool, struct page *p)
> > {
> > @@ -486,7 +509,7 @@ static unsigned int ttm_pool_page_order(struct ttm_pool *pool, struct page *p)
> > return dma->vaddr & ~PAGE_MASK;
> > }
> >
> > - return p->private;
> > + return ttm_pool_page_order_nodma(p);
> > }
> >
> > /*
> > diff --git a/include/drm/ttm/ttm_pool.h b/include/drm/ttm/ttm_pool.h
> > index bb6347e5b297..429f4f987a19 100644
> > --- a/include/drm/ttm/ttm_pool.h
> > +++ b/include/drm/ttm/ttm_pool.h
> > @@ -94,6 +94,8 @@ long ttm_pool_backup(struct ttm_pool *pool, struct ttm_tt *ttm,
> > int ttm_pool_restore_and_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
> > const struct ttm_operation_ctx *ctx);
> >
> > +unsigned int ttm_pool_page_order_nodma(const struct page *p);
> > +
> > int ttm_pool_mgr_init(void);
> > void ttm_pool_mgr_fini(void);
> >
> >
>
>
>
>
next prev parent reply other threads:[~2026-12-04 17:36 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 20:23 [PATCH v6 00/35] drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs Matthew Brost
2026-12-03 20:23 ` [PATCH v6 01/35] drm/ttm/pool: Allow backing off reclaim at the beneficial order Matthew Brost
2026-12-03 20:23 ` [PATCH v6 02/35] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Matthew Brost
2026-12-04 13:12 ` Natalie Vock
2026-12-04 17:36 ` Matthew Brost [this message]
2026-12-03 20:23 ` [PATCH v6 03/35] drm/ttm: Record sub-optimal page order allocations in ttm_tt Matthew Brost
2026-12-04 13:16 ` Natalie Vock
2026-12-03 20:23 ` [PATCH v6 04/35] drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc() Matthew Brost
2026-12-04 13:39 ` Natalie Vock
2026-12-03 20:23 ` [PATCH v6 05/35] drm/ttm: Support defragmentation moves Matthew Brost
2026-12-04 14:04 ` Natalie Vock
2026-12-04 19:17 ` Matthew Brost
2026-12-03 20:23 ` [PATCH v6 06/35] drm/ttm: Add fault injection for beneficial-order allocation failures Matthew Brost
2026-12-03 20:23 ` [PATCH v6 07/35] drm/ttm/pool: Keep chunks self-aligned when resuming an interrupted restore Matthew Brost
2026-12-03 21:00 ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 08/35] drm/ttm: Harvest beneficial-order pages on defragmentation moves Matthew Brost
2026-12-03 23:11 ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 09/35] drm/ttm: Bound page (re)allocation per defragmentation move Matthew Brost
2026-12-03 20:23 ` [PATCH v6 10/35] drm/ttm: Preallocate beneficial-order defrag pages outside the lock Matthew Brost
2026-12-04 2:37 ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 11/35] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc() Matthew Brost
2026-12-04 3:39 ` Niranjana Vishwanathapura
2026-12-04 4:20 ` Matthew Brost
2026-12-03 20:23 ` [PATCH v6 12/35] drm/gpusvm: Add a DMA-mapping accounting callback Matthew Brost
2026-12-03 20:23 ` [PATCH v6 13/35] drm/xe: Add debugfs stats for DMA-mapped pages per order Matthew Brost
2026-12-03 20:23 ` [PATCH v6 14/35] drm/xe: Track BOs backed at a sub-optimal page order Matthew Brost
2026-12-04 20:00 ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 15/35] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies Matthew Brost
2026-12-03 20:23 ` [PATCH v6 16/35] drm/xe: Handle defrag moves in xe_bo_move() Matthew Brost
2026-12-04 4:54 ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 17/35] drm/xe: Skip self-copies for borrowed pages on defrag moves Matthew Brost
2026-12-04 21:13 ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 18/35] drm/xe: Add a page defragmentation worker Matthew Brost
2026-12-04 21:22 ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 19/35] drm/xe: Add defrag GT stats Matthew Brost
2026-12-03 20:23 ` [PATCH v6 20/35] drm/xe: Add Kconfig.profile options for BO defrag configuration Matthew Brost
2026-12-03 20:23 ` [PATCH v6 21/35] drm/xe: Defrag using out-of-lock page preallocation Matthew Brost
2026-12-04 21:33 ` Niranjana Vishwanathapura
2026-12-03 20:23 ` [PATCH v6 22/35] drm/xe: Add defrag profiling tracepoints Matthew Brost
2026-12-03 20:23 ` [PATCH v6 23/35] drm/xe: Preallocate system BO backing outside the dma-resv lock Matthew Brost
2026-12-03 20:23 ` [PATCH v6 24/35] drm/xe: Add tracepoint for xe_gem_create_ioctl Matthew Brost
2026-12-03 20:23 ` [PATCH v6 25/35] drm/xe: Add IOVA-based xe_res_cursor variant Matthew Brost
2026-12-03 20:23 ` [PATCH v6 26/35] drm/xe: Don't DMA map tt pages after device unplug Matthew Brost
2026-12-04 12:21 ` Matthew Auld
2026-12-03 20:23 ` [PATCH v6 27/35] drm/xe: Lock the bo in xe_bo_dma_unmap_pinned() Matthew Brost
2026-12-03 20:23 ` [PATCH v6 28/35] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs Matthew Brost
2026-12-04 11:57 ` Matthew Auld
2026-12-03 20:23 ` [PATCH v6 29/35] drm/xe: Add per-device dependency scheduler for IOVA defrag finalize Matthew Brost
2026-12-03 20:23 ` [PATCH v6 30/35] drm/xe: Add packed copy-step IOVA mapping for defrag Matthew Brost
2026-12-03 20:23 ` [PATCH v6 31/35] drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies Matthew Brost
2026-12-04 15:39 ` Matthew Auld
2026-12-03 20:23 ` [PATCH v6 32/35] drm/xe: Finalize defrag-IOVA moves with post-copy job Matthew Brost
2026-12-03 20:23 ` [PATCH v6 33/35] drm/xe: Grow the USM batch pool to 2M and map it via a single PDE Matthew Brost
2026-12-03 20:23 ` [PATCH v6 34/35] drm/xe: Add bo_defrag debugfs entry Matthew Brost
2026-12-03 20:23 ` [PATCH v6 35/35] drm/xe: Make BO defrag tunables configurable via sysfs Matthew Brost
2026-12-03 21:02 ` ✓ CI.KUnit: success for drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs (rev3) Patchwork
2026-12-03 21:46 ` ✓ Xe.CI.BAT: " Patchwork
2026-12-04 21:42 ` ✗ 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=axL6H4s5WBi4f8NB@gsse-cloud1.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=airlied@gmail.com \
--cc=arunpravin.paneerselvam@amd.com \
--cc=carlos.santa@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.auld@intel.com \
--cc=mripard@kernel.org \
--cc=nat@pixelcluster.dev \
--cc=niranjana.vishwanathapura@intel.com \
--cc=ryanneph@google.com \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tzimmermann@suse.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox