Commit Graph

18 Commits

Author SHA1 Message Date
Eric Engestrom 4a14ba6fce disk_cache: add env var to show stats
Signed-off-by: Eric Engestrom <eric@igalia.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Tested-by: Chris Healy <healych@amazon.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19644>
2022-11-12 03:04:35 +00:00
Dmitry Osipenko 32211788d0 util/disk_cache: Add new mesa-db cache type
Introduce new cache type, the Mesa-DB. This is a single-file read/write
cache that is based on the read-only Fossilize DB cache. Mesa-DB supports
cache size capping. It's a much more efficient cache than the multi-file
cache because Mesa-DB doesn't have the inode overhead. The plan is to make
Mesa-DB the default cache implementation once it will be deemed as stable
and well tested. For now users have to set the new MESA_DISK_CACHE_DATABASE
environment variable in order to active the Mesa-DB cache.

Mesa-DB cache is resilient to corrupted cache files and doesn't require
maintenance from users and developers. The size capping is implemented
by evicting least recently used cache items and compacting the cache
database files with the evicted entries. In order to prevent frequent
compaction of the cache, at minimum a half of cache is evicted when cache
is full.

Acked-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16888>
2022-08-04 17:52:49 +00:00
Dmitry Osipenko f64f74b8f2 util/disk_cache: Make disk_cache_os.h usable by C++ code
The cache tests are written in C++ and the upcoming new Mese-DB cache
tests will need to include disk_cache_os.h that misses extern "C"
modifier required by C++ linkage. Add the modifier.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16888>
2022-08-04 17:52:49 +00:00
Dmitry Osipenko 517e523a2a util/disk_cache: Move struct cache_entry_file_data to the disk_cache_os.h
Relocate struct cache_entry_file_data to the header file, making it
accessible to the cache testing code. This is a preparatory step towards
addition of the new Mesa-DB cache type.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16888>
2022-08-04 17:52:49 +00:00
Dmitry Osipenko d86335dd49 util/disk_cache: Append to disk_cache_load_cache_index() with _foz
The disk_cache_load_cache_index() is solely about the foz-db cache and
we're going to add the new cache type. Append the function name with
_foz postfix to improve the naming, making clear what that function is
about.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16888>
2022-08-04 17:52:49 +00:00
Dmitry Osipenko 2a9b4ad177 util/disk_cache: Add option to disable compression
The shader cache files produced by multi-file cache have a minimum size
limitation imposed by filesystem, usually it's 4KB. In order to make
cache tests suitable for a single file caches, we need to bypass the data
compression, making size of written out data determined for the eviction
testing.

The disk_cache_create() now checks whether driver_id name is set to
"make_check_uncompressed" in order to disable cache data compression.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16888>
2022-08-04 17:52:49 +00:00
Timothy Arceri 9d1ef1595c util/disk_cache: make MESA_DISK_CACHE_READ_ONLY_FOZ_DBS a relative path
Rather than passing in full paths this changes things so that we can
just pass in filenames relative to the current cache directory.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9279>
2021-03-04 04:07:46 +00:00
Timothy Arceri 644fcd9486 util/disk_cache: make use of single file cache when env var set
When the MESA_DISK_CACHE_SINGLE_FILE environment variable is set
we make use of the new single file shader cache implementation.

The new cache uses the following directory structure based on the
first defined name as follows:

 $MESA_GLSL_CACHE_DIR/driver_id/gpu_name/foz_cache.foz
 $MESA_GLSL_CACHE_DIR/driver_id/gpu_name/foz_cache_idx.foz

 $XDG_CACHE_HOME/mesa_shader_cache_sf/driver_id/gpu_name/foz_cache.foz
 $XDG_CACHE_HOME/mesa_shader_cache_sf/driver_id/gpu_name/foz_cache_idx.foz

 <pwd.pw_dir>/.cache/mesa_shader_cache_sf/driver_id/gpu_name/foz_cache.foz
 <pwd.pw_dir>/.cache/mesa_shader_cache_sf/driver_id/gpu_name/foz_cache_idx.foz

Where foz_cache_idx.foz is a database of offsets pointing to the location of
the shader cache entries in foz_cache.foz

This initial implementation doesn't have any max cache size handling and is
initially intended to be use by applications such as steam that will handle
cache management for us.

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7725>
2021-02-21 02:50:45 +00:00
Timothy Arceri 48d7c4e0f3 util/disk_cache: do crc32 check on compressed data for ZSTD
This will be faster and avoids checking for errors with the
compression implementation which we shouldn't need to do. Instead
we trust the compression library does the correct thing and simply
error check the data loaded from disk.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7725>
2021-02-21 02:50:45 +00:00
Timothy Arceri 367ac07efc disk_cache: move cache item loading code into disk_cache_load_item() helper
This should be helpful if someone chooses to implement cache support on
windows. Also providing this greater level of abstraction makes it easier
to implement alterative cache layouts in future.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
2020-09-11 06:03:58 +00:00
Timothy Arceri 8598dc1a75 disk_cache: add new OS specific helper disk_cache_evict_item()
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
2020-09-11 06:03:58 +00:00
Timothy Arceri 7893dc405c disk_cache: move get_cache_file() to an OS specific helper
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
2020-09-11 06:03:58 +00:00
Timothy Arceri 593ef166ae disk_cache: create new helper for writing cache items to disk
This pulls out the cache item writing code from cache_put() into
a new helper. In this patch we also move various functions called
by this code into the new disk_cache_os.c file.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
2020-09-11 06:03:58 +00:00
Timothy Arceri b4a3a80403 disk_cache: move evict_lru_item() to an OS specific helper
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
2020-09-11 06:03:58 +00:00
Timothy Arceri e1236470dc disk_cache: move munmap into an OS specific helper
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
2020-09-11 06:03:58 +00:00
Timothy Arceri 889356e731 disk_cache: move index mmap into OS specific helper
This will make windows support easier to add in future.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
2020-09-11 06:03:58 +00:00
Timothy Arceri 62c4339118 disk_cache: add disk_cache_enabled() helper
This will make windows support easier to add in future.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
2020-09-11 06:03:58 +00:00
Timothy Arceri 4339ecde35 disk_cache: move cache dir generation into OS specific helper file
This will make windows support easier to add in future. To avoid code
churn this temporarily duplicates the mkdir_if_needed() function, we
will delete the duplicate in a following patch.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
2020-09-11 06:03:58 +00:00