Commit 89d19b2b authored by Chris Wilson's avatar Chris Wilson
Browse files

drm/i915: Release shortlived maps of longlived objects



Some objects we map once during their construction, and then never
access their mappings again, even if they are kept around for the
duration of the driver. Keeping those pages mapped, often vmapped, is
therefore wasteful and we should release the maps as soon as we no
longer need them.

Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarMatthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200708173748.32734-3-chris@chris-wilson.co.uk
parent 59c94b9d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -394,6 +394,8 @@ static inline void i915_gem_object_unpin_map(struct drm_i915_gem_object *obj)
	i915_gem_object_unpin_pages(obj);
}

void __i915_gem_object_release_map(struct drm_i915_gem_object *obj);

void
i915_gem_object_flush_write_domain(struct drm_i915_gem_object *obj,
				   unsigned int flush_domains);
+15 −0
Original line number Diff line number Diff line
@@ -408,6 +408,21 @@ void __i915_gem_object_flush_map(struct drm_i915_gem_object *obj,
	}
}

void __i915_gem_object_release_map(struct drm_i915_gem_object *obj)
{
	GEM_BUG_ON(!obj->mm.mapping);

	/*
	 * We allow removing the mapping from underneath pinned pages!
	 *
	 * Furthermore, since this is an unsafe operation reserved only
	 * for construction time manipulation, we ignore locking prudence.
	 */
	unmap_object(obj, page_mask_bits(fetch_and_zero(&obj->mm.mapping)));

	i915_gem_object_unpin_map(obj);
}

struct scatterlist *
i915_gem_object_get_sg(struct drm_i915_gem_object *obj,
		       unsigned int n,
+1 −1
Original line number Diff line number Diff line
@@ -396,7 +396,7 @@ int gen7_setup_clear_gpr_bb(struct intel_engine_cs * const engine,
	emit_batch(vma, memset(batch, 0, bv.max_size), &bv);

	i915_gem_object_flush_map(vma->obj);
	i915_gem_object_unpin_map(vma->obj);
	__i915_gem_object_release_map(vma->obj);

	return 0;
}
+1 −1
Original line number Diff line number Diff line
@@ -3937,7 +3937,7 @@ static int intel_init_workaround_bb(struct intel_engine_cs *engine)
	GEM_BUG_ON(batch_ptr - batch > CTX_WA_BB_OBJ_SIZE);

	__i915_gem_object_flush_map(wa_ctx->vma->obj, 0, batch_ptr - batch);
	i915_gem_object_unpin_map(wa_ctx->vma->obj);
	__i915_gem_object_release_map(wa_ctx->vma->obj);
	if (ret)
		lrc_destroy_wa_ctx(engine);

+1 −1
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ static int render_state_setup(struct intel_renderstate *so,
	ret = 0;
out:
	__i915_gem_object_flush_map(so->vma->obj, 0, i * sizeof(u32));
	i915_gem_object_unpin_map(so->vma->obj);
	__i915_gem_object_release_map(so->vma->obj);
	return ret;
}

Loading