intel: Free memory before inserting bo into cache.
authorChris Wilson <chris@chris-wilson.co.uk>
Wed, 2 Dec 2009 13:36:22 +0000 (13:36 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Wed, 2 Dec 2009 14:29:23 +0000 (14:29 +0000)
This has the unfortunate behaviour of releasing our malloc cache, but
the alternative is for X to consume a couple of gigabytes of ram and
die during testing. Fortunately the extra mallocs have little impact on
performance whereas avoiding swap and death, lots.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
intel/intel_bufmgr_gem.c

index ac7297b..571ab5c 100644 (file)
@@ -727,9 +727,6 @@ drm_intel_gem_bo_free(drm_intel_bo *bo)
        if (bo_gem->gtt_virtual)
                munmap(bo_gem->gtt_virtual, bo_gem->bo.size);
 
-       free(bo_gem->reloc_target_bo);
-       free(bo_gem->relocs);
-
        /* Close this object */
        memset(&close, 0, sizeof(close));
        close.handle = bo_gem->gem_handle;
@@ -788,6 +785,16 @@ drm_intel_gem_bo_unreference_final(drm_intel_bo *bo, time_t time)
        DBG("bo_unreference final: %d (%s)\n",
            bo_gem->gem_handle, bo_gem->name);
 
+       /* release memory associated with this object */
+       if (bo_gem->reloc_target_bo) {
+               free(bo_gem->reloc_target_bo);
+               bo_gem->reloc_target_bo = NULL;
+       }
+       if (bo_gem->relocs) {
+               free(bo_gem->relocs);
+               bo_gem->relocs = NULL;
+       }
+
        bucket = drm_intel_gem_bo_bucket_for_size(bufmgr_gem, bo->size);
        /* Put the buffer into our internal cache for reuse if we can. */
        tiling_mode = I915_TILING_NONE;