[Mesa-dev] [PATCH 4/4] i965/drm: Purge the bucket when its cached buffer is evicted

James Xiong james.xiong at intel.com
Tue May 1 23:25:32 UTC 2018


From: "Xiong, James" <james.xiong at intel.com>

When one of cached buffers is found to be evicted by kernel,
most likely the buffers freed earlier than this buffer are
gone too, go through the cached list in the bucket and purge.

Signed-off-by: Xiong, James <james.xiong at intel.com>
---
 src/mesa/drivers/dri/i965/brw_bufmgr.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.c b/src/mesa/drivers/dri/i965/brw_bufmgr.c
index 5235aa6..9f2e566 100644
--- a/src/mesa/drivers/dri/i965/brw_bufmgr.c
+++ b/src/mesa/drivers/dri/i965/brw_bufmgr.c
@@ -248,17 +248,20 @@ brw_bo_madvise(struct brw_bo *bo, int state)
    return madv.retained;
 }
 
-/* drop the oldest entries that have been purged by the kernel */
+/* drop the entries that are older than the given time */
 static void
 brw_bo_cache_purge_bucket(struct brw_bufmgr *bufmgr,
-                          struct bo_cache_bucket *bucket)
+                          struct bo_cache_bucket *bucket,
+                          time_t time)
 {
    list_for_each_entry_safe(struct brw_bo, bo, &bucket->head, head) {
-      if (brw_bo_madvise(bo, I915_MADV_DONTNEED))
+      if (bo->free_time >= time) {
+         brw_bo_madvise(bo, I915_MADV_DONTNEED);
+         list_del(&bo->head);
+         bo_free(bo);
+      } else {
          break;
-
-      list_del(&bo->head);
-      bo_free(bo);
+      }
    }
 }
 
@@ -319,8 +322,8 @@ retry:
 
       if (bo) {
          if (!brw_bo_madvise(bo, I915_MADV_WILLNEED)) {
+            brw_bo_cache_purge_bucket(bufmgr, bucket, bo->free_time);
             bo_free(bo);
-            brw_bo_cache_purge_bucket(bufmgr, bucket);
             return NULL;
          }
 
-- 
2.7.4



More information about the mesa-dev mailing list