diff mbox series

[2/2] drm/i915: Mark "page-backed" dmabuf as being shrinkable

Message ID 20180807181101.14696-2-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show
Series [1/2] drm/i915/selftests: Exercise invalidation of dmabuf import from shrinker | expand

Commit Message

Chris Wilson Aug. 7, 2018, 6:11 p.m. UTC
We currently assume that if we import a dmabuf, it is not backed by
pages (we assume it exists in video memory on a foriegn device).
However, some dmabuf will be backed by ordinary struct pages (e.g. vgem)
and as such they may be shrinkable from direct reclaim. Since commit
09ea0dfbf972 ("dma-buf: make map_atomic and map function pointers
optional") drivers do not need to supply a kmap() vfunc if they have no
convenient access to the physical backing page. We can use that
information to differentiate dmabuf that are likely to be backed by
struct page and so suitable for including in our shrinkable set.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
index 82e2ca17a441..8bc4030059f8 100644
--- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
@@ -269,7 +269,15 @@  static void i915_gem_object_put_pages_dmabuf(struct drm_i915_gem_object *obj,
 				 DMA_BIDIRECTIONAL);
 }
 
-static const struct drm_i915_gem_object_ops i915_gem_object_dmabuf_ops = {
+static const struct drm_i915_gem_object_ops
+i915_gem_object_dmabuf_ops = {
+	.get_pages = i915_gem_object_get_pages_dmabuf,
+	.put_pages = i915_gem_object_put_pages_dmabuf,
+};
+
+static const struct drm_i915_gem_object_ops
+i915_gem_object_dmabuf_ops__shrinkable = {
+	.flags = I915_GEM_OBJECT_IS_SHRINKABLE,
 	.get_pages = i915_gem_object_get_pages_dmabuf,
 	.put_pages = i915_gem_object_put_pages_dmabuf,
 };
@@ -308,7 +316,10 @@  struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
 	}
 
 	drm_gem_private_object_init(dev, &obj->base, dma_buf->size);
-	i915_gem_object_init(obj, &i915_gem_object_dmabuf_ops);
+	i915_gem_object_init(obj,
+			     dma_buf->ops->map ?
+			     &i915_gem_object_dmabuf_ops__shrinkable :
+			     &i915_gem_object_dmabuf_ops);
 	obj->base.import_attach = attach;
 	obj->resv = dma_buf->resv;