From: Alan Swanson <[email protected]> Select higher of current 1G default or 10% of filesystem where cache is located.
Acked-by: Timothy Arceri <[email protected]> --- src/util/disk_cache.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index 7fc35f1..9929701 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -24,34 +24,36 @@ #ifdef ENABLE_SHADER_CACHE #include <ctype.h> #include <ftw.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <sys/file.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/statvfs.h> #include <sys/mman.h> #include <unistd.h> #include <fcntl.h> #include <pwd.h> #include <errno.h> #include <dirent.h> #include "zlib.h" #include "util/crc32.h" #include "util/u_atomic.h" #include "util/u_queue.h" #include "util/mesa-sha1.h" #include "util/ralloc.h" #include "main/errors.h" +#include "util/macros.h" #include "disk_cache.h" /* Number of bits to mask off from a cache key to get an index. */ #define CACHE_INDEX_KEY_BITS 16 /* Mask for computing an index from a key. */ #define CACHE_INDEX_KEY_MASK ((1 << CACHE_INDEX_KEY_BITS) - 1) /* The number of keys that can be stored in the index. */ @@ -227,20 +229,21 @@ create_mesa_cache_dir(void *mem_ctx, const char *path, const char *timestamp, struct disk_cache * disk_cache_create(const char *gpu_name, const char *timestamp) { void *local; struct disk_cache *cache = NULL; char *path, *max_size_str; uint64_t max_size; int fd = -1; struct stat sb; + struct statvfs vfs = { 0 }; size_t size; /* If running as a users other than the real user disable cache */ if (geteuid() != getuid()) return NULL; /* A ralloc context for transient data during this invocation. */ local = ralloc_context(NULL); if (local == NULL) goto fail; @@ -388,23 +391,25 @@ disk_cache_create(const char *gpu_name, const char *timestamp) case '\0': case 'G': case 'g': default: max_size *= 1024*1024*1024; break; } } } - /* Default to 1GB for maximum cache size. */ - if (max_size == 0) - max_size = 1024*1024*1024; + /* Default to 1GB or 10% of filesystem for maximum cache size. */ + if (max_size == 0) { + statvfs(path, &vfs); + max_size = MAX2(1024*1024*1024, vfs.f_blocks * vfs.f_bsize / 10); + } cache->max_size = max_size; /* A limit of 32 jobs was choosen as observations of Deus Ex start-up times * showed that we reached at most 11 jobs on an Intel i5-6400 [email protected] * (a fairly modist desktop CPU). 1 thread was choosen because we don't * really care about getting things to disk quickly just that it's not * blocking other tasks. */ util_queue_init(&cache->cache_queue, "disk_cache", 32, 1); -- 2.9.3 _______________________________________________ mesa-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-dev
