mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-28 22:40:24 +01:00
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>
110 lines
2.2 KiB
C
110 lines
2.2 KiB
C
/*
|
|
* Copyright © 2022 Collabora, Ltd.
|
|
*
|
|
* Based on Fossilize DB:
|
|
* Copyright © 2020 Valve Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#ifndef MESA_CACHE_DB_H
|
|
#define MESA_CACHE_DB_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#include "detect_os.h"
|
|
#include "simple_mtx.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct mesa_cache_db_file {
|
|
FILE *file;
|
|
char *path;
|
|
off_t offset;
|
|
uint64_t uuid;
|
|
};
|
|
|
|
struct mesa_cache_db {
|
|
struct hash_table_u64 *index_db;
|
|
struct mesa_cache_db_file cache;
|
|
struct mesa_cache_db_file index;
|
|
uint64_t max_cache_size;
|
|
simple_mtx_t flock_mtx;
|
|
void *mem_ctx;
|
|
uint64_t uuid;
|
|
bool alive;
|
|
};
|
|
|
|
#if DETECT_OS_WINDOWS == 0
|
|
bool
|
|
mesa_cache_db_open(struct mesa_cache_db *db, const char *cache_path);
|
|
|
|
void
|
|
mesa_cache_db_close(struct mesa_cache_db *db);
|
|
|
|
void
|
|
mesa_cache_db_set_size_limit(struct mesa_cache_db *db,
|
|
uint64_t max_cache_size);
|
|
|
|
unsigned int
|
|
mesa_cache_db_file_entry_size(void);
|
|
|
|
void *
|
|
mesa_cache_db_read_entry(struct mesa_cache_db *db,
|
|
const uint8_t *cache_key_160bit,
|
|
size_t *size);
|
|
|
|
bool
|
|
mesa_cache_db_entry_write(struct mesa_cache_db *db,
|
|
const uint8_t *cache_key_160bit,
|
|
const void *blob, size_t blob_size);
|
|
#else
|
|
static inline bool
|
|
mesa_cache_db_open(struct mesa_cache_db *db, const char *cache_path)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline void
|
|
mesa_cache_db_close(struct mesa_cache_db *db)
|
|
{
|
|
}
|
|
|
|
static inline void
|
|
mesa_cache_db_set_size_limit(struct mesa_cache_db *db,
|
|
uint64_t max_cache_size)
|
|
{
|
|
}
|
|
|
|
static inline unsigned int
|
|
mesa_cache_db_file_entry_size(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void *
|
|
mesa_cache_db_read_entry(struct mesa_cache_db *db,
|
|
const uint8_t *cache_key_160bit,
|
|
size_t *size)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline bool
|
|
mesa_cache_db_entry_write(struct mesa_cache_db *db,
|
|
const uint8_t *cache_key_160bit,
|
|
const void *blob, size_t blob_size)
|
|
{
|
|
return false;
|
|
}
|
|
#endif /* DETECT_OS_WINDOWS */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* MESA_CACHE_DB_H */
|