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

Submitted by Alan Swanson on March 6, 2017, 4:17 p.m.

Details

Message ID 20170306161732.12135-2-reiver@improbability.net
State New
Headers show
Series "Series without cover letter" ( rev: 7 6 5 4 3 2 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Alan Swanson March 6, 2017, 4:17 p.m.
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(-)

Patch hide | download patch | download mbox

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.

Comments

This seems to break "make check", so needs to update tests I guess.

GraÅžvydas

On Mon, Mar 6, 2017 at 6:17 PM, Alan Swanson <reiver@improbability.net> wrote:
> 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
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev