drm/i915: Make object/vma allocation caches global
As our allocations are not device specific, we can move our slab caches to a global scope. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20190228102035.5857-2-chris@chris-wilson.co.uk
This commit is contained in:
@@ -30,6 +30,20 @@
|
||||
|
||||
#include <drm/drm_gem.h>
|
||||
|
||||
static struct i915_global_vma {
|
||||
struct kmem_cache *slab_vmas;
|
||||
} global;
|
||||
|
||||
struct i915_vma *i915_vma_alloc(void)
|
||||
{
|
||||
return kmem_cache_zalloc(global.slab_vmas, GFP_KERNEL);
|
||||
}
|
||||
|
||||
void i915_vma_free(struct i915_vma *vma)
|
||||
{
|
||||
return kmem_cache_free(global.slab_vmas, vma);
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_DRM_I915_ERRLOG_GEM) && IS_ENABLED(CONFIG_DRM_DEBUG_MM)
|
||||
|
||||
#include <linux/stackdepot.h>
|
||||
@@ -115,7 +129,7 @@ vma_create(struct drm_i915_gem_object *obj,
|
||||
/* The aliasing_ppgtt should never be used directly! */
|
||||
GEM_BUG_ON(vm == &vm->i915->mm.aliasing_ppgtt->vm);
|
||||
|
||||
vma = kmem_cache_zalloc(vm->i915->vmas, GFP_KERNEL);
|
||||
vma = i915_vma_alloc();
|
||||
if (vma == NULL)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
@@ -190,7 +204,7 @@ vma_create(struct drm_i915_gem_object *obj,
|
||||
cmp = i915_vma_compare(pos, vm, view);
|
||||
if (cmp == 0) {
|
||||
spin_unlock(&obj->vma.lock);
|
||||
kmem_cache_free(vm->i915->vmas, vma);
|
||||
i915_vma_free(vma);
|
||||
return pos;
|
||||
}
|
||||
|
||||
@@ -222,7 +236,7 @@ vma_create(struct drm_i915_gem_object *obj,
|
||||
return vma;
|
||||
|
||||
err_vma:
|
||||
kmem_cache_free(vm->i915->vmas, vma);
|
||||
i915_vma_free(vma);
|
||||
return ERR_PTR(-E2BIG);
|
||||
}
|
||||
|
||||
@@ -803,8 +817,6 @@ void i915_vma_reopen(struct i915_vma *vma)
|
||||
|
||||
static void __i915_vma_destroy(struct i915_vma *vma)
|
||||
{
|
||||
struct drm_i915_private *i915 = vma->vm->i915;
|
||||
|
||||
GEM_BUG_ON(vma->node.allocated);
|
||||
GEM_BUG_ON(vma->fence);
|
||||
|
||||
@@ -825,7 +837,7 @@ static void __i915_vma_destroy(struct i915_vma *vma)
|
||||
|
||||
i915_active_fini(&vma->active);
|
||||
|
||||
kmem_cache_free(i915->vmas, vma);
|
||||
i915_vma_free(vma);
|
||||
}
|
||||
|
||||
void i915_vma_destroy(struct i915_vma *vma)
|
||||
@@ -1041,3 +1053,22 @@ unpin:
|
||||
#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
|
||||
#include "selftests/i915_vma.c"
|
||||
#endif
|
||||
|
||||
int __init i915_global_vma_init(void)
|
||||
{
|
||||
global.slab_vmas = KMEM_CACHE(i915_vma, SLAB_HWCACHE_ALIGN);
|
||||
if (!global.slab_vmas)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i915_global_vma_shrink(void)
|
||||
{
|
||||
kmem_cache_shrink(global.slab_vmas);
|
||||
}
|
||||
|
||||
void i915_global_vma_exit(void)
|
||||
{
|
||||
kmem_cache_destroy(global.slab_vmas);
|
||||
}
|
||||
|
Reference in New Issue
Block a user