summaryrefslogtreecommitdiffstats
path: root/src/util/disk_cache.c
diff options
context:
space:
mode:
authorAlan Swanson <[email protected]>2017-03-06 16:17:31 +0000
committerTimothy Arceri <[email protected]>2017-03-15 11:15:11 +1100
commitf1e96714424f516ec3ee7a341fb10068340b0411 (patch)
tree0b7d3db44aecc4ce9b50ad9a5ba746e39bc0d6ca /src/util/disk_cache.c
parentaf09b867329bcc5d50c22c2e634f5c5deb51e184 (diff)
util/disk_cache: actually enforce cache size
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. V2: (Timothy Arceri) fix make check tests Reviewed-by: Grazvydas Ignotas <[email protected]>
Diffstat (limited to 'src/util/disk_cache.c')
-rw-r--r--src/util/disk_cache.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 931e308cd53..54134441bda 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -798,6 +798,7 @@ cache_put(void *job, int thread_index)
assert(job);
int fd = -1, fd_final = -1, err, ret;
+ unsigned i = 0;
size_t len;
char *filename = NULL, *filename_tmp = NULL;
struct disk_cache_put_job *dc_job = (struct disk_cache_put_job *) job;
@@ -853,8 +854,11 @@ cache_put(void *job, int thread_index)
* Before we do that, if the cache is too large, evict something
* else first.
*/
- if (*dc_job->cache->size + dc_job->size > dc_job->cache->max_size)
+ while ((*dc_job->cache->size + dc_job->size > dc_job->cache->max_size) &&
+ i < 8) {
evict_lru_item(dc_job->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.