From: Matthew Brost <matthew.brost@intel.com>
To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Carlos Santa" <carlos.santa@intel.com>,
"Christian Koenig" <christian.koenig@amd.com>,
"Huang Rui" <ray.huang@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>,
"Daniel Colascione" <dancol@dancol.org>
Subject: [PATCH v2 3/5] drm/ttm: Introduce ttm_bo_shrink_kswap_fragmented()
Date: Wed, 22 Apr 2026 22:56:54 -0700 [thread overview]
Message-ID: <20260423055656.1696379-4-matthew.brost@intel.com> (raw)
In-Reply-To: <20260423055656.1696379-1-matthew.brost@intel.com>
Introduce ttm_bo_shrink_kswap_fragmented() to allow TTM users to
distinguish background reclaim from kswapd that is likely driven by
high-order allocation failures under fragmentation.
The helper returns true when:
- reclaim is running in kswapd, and
- the target node is valid, and
- one of the relevant zones reports free pages significantly above
its high watermark (via zone_appears_fragmented()).
This provides a coarse signal that overall free memory is available,
and that reclaim activity may be driven by fragmentation rather than
true memory pressure.
The intent is to allow drivers to adjust shrinker behavior in this
case, for example by preferring purgeable or low-value objects instead
of aggressively evicting active working sets in the background reclaim
path.
The heuristic is intentionally simple and conservative, and is not
intended to replace core MM fragmentation or compaction decisions.
No functional change; this is a preparatory helper for TTM users.
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Matthew Brost <matthew.brost@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: Daniel Colascione <dancol@dancol.org>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/ttm/ttm_bo_util.c | 34 +++++++++++++++++++++++++++++++
include/drm/ttm/ttm_bo.h | 2 ++
2 files changed, 36 insertions(+)
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index f83b7d5ec6c6..46adcb7d9a0c 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -1169,3 +1169,37 @@ bool ttm_bo_shrink_avoid_wait(void)
return !current_is_kswapd();
}
EXPORT_SYMBOL(ttm_bo_shrink_avoid_wait);
+
+/**
+ * ttm_bo_shrink_kswap_fragmented() - Whether in kswap and memory appears
+ * fragmented
+ * @nid: current node being shrunk
+ *
+ * Return: true if in kswap and memory appears fragmented, false is not.
+ */
+bool ttm_bo_shrink_kswap_fragmented(int nid)
+{
+ enum zone_type zone_type;
+
+ if (!current_is_kswapd())
+ return false;
+
+ if (!numa_valid_node(nid))
+ return false;
+
+#if IS_ENABLED(CONFIG_ZONE_DMA32)
+ zone_type = ZONE_DMA32;
+#else
+ zone_type = ZONE_NORMAL;
+#endif
+
+ for (; zone_type <= ZONE_NORMAL; ++zone_type) {
+ struct zone *zone = &NODE_DATA(nid)->node_zones[zone_type];
+
+ if (zone_appears_fragmented(zone))
+ return true;
+ }
+
+ return false;
+}
+EXPORT_SYMBOL(ttm_bo_shrink_kswap_fragmented);
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 8310bc3d55f9..9a457fd667bb 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -262,6 +262,8 @@ bool ttm_bo_shrink_suitable(struct ttm_buffer_object *bo, struct ttm_operation_c
bool ttm_bo_shrink_avoid_wait(void);
+bool ttm_bo_shrink_kswap_fragmented(int nid);
+
/**
* ttm_bo_reserve:
*
--
2.34.1
next prev parent reply other threads:[~2026-04-23 5:57 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-23 5:56 [PATCH v2 0/5] mm, drm/ttm, drm/xe: Avoid reclaim/eviction loops under fragmentation Matthew Brost
2026-04-23 5:56 ` [PATCH v2 1/5] mm: Introduce zone_appears_fragmented() Matthew Brost
2026-04-23 6:04 ` Balbir Singh
2026-04-23 6:16 ` Matthew Brost
2026-04-23 6:27 ` Matthew Brost
2026-04-23 10:27 ` David Hildenbrand (Arm)
2026-04-23 11:27 ` Thomas Hellström
2026-04-23 19:08 ` Matthew Brost
2026-04-23 22:21 ` Matthew Brost
2026-04-24 7:05 ` Thomas Hellström
2026-04-24 7:26 ` David Hildenbrand (Arm)
2026-04-30 2:47 ` Matthew Brost
2026-04-30 7:47 ` Thomas Hellström
2026-04-30 16:34 ` Matthew Brost
2026-04-30 19:59 ` Thomas Hellström
2026-04-30 17:06 ` Vlastimil Babka (SUSE)
2026-04-28 9:51 ` Andi Shyti
2026-04-28 10:05 ` Andi Shyti
2026-04-30 2:34 ` Matthew Brost
2026-04-30 2:37 ` Matthew Brost
2026-04-23 5:56 ` [PATCH v2 2/5] drm/ttm: Issue direct reclaim at beneficial_order Matthew Brost
2026-04-28 9:55 ` Andi Shyti
2026-04-23 5:56 ` Matthew Brost [this message]
2026-04-28 10:07 ` [PATCH v2 3/5] drm/ttm: Introduce ttm_bo_shrink_kswap_fragmented() Andi Shyti
2026-04-30 6:23 ` Matthew Brost
2026-04-30 7:39 ` Christian König
2026-04-23 5:56 ` [PATCH v2 4/5] drm/xe: Set TTM device beneficial_order to 9 (2M) Matthew Brost
2026-04-28 10:46 ` Andi Shyti
2026-04-23 5:56 ` [PATCH v2 5/5] drm/xe: Avoid shrinker reclaim from kswapd under fragmentation Matthew Brost
2026-04-23 6:04 ` ✓ CI.KUnit: success for mm, drm/ttm, drm/xe: Avoid reclaim/eviction loops " Patchwork
2026-04-23 6:53 ` ✓ Xe.CI.BAT: " Patchwork
2026-04-23 17:30 ` ✗ 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=20260423055656.1696379-4-matthew.brost@intel.com \
--to=matthew.brost@intel.com \
--cc=airlied@gmail.com \
--cc=carlos.santa@intel.com \
--cc=christian.koenig@amd.com \
--cc=dancol@dancol.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.auld@intel.com \
--cc=mripard@kernel.org \
--cc=ray.huang@amd.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