[Mesa-dev] [PATCH 2/3] util/disk_cache: actually enforce cache size

Alan Swanson reiver at improbability.net
Mon Mar 6 16:17:31 UTC 2017


Currently only a one in one out eviction so if at max_size and
cache files were to constantly increase in size then so would the
cache. Restrict to limit of 8 evictions per new cache entry.
---
 src/util/disk_cache.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 28f8ea4054..d2ae69911a 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -724,6 +724,7 @@ disk_cache_put(struct disk_cache *cache,
           size_t size)
 {
    int fd = -1, fd_final = -1, err, ret;
+   unsigned i = 0;
    size_t len;
    char *filename = NULL, *filename_tmp = NULL;
 
@@ -778,8 +779,10 @@ disk_cache_put(struct disk_cache *cache,
     * Before we do that, if the cache is too large, evict something
     * else first.
     */
-   if (*cache->size + size > cache->max_size)
+   while ((*cache->size + size > cache->max_size) && i < 8) {
       evict_lru_item(cache);
+      i++;
+   }
 
    /* Create CRC of the data and store at the start of the file. We will
     * read this when restoring the cache and use it to check for corruption.
-- 
2.11.1



More information about the mesa-dev mailing list