public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Idle the GPU before shinking everything
@ 2017-11-07 21:31 Chris Wilson
  2017-11-08  9:31 ` ✗ Fi.CI.BAT: failure for " Patchwork
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Chris Wilson @ 2017-11-07 21:31 UTC (permalink / raw)
  To: intel-gfx

The handling of contexts are peculiar. Instead of tieing their vma to
activity, we pin the context. This means that we cannot simply unbind
the context object itself at will (which would normally cause us to wait
for the vma to be idle), but must manually idle the GPU and retire
requests first.

A consequence of this peculiarity is when doing a last desperate attempt
to recover memory. If the memory is tied up inside active context
objects, we will fail to recover any memory simply by trying to unbind
the objects without first doing a wait-for-idle.

A side-effect of removing the call to shrinker_lock_uninterruptible()
from i915_gem_shrinker_oom() was that we removed an unlocked
wait-for-idle, and so lost the "natural" shrinkage of context objects.
By replacing that with a locked wait from inside i915_gem_shrink(), we
not only replace it with the ability to recover all context objects, but
do so for all i915_gem_shrink_all() callers.

References: https://bugs.freedesktop.org/show_bug.cgi?id=102936
Fixes: f2123818ffad ("drm/i915: Move dev_priv->mm.[un]bound_list to its own lock")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_gem_shrinker.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_gem_shrinker.c b/drivers/gpu/drm/i915/i915_gem_shrinker.c
index eb31f8aa5c21..e72f5543a4e9 100644
--- a/drivers/gpu/drm/i915/i915_gem_shrinker.c
+++ b/drivers/gpu/drm/i915/i915_gem_shrinker.c
@@ -162,6 +162,24 @@ i915_gem_shrink(struct drm_i915_private *dev_priv,
 	if (!shrinker_lock(dev_priv, &unlock))
 		return 0;
 
+	/*
+	 * When shrinking everything, also consider active contexts.
+	 * Active contexts are pinned until they are retired, and so can
+	 * not be simply unbound to retire and unpin their pages. To shrink
+	 * the contexts, we must wait until the gpu is idle and to be able
+	 * to shrink *all* contexts, first switch to the permanently
+	 * pinned kernel context.
+	 *
+	 * We don't care about errors here (trying to switch contexts will
+	 * need an allocation for its request etc); if we cannot switch and
+	 * wait upon the GPU, we will free as much as we can and hope to get
+	 * a second chance.
+	 */
+	if (target == -1ul && flags & I915_SHRINK_ACTIVE) {
+		i915_gem_switch_to_kernel_context(dev_priv);
+		i915_gem_wait_for_idle(dev_priv, I915_WAIT_LOCKED);
+	}
+
 	trace_i915_gem_shrink(dev_priv, target, flags);
 	i915_gem_retire_requests(dev_priv);
 
-- 
2.15.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-11-08 14:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-07 21:31 [PATCH] drm/i915: Idle the GPU before shinking everything Chris Wilson
2017-11-08  9:31 ` ✗ Fi.CI.BAT: failure for " Patchwork
2017-11-08  9:38 ` [PATCH] " Chris Wilson
2017-11-08  9:44 ` [PATCH v2] " Chris Wilson
2017-11-08 14:56   ` Joonas Lahtinen
2017-11-08 10:59 ` ✓ Fi.CI.BAT: success for drm/i915: Idle the GPU before shinking everything (rev2) Patchwork
2017-11-08 11:37 ` ✗ Fi.CI.BAT: failure " Patchwork
2017-11-08 11:57 ` ✓ Fi.CI.BAT: success " Patchwork
2017-11-08 13:06 ` ✓ Fi.CI.IGT: " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox