[Mesa-dev] [PATCH 3/7] glsl: Add initial functions to implement an on-disk cache
Tapani Pälli
tapani.palli at intel.com
Wed Feb 4 22:03:08 PST 2015
Hi;
On 02/04/2015 11:52 PM, Carl Worth wrote:
> From: Kristian Høgsberg <krh at bitplanet.net>
>
> This code provides for an on-disk cache of objects. Objects are stored
> and retrieved (in ~/.cache/mesa) via names that are arbitrary 20-byte
> sequences, (intended to be SHA-1 hashes of something identifying for
> the content).
>
> The cache is limited to a maximum number of entries (1024 in this
> patch), and uses random replacement. These attributes are managed via
What would you think about changing this to use some defined maximum
size (in MB)? I think for the user size is what matters and it could be
a configurable option, number of items seems a bit vague and hard to
predict (?)
8<
> +uint8_t *
> +cache_get(struct program_cache *cache, cache_key key, size_t *size)
> +{
> + int fd, ret, len;
> + struct stat sb;
> + char filename[256], *data;
> +
> + if (size)
> + *size = 0;
> +
> + if (!cache_has(cache, key))
> + return NULL;
> +
> + get_cache_file(cache, filename, sizeof filename, key);
> +
> + fd = open(filename, O_RDONLY | O_CLOEXEC);
> + if (fd == -1)
> + return NULL;
> +
> + if (fstat(fd, &sb) == -1) {
> + close(fd);
> + return NULL;
> + }
> +
> + data = (char *) malloc(sb.st_size);
> + if (data == NULL) {
> + close(fd);
> + return NULL;
> + }
Will there be some further verification here if the file contents are
what is expected or is this done in higher level where cache is called?
// Tapani
More information about the mesa-dev
mailing list