drm/i915: Allow shrinking of userptr objects once again
authorTvrtko Ursulin <tvrtko.ursulin@intel.com>
Tue, 1 Nov 2016 14:44:10 +0000 (14:44 +0000)
committerTvrtko Ursulin <tvrtko.ursulin@intel.com>
Tue, 1 Nov 2016 16:35:26 +0000 (16:35 +0000)
Commit 1bec9b0bda3d ("drm/i915/shrinker: Only shmemfs objects
are backed by swap") stopped considering the userptr objects
in shrinker callbacks.

Restore that so idle userptr objects can be discarded in order
to free up memory.

One change further to what was introduced in 1bec9b0bda3d is
to start considering userptr objects in oom but that should
also be a correct thing to do.

v2: Introduce I915_GEM_OBJECT_IS_SHRINKABLE. (Chris Wilson)

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Fixes: 1bec9b0bda3d ("drm/i915/shrinker: Only shmemfs objects are backed by swap")
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Mika Kuoppala <mika.kuoppala@intel.com>
Cc: <stable@vger.kernel.org>
Link: http://patchwork.freedesktop.org/patch/msgid/1478011450-6634-1-git-send-email-tvrtko.ursulin@linux.intel.com
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/i915_gem_internal.c
drivers/gpu/drm/i915/i915_gem_shrinker.c
drivers/gpu/drm/i915/i915_gem_userptr.c

index b8e72cdcb713ab76f7797122cdd7abb67104ede9..f20e24baf95c610dcf88eddc0c6cb81122db24f7 100644 (file)
@@ -2181,6 +2181,7 @@ enum hdmi_force_audio {
 struct drm_i915_gem_object_ops {
        unsigned int flags;
 #define I915_GEM_OBJECT_HAS_STRUCT_PAGE 0x1
+#define I915_GEM_OBJECT_IS_SHRINKABLE   0x2
 
        /* Interface between the GEM object and its backing storage.
         * get_pages() is called once prior to the use of the associated set
@@ -2429,6 +2430,12 @@ i915_gem_object_has_struct_page(const struct drm_i915_gem_object *obj)
        return obj->ops->flags & I915_GEM_OBJECT_HAS_STRUCT_PAGE;
 }
 
+static inline bool
+i915_gem_object_is_shrinkable(const struct drm_i915_gem_object *obj)
+{
+       return obj->ops->flags & I915_GEM_OBJECT_IS_SHRINKABLE;
+}
+
 static inline bool
 i915_gem_object_is_active(const struct drm_i915_gem_object *obj)
 {
index 207b8ef851365180c232517cd3d5b1a87054575f..a97fdfa806632f6191b1b0b5ca4fe94b5465fecb 100644 (file)
@@ -4146,7 +4146,8 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,
 }
 
 static const struct drm_i915_gem_object_ops i915_gem_object_ops = {
-       .flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE,
+       .flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE |
+                I915_GEM_OBJECT_IS_SHRINKABLE,
        .get_pages = i915_gem_object_get_pages_gtt,
        .put_pages = i915_gem_object_put_pages_gtt,
 };
index 1b0607a44a9ae128b07bc29dbf6b6ba01282bb9f..4b3ff3e5b911167557880228d5da44bb3d2616bf 100644 (file)
@@ -132,7 +132,8 @@ static void i915_gem_object_put_pages_internal(struct drm_i915_gem_object *obj,
 }
 
 static const struct drm_i915_gem_object_ops i915_gem_object_internal_ops = {
-       .flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE,
+       .flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE |
+                I915_GEM_OBJECT_IS_SHRINKABLE,
        .get_pages = i915_gem_object_get_pages_internal,
        .put_pages = i915_gem_object_put_pages_internal,
 };
index f988652f1e26c5de87407272c752abd4f6d5e65a..87dd27d5146c2ea810f332eef7877e9c27d4094d 100644 (file)
@@ -83,8 +83,8 @@ static bool can_release_pages(struct drm_i915_gem_object *obj)
        if (!obj->mm.pages)
                return false;
 
-       /* Only shmemfs objects are backed by swap */
-       if (!obj->base.filp)
+       /* Consider only shrinkable ojects. */
+       if (!i915_gem_object_is_shrinkable(obj))
                return false;
 
        /* Only report true if by unbinding the object and putting its pages
index 9bf44b5bca101448d2e71bd558cf464db27b4caa..64261639f54727464d137fd50ae0eaa199c32761 100644 (file)
@@ -707,7 +707,8 @@ i915_gem_userptr_dmabuf_export(struct drm_i915_gem_object *obj)
 }
 
 static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = {
-       .flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE,
+       .flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE |
+                I915_GEM_OBJECT_IS_SHRINKABLE,
        .get_pages = i915_gem_userptr_get_pages,
        .put_pages = i915_gem_userptr_put_pages,
        .dmabuf_export = i915_gem_userptr_dmabuf_export,