util/u_queue: track job size and limit the size of queue growth

When both UTIL_QUEUE_INIT_RESIZE_IF_FULL and
UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY are set, we can get into a
situation where the queue never executes and grows to a huge size
due to all other threads being busy.

This is the case with the shader cache when attempting to compile a
huge number of shaders up front. If all threads are busy compiling
shaders the cache queues memory use can climb into the many GBs
very fast.

The use of these two flags with the shader cache is intended to
allow shaders compiled at runtime to be compiled as fast as possible.
To avoid huge memory use but still allow the queue to perform
optimally in the run time compilation case, we now add the ability
to track memory consumed by the jobs in the queue and limit it to
a hardcoded 256MB which should be more than enough.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
This commit is contained in:
Timothy Arceri
2019-09-03 13:05:08 +10:00
parent a2ee29c3da
commit 896885025f
9 changed files with 28 additions and 13 deletions
+4 -1
View File
@@ -193,6 +193,7 @@ typedef void (*util_queue_execute_func)(void *job, int thread_index);
struct util_queue_job {
void *job;
size_t job_size;
struct util_queue_fence *fence;
util_queue_execute_func execute;
util_queue_execute_func cleanup;
@@ -212,6 +213,7 @@ struct util_queue {
unsigned num_threads; /* decreasing this number will terminate threads */
int max_jobs;
int write_idx, read_idx; /* ring buffer pointers */
size_t total_jobs_size; /* memory use of all jobs in the queue */
struct util_queue_job *jobs;
/* for cleanup at exit(), protected by exit_mutex */
@@ -230,7 +232,8 @@ void util_queue_add_job(struct util_queue *queue,
void *job,
struct util_queue_fence *fence,
util_queue_execute_func execute,
util_queue_execute_func cleanup);
util_queue_execute_func cleanup,
const size_t job_size);
void util_queue_drop_job(struct util_queue *queue,
struct util_queue_fence *fence);