util/mesa-db: Don't account header size

In order to ease writing mesa-db eviction unit tests, stop accounting
mesa-db cache file header size during checking whether cache file reached
the size limit. This change ensures that older unit tests will keep working
whenever cache header version/size will change.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20256>
This commit is contained in:
Dmitry Osipenko
2022-10-24 13:13:29 +03:00
committed by Marge Bot
parent 51869405bc
commit f68db0da4c

View File

@@ -723,6 +723,19 @@ fail:
return NULL;
}
static bool
mesa_cache_db_has_space_locked(struct mesa_cache_db *db, size_t blob_size)
{
return ftell(db->cache.file) + blob_file_size(blob_size) -
sizeof(struct mesa_db_file_header) <= db->max_cache_size;
}
static size_t
mesa_cache_db_eviction_size(struct mesa_cache_db *db)
{
return db->max_cache_size / 2 - sizeof(struct mesa_db_file_header);
}
bool
mesa_cache_db_entry_write(struct mesa_cache_db *db,
const uint8_t *cache_key_160bit,
@@ -745,8 +758,8 @@ mesa_cache_db_entry_write(struct mesa_cache_db *db,
if (!mesa_db_seek_end(db->cache.file))
goto fail_fatal;
if (ftell(db->cache.file) + blob_file_size(blob_size) > db->max_cache_size) {
if (!mesa_db_compact(db, MAX2(blob_size, db->max_cache_size / 2)))
if (!mesa_cache_db_has_space_locked(db, blob_size)) {
if (!mesa_db_compact(db, MAX2(blob_size, mesa_cache_db_eviction_size(db))))
goto fail_fatal;
} else {
if (!mesa_db_update_index(db))