summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2012-01-01 14:32:48 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2012-01-01 15:24:46 +0000
commit1a6c16a24cb74f82df9757c034c50f2cf141523f (patch)
tree1fce713bd6a1ed3bbbdef2163c8b70ce9bbc4222
parentf008a2a90c632d843f07846426f6d14af728c13b (diff)
sna: Keep a freelist of buffers
As reallocation of bo is the most frequent cause of malloc/free. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--src/sna/kgem.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/sna/kgem.c b/src/sna/kgem.c
index 969036ec..7424a8a9 100644
--- a/src/sna/kgem.c
+++ b/src/sna/kgem.c
@@ -108,6 +108,7 @@ struct kgem_partial_bo {
uint32_t write : 1;
};
+static struct kgem_bo *__kgem_freed_bo;
static struct drm_i915_gem_exec_object2 _kgem_dummy_exec;
static void kgem_sna_reset(struct kgem *kgem)
@@ -381,9 +382,14 @@ static struct kgem_bo *__kgem_bo_alloc(int handle, int size)
{
struct kgem_bo *bo;
- bo = malloc(sizeof(*bo));
- if (bo == NULL)
- return NULL;
+ if (__kgem_freed_bo) {
+ bo = __kgem_freed_bo;
+ __kgem_freed_bo = *(struct kgem_bo **)bo;
+ } else {
+ bo = malloc(sizeof(*bo));
+ if (bo == NULL)
+ return NULL;
+ }
return __kgem_bo_init(bo, handle, size);
}
@@ -747,7 +753,12 @@ static void kgem_bo_free(struct kgem *kgem, struct kgem_bo *bo)
_list_del(&bo->list);
_list_del(&bo->request);
gem_close(kgem->fd, bo->handle);
- free(bo);
+
+ if (!bo->io) {
+ *(struct kgem_bo **)bo = __kgem_freed_bo;
+ __kgem_freed_bo = bo;
+ } else
+ free(bo);
}
static bool is_mmaped_buffer(struct kgem_partial_bo *bo)