mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-07 06:30:11 +01:00
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: fd9f7b748e ("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>
This commit is contained in:
parent
2a9378a0f9
commit
7b40d32187
1 changed files with 48 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue