drm/i915: Move stale context reaping to common i915_gem_context_create
authorChris Wilson <chris@chris-wilson.co.uk>
Wed, 5 Jul 2017 14:26:32 +0000 (15:26 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 6 Jul 2017 10:50:52 +0000 (11:50 +0100)
We need to reap the stale contexts for all new contexts, be they created
by user in i915_gem_context_ioctl or from opening a new file in
i915_gem_context_open. Both paths may be called very frequently
accumulating many stale contexts before any worker has a chance to run
and free their memory.

Fixes: 1acfc104cdf8 ("drm/i915: Enable rcu-only context lookups")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170705142634.18554-2-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/i915_gem_context.c

index 98d2ce9..c58a95c 100644 (file)
@@ -383,6 +383,10 @@ i915_gem_create_context(struct drm_i915_private *dev_priv,
 
        lockdep_assert_held(&dev_priv->drm.struct_mutex);
 
+       /* Reap stale contexts */
+       i915_gem_retire_requests(dev_priv);
+       contexts_free(dev_priv);
+
        ctx = __create_hw_context(dev_priv, file_priv);
        if (IS_ERR(ctx))
                return ctx;
@@ -989,10 +993,6 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
        if (ret)
                return ret;
 
-       /* Reap stale contexts */
-       i915_gem_retire_requests(dev_priv);
-       contexts_free(dev_priv);
-
        ctx = i915_gem_create_context(dev_priv, file_priv);
        mutex_unlock(&dev->struct_mutex);
        if (IS_ERR(ctx))