diff mbox series

[v2] drm/i915: Recover batch pool caches from shrinker

Message ID 20180916205723.12242-1-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show
Series [v2] drm/i915: Recover batch pool caches from shrinker | expand

Commit Message

Chris Wilson Sept. 16, 2018, 8:57 p.m. UTC
Discard all of our batch pools under mempressure to make their pages
available to the shrinker. We will quickly reacquire them when necessary
for more GPU relocations or for the command parser.

v2: Init the lists for mock_engine

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107936
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem_batch_pool.c   |  7 +++++--
 drivers/gpu/drm/i915/i915_gem_shrinker.c     | 11 +++++++++++
 drivers/gpu/drm/i915/selftests/mock_engine.c |  2 ++
 3 files changed, 18 insertions(+), 2 deletions(-)

Comments

Matthew Auld Sept. 19, 2018, 6:34 p.m. UTC | #1
On Sun, 16 Sep 2018 at 21:59, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>
> Discard all of our batch pools under mempressure to make their pages
> available to the shrinker. We will quickly reacquire them when necessary
> for more GPU relocations or for the command parser.
>
> v2: Init the lists for mock_engine
>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107936
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

What stops shrink_caches being called while we have a batch pool
object with its pages still pinned, like in the middle of
__reloc_gpu_alloc? Maybe I'm missing something...
Chris Wilson Sept. 19, 2018, 7:39 p.m. UTC | #2
Quoting Matthew Auld (2018-09-19 19:34:47)
> On Sun, 16 Sep 2018 at 21:59, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> >
> > Discard all of our batch pools under mempressure to make their pages
> > available to the shrinker. We will quickly reacquire them when necessary
> > for more GPU relocations or for the command parser.
> >
> > v2: Init the lists for mock_engine
> >
> > Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107936
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> 
> What stops shrink_caches being called while we have a batch pool
> object with its pages still pinned, like in the middle of
> __reloc_gpu_alloc? Maybe I'm missing something...

Once it is pinned for use, it is fine, it cannot be shrunk underneath
us. The problem lies in the zombie reference as we may find ourselves
without an active reference. The only way to be certain would be to
return a strong ref. That just felt like more upheaval than it was
worth (or rather I was hoping that the active-ref would be earlier).
-Chris
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_batch_pool.c b/drivers/gpu/drm/i915/i915_gem_batch_pool.c
index f3890b664e3f..b7727a404b46 100644
--- a/drivers/gpu/drm/i915/i915_gem_batch_pool.c
+++ b/drivers/gpu/drm/i915/i915_gem_batch_pool.c
@@ -131,10 +131,13 @@  i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool,
 		return obj;
 
 found:
+	list_del(&obj->batch_pool_link);
 	ret = i915_gem_object_pin_pages(obj);
-	if (ret)
+	if (ret) {
+		i915_gem_object_put(obj);
 		return ERR_PTR(ret);
+	}
 
-	list_move_tail(&obj->batch_pool_link, list);
+	list_add_tail(&obj->batch_pool_link, list);
 	return obj;
 }
diff --git a/drivers/gpu/drm/i915/i915_gem_shrinker.c b/drivers/gpu/drm/i915/i915_gem_shrinker.c
index ea90d3a0d511..610a78e2f0b1 100644
--- a/drivers/gpu/drm/i915/i915_gem_shrinker.c
+++ b/drivers/gpu/drm/i915/i915_gem_shrinker.c
@@ -117,6 +117,15 @@  static bool unsafe_drop_pages(struct drm_i915_gem_object *obj)
 	return !i915_gem_object_has_pages(obj);
 }
 
+static void shrink_caches(struct drm_i915_private *i915)
+{
+	struct intel_engine_cs *engine;
+	enum intel_engine_id id;
+
+	for_each_engine(engine, i915, id)
+		i915_gem_batch_pool_fini(&engine->batch_pool);
+}
+
 /**
  * i915_gem_shrink - Shrink buffer object caches
  * @i915: i915 device
@@ -180,6 +189,8 @@  i915_gem_shrink(struct drm_i915_private *i915,
 	trace_i915_gem_shrink(i915, target, flags);
 	i915_retire_requests(i915);
 
+	shrink_caches(i915);
+
 	/*
 	 * Unbinding of objects will require HW access; Let us not wake the
 	 * device just to recover a little memory. If absolutely necessary,
diff --git a/drivers/gpu/drm/i915/selftests/mock_engine.c b/drivers/gpu/drm/i915/selftests/mock_engine.c
index 22a73da45ad5..8fc511eb3f13 100644
--- a/drivers/gpu/drm/i915/selftests/mock_engine.c
+++ b/drivers/gpu/drm/i915/selftests/mock_engine.c
@@ -205,6 +205,8 @@  struct intel_engine_cs *mock_engine(struct drm_i915_private *i915,
 	intel_engine_init_breadcrumbs(&engine->base);
 	engine->base.breadcrumbs.mock = true; /* prevent touching HW for irqs */
 
+	intel_engine_init_batch_pool(&engine->base);
+
 	/* fake hw queue */
 	spin_lock_init(&engine->hw_lock);
 	timer_setup(&engine->hw_delay, hw_delay_complete, 0);