@@ -684,22 +684,20 @@ drm_intel_gem_bo_madvise(drm_intel_bo *bo, int madv)
madv);
}
-/* drop the oldest entries that have been purged by the kernel */
+/* drop the entries that are older than the given time */
static void
drm_intel_gem_bo_cache_purge_bucket(drm_intel_bufmgr_gem *bufmgr_gem,
- struct drm_intel_gem_bo_bucket *bucket)
+ struct drm_intel_gem_bo_bucket *bucket,
+ time_t time)
{
- while (!DRMLISTEMPTY(&bucket->head)) {
- drm_intel_bo_gem *bo_gem;
-
- bo_gem = DRMLISTENTRY(drm_intel_bo_gem,
- bucket->head.next, head);
- if (drm_intel_gem_bo_madvise_internal
- (bufmgr_gem, bo_gem, I915_MADV_DONTNEED))
- break;
-
- DRMLISTDEL(&bo_gem->head);
- drm_intel_gem_bo_free(&bo_gem->bo);
+ drm_intel_bo_gem *bo_gem, *temp;
+ DRMLISTFOREACHENTRYSAFE(bo_gem, temp, &bucket->head, head) {
+ if (bo_gem->free_time >= time) {
+ drm_intel_gem_bo_madvise_internal
+ (bufmgr_gem, bo_gem, I915_MADV_DONTNEED);
+ DRMLISTDEL(&bo_gem->head);
+ drm_intel_gem_bo_free(&bo_gem->bo);
+ }
}
}
@@ -753,9 +751,10 @@ retry:
if (bo_gem) {
if (!drm_intel_gem_bo_madvise_internal
(bufmgr_gem, bo_gem, I915_MADV_WILLNEED)) {
- drm_intel_gem_bo_free(&bo_gem->bo);
drm_intel_gem_bo_cache_purge_bucket(bufmgr_gem,
- bucket);
+ bucket,
+ bo_gem->free_time);
+ drm_intel_gem_bo_free(&bo_gem->bo);
return NULL;
}