[Mesa-dev] [PATCH 1/2] i965: Put freed and idle buffers to the head of the free list

Chris Wilson chris at chris-wilson.co.uk
Fri Oct 20 13:10:35 UTC 2017

We treat our free list as a rough bidirectional MRU, at the tail we have
active buffers to be reallocated for rendering, and at the head we have
the inactive buffers that we can reallocate for use by the CPU. At both
ends we want the most recently used of each category to limit RSS upon

At the time of freeing, we can inspect the busyness of the buffer to
decide if we should place it at the tail (for reuse of active buffers)
or head (for reuse of inactive buffers).

The question comes at the middle, what should we do? If we attempt to
allocate from the tail for an active buffer, but it is already idle,
should we prefer to reuse that or the mru idle from the head? Since we
have no immediate means for ranking the last access of the pair, we just
continue to use the one to hand.

Cc: Kenneth Graunke <kenneth at whitecape.org>
 src/mesa/drivers/dri/i965/brw_bufmgr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.c b/src/mesa/drivers/dri/i965/brw_bufmgr.c
index 17036b53bc..19c9ba2fa5 100644
--- a/src/mesa/drivers/dri/i965/brw_bufmgr.c
+++ b/src/mesa/drivers/dri/i965/brw_bufmgr.c
@@ -633,7 +633,10 @@ bo_unreference_final(struct brw_bo *bo, time_t time)
       bo->name = NULL;
       bo->kflags = 0;
-      list_addtail(&bo->head, &bucket->head);
+      if (brw_bo_busy(bo))
+         list_addtail(&bo->head, &bucket->head);
+      else
+         list_add(&bo->head, &bucket->head);
    } else {

More information about the mesa-dev mailing list