From: Matthew Brost <matthew.brost@intel.com>
To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: "Carlos Santa" <carlos.santa@intel.com>,
"Ryan Neph" <ryanneph@google.com>,
"Natalie Vock" <nat@pixelcluster.dev>,
"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>
Subject: [PATCH v5 07/36] drm/ttm/pool: Keep chunks self-aligned when resuming an interrupted restore
Date: Wed, 2 Dec 2026 15:32:54 -0800 [thread overview]
Message-ID: <20261202233323.3743190-8-matthew.brost@intel.com> (raw)
In-Reply-To: <20261202233323.3743190-1-matthew.brost@intel.com>
__ttm_pool_alloc() fills a tt with a non-increasing order walk starting
at MAX_PAGE_ORDER, so every order-k chunk lands at a 2^k-aligned offset
in the tt. ttm_pool_restore_and_alloc() however may be interrupted
(e.g. -EINTR from ttm_pool_restore_commit()) and later resume
__ttm_pool_alloc() at a non-zero offset. The walk then restarts at
MAX_PAGE_ORDER, bounded only by the number of remaining pages, and can
place a large chunk at an unaligned offset (e.g. an order-9 chunk at
offset 256 after an order-8 fallback).
That is harmless today, but upcoming defragmentation support relies on
chunks being self-aligned to borrow whole chunks from an old tt at the
same offset. Cap the starting order by the alignment of the offset being
resumed at, which keeps the invariant at negligible cost: at worst an
interrupted restore misses a single larger order.
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>
---
drivers/gpu/drm/ttm/ttm_pool.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index 4e146798848a..5c7fec62aa30 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -927,6 +927,8 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
.page_caching = tt->caching,
.allow_pools = true,
};
+ pgoff_t off = tt->num_pages - alloc->remaining_pages;
+ unsigned int start_order = MAX_PAGE_ORDER;
gfp_t gfp_flags = GFP_USER;
pgoff_t caching_divide;
int r;
@@ -947,7 +949,17 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
it.gfp_flags = gfp_flags;
- for (it.order = ttm_pool_alloc_find_order(MAX_PAGE_ORDER, alloc);
+ /*
+ * Keep chunks self-aligned (an order-k chunk at a 2^k-aligned offset):
+ * the order walk below is non-increasing, so that holds as long as it
+ * starts at an order @off is aligned to. @off is only non-zero when
+ * resuming an interrupted restore, which would otherwise restart at
+ * MAX_PAGE_ORDER and could place a large chunk at an unaligned offset.
+ */
+ if (off)
+ start_order = min_t(unsigned int, start_order, __ffs(off));
+
+ for (it.order = ttm_pool_alloc_find_order(start_order, alloc);
alloc->remaining_pages;
it.order = ttm_pool_alloc_find_order(it.order, alloc)) {
/* Acquire a page (pool / system) for this order. */
--
2.34.1
next prev parent reply other threads:[~2026-12-02 23:33 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261202233323.3743190-1-matthew.brost@intel.com>
2026-12-02 23:32 ` [PATCH v5 01/36] drm/ttm/pool: Allow backing off reclaim at the beneficial order Matthew Brost
2026-12-02 23:32 ` [PATCH v5 02/36] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Matthew Brost
2026-12-02 23:32 ` [PATCH v5 03/36] drm/ttm: Record sub-optimal page order allocations in ttm_tt Matthew Brost
2026-12-02 23:32 ` [PATCH v5 04/36] drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc() Matthew Brost
2026-12-02 23:32 ` [PATCH v5 05/36] drm/ttm: Support defragmentation moves Matthew Brost
2026-12-02 23:32 ` [PATCH v5 06/36] drm/ttm: Add fault injection for beneficial-order allocation failures Matthew Brost
2026-12-02 23:32 ` Matthew Brost [this message]
2026-12-02 23:32 ` [PATCH v5 08/36] drm/ttm: Harvest beneficial-order pages on defragmentation moves Matthew Brost
2026-12-02 23:32 ` [PATCH v5 09/36] drm/ttm: Bound page (re)allocation per defragmentation move Matthew Brost
2026-12-02 23:32 ` [PATCH v5 10/36] drm/ttm: Preallocate beneficial-order defrag pages outside the lock Matthew Brost
2026-12-02 23:32 ` [PATCH v5 11/36] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc() Matthew Brost
2026-12-02 23:33 ` [PATCH v5 14/36] drm/xe: Track BOs backed at a sub-optimal page order Matthew Brost
2026-12-02 23:33 ` [PATCH v5 15/36] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies Matthew Brost
2026-12-02 23:33 ` [PATCH v5 16/36] drm/xe: Handle defrag moves in xe_bo_move() Matthew Brost
2026-12-02 23:33 ` [PATCH v5 17/36] drm/xe: Skip self-copies for borrowed pages on defrag moves Matthew Brost
2026-12-02 23:33 ` [PATCH v5 18/36] drm/xe: Add a page defragmentation worker Matthew Brost
2026-12-02 23:33 ` [PATCH v5 19/36] drm/xe: Add defrag GT stats Matthew Brost
2026-12-02 23:33 ` [PATCH v5 20/36] drm/xe: Add Kconfig.profile options for BO defrag configuration Matthew Brost
2026-12-03 3:35 ` Niranjana Vishwanathapura
2026-12-02 23:33 ` [PATCH v5 21/36] drm/xe: Defrag using out-of-lock page preallocation Matthew Brost
2026-12-02 23:33 ` [PATCH v5 22/36] drm/xe: Add defrag profiling tracepoints Matthew Brost
2026-12-03 4:03 ` Niranjana Vishwanathapura
2026-12-02 23:33 ` [PATCH v5 23/36] drm/xe: Preallocate system BO backing outside the dma-resv lock Matthew Brost
2026-12-03 4:38 ` Niranjana Vishwanathapura
2026-12-02 23:33 ` [PATCH v5 24/36] drm/xe: Add tracepoint for xe_gem_create_ioctl Matthew Brost
2026-12-02 23:33 ` [PATCH v5 25/36] drm/xe: Add IOVA-based xe_res_cursor variant Matthew Brost
2026-12-02 23:33 ` [PATCH v5 29/36] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs Matthew Brost
2026-12-02 23:33 ` [PATCH v5 30/36] drm/xe: Add per-device dependency scheduler for IOVA defrag finalize Matthew Brost
2026-12-02 23:33 ` [PATCH v5 31/36] drm/xe: Add packed copy-step IOVA mapping for defrag Matthew Brost
2026-12-02 23:33 ` [PATCH v5 32/36] drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies Matthew Brost
2026-12-02 23:33 ` [PATCH v5 33/36] drm/xe: Finalize defrag-IOVA moves with post-copy job Matthew Brost
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=20261202233323.3743190-8-matthew.brost@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=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
all inboxes | Powered by JetHome®