[PATCH 35/49] drm/i915: Mark "page-backed" dmabuf as being shrinkable

Chris Wilson chris at chris-wilson.co.uk
Fri Oct 5 14:33:28 UTC 2018


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 at chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Cc: Daniel Vetter <daniel at ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

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;
 
-- 
2.19.0



More information about the Intel-gfx-trybot mailing list