diff options
| author | Dmitry Osipenko <dmitry.osipenko@collabora.com> | 2024-09-20 06:31:04 +0300 |
|---|---|---|
| committer | Marge Bot <emma+marge@anholt.net> | 2024-10-25 18:06:14 +0000 |
| commit | 7b40d32187bbdd0cd8da75d4c626ea87dd14b4fb (patch) | |
| tree | 9054db0698077e18712a9b095b537c4ed283ece6 | |
| parent | 2a9378a0f97c9eddaba4dba32a24be699916f482 (diff) | |
util/mesa-db: Open DB files during access time
Open DB files when DB is accessed and close them afterwards to reduce
number of FDs used by multi-part DB cache.
Fixes: fd9f7b748e2e ("util/mesa-db: Introduce multipart mesa-db cache")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11776
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11810
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Acked-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30988>
| -rw-r--r-- | src/util/mesa_cache_db.c | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/src/util/mesa_cache_db.c b/src/util/mesa_cache_db.c index 77a89a20fa4..f7536ae4a86 100644 --- a/src/util/mesa_cache_db.c +++ b/src/util/mesa_cache_db.c @@ -83,6 +83,12 @@ static inline bool mesa_db_truncate(FILE *file, long pos) return !ftruncate(fileno(file), pos); } +static bool +mesa_db_reopen_file(struct mesa_cache_db_file *db_file); + +static void +mesa_db_close_file(struct mesa_cache_db_file *db_file); + static int mesa_db_flock(FILE *file, int op) { @@ -100,8 +106,12 @@ mesa_db_lock(struct mesa_cache_db *db) { simple_mtx_lock(&db->flock_mtx); + if (!mesa_db_reopen_file(&db->index) || + !mesa_db_reopen_file(&db->cache)) + goto close_files; + if (mesa_db_flock(db->cache.file, LOCK_EX) < 0) - goto unlock_mtx; + goto close_files; if (mesa_db_flock(db->index.file, LOCK_EX) < 0) goto unlock_cache; @@ -110,7 +120,10 @@ mesa_db_lock(struct mesa_cache_db *db) unlock_cache: mesa_db_flock(db->cache.file, LOCK_UN); -unlock_mtx: +close_files: + mesa_db_close_file(&db->index); + mesa_db_close_file(&db->cache); + simple_mtx_unlock(&db->flock_mtx); return false; @@ -121,6 +134,10 @@ mesa_db_unlock(struct mesa_cache_db *db) { mesa_db_flock(db->index.file, LOCK_UN); mesa_db_flock(db->cache.file, LOCK_UN); + + mesa_db_close_file(&db->index); + mesa_db_close_file(&db->cache); + simple_mtx_unlock(&db->flock_mtx); } @@ -495,10 +512,34 @@ mesa_db_open_file(struct mesa_cache_db_file *db_file, return true; } +static bool +mesa_db_reopen_file(struct mesa_cache_db_file *db_file) +{ + if (db_file->file) + return true; + + db_file->file = mesa_db_fopen(db_file->path); + if (!db_file->file) + return false; + + return true; +} + static void mesa_db_close_file(struct mesa_cache_db_file *db_file) { - fclose(db_file->file); + if (db_file->file) { + fclose(db_file->file); + db_file->file = NULL; + } +} + +static void +mesa_db_free_file(struct mesa_cache_db_file *db_file) +{ + if (db_file->file) + fclose(db_file->file); + free(db_file->path); } @@ -718,9 +759,9 @@ destroy_mtx: ralloc_free(db->mem_ctx); close_index: - mesa_db_close_file(&db->index); + mesa_db_free_file(&db->index); close_cache: - mesa_db_close_file(&db->cache); + mesa_db_free_file(&db->cache); return false; } @@ -754,8 +795,8 @@ mesa_cache_db_close(struct mesa_cache_db *db) db->index_entries = NULL; } - mesa_db_close_file(&db->index); - mesa_db_close_file(&db->cache); + mesa_db_free_file(&db->index); + mesa_db_free_file(&db->cache); } void |