From f68db0da4cf2b3ef82ccdf3893f5d43c51770ac7 Mon Sep 17 00:00:00 2001 From: Dmitry Osipenko Date: Mon, 24 Oct 2022 13:13:29 +0300 Subject: [PATCH] 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 Signed-off-by: Dmitry Osipenko Part-of: --- src/util/mesa_cache_db.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/util/mesa_cache_db.c b/src/util/mesa_cache_db.c index 1619ad239f8..2da025b40c5 100644 --- a/src/util/mesa_cache_db.c +++ b/src/util/mesa_cache_db.c @@ -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))