[master] f44514a24 task: Add a TASK_QUEUE_RESERVE macro

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Aug 29 13:42:07 UTC 2022


commit f44514a2490433f3e2ea403405730418dc5e2bb0
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Jul 18 17:11:04 2022 +0200

    task: Add a TASK_QUEUE_RESERVE macro
    
    The new macro is added to better reflect operations that cater to the
    thread reserve. It also enables the allocation the right number of
    reserve heads in struct pool, instead of having one for each priority.
    It grants the possibility of priority classes so low that they wouldn't
    be eligible to queuing, without wasting space with needless queue heads.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 78e4ecee1..805612d3e 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -206,7 +206,7 @@ struct pool_task {
  * TASK_QUEUE_RUSH is req's returning from waiting list
  *
  * NOTE: When changing the number of classes, update places marked with
- * TASK_QUEUE__END in mgt_pool.c
+ * TASK_QUEUE_RESERVE in params.h
  */
 enum task_prio {
 	TASK_QUEUE_BO,
@@ -218,6 +218,7 @@ enum task_prio {
 };
 
 #define TASK_QUEUE_HIGHEST_PRIORITY TASK_QUEUE_BO
+#define TASK_QUEUE_RESERVE TASK_QUEUE__END
 #define TASK_QUEUE_LIMITED(prio) \
 	(prio == TASK_QUEUE_REQ || prio == TASK_QUEUE_STR)
 
diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index 6d854c127..a71e0a770 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -150,7 +150,7 @@ pool_mkpool(unsigned pool_no)
 
 	VTAILQ_INIT(&pp->idle_queue);
 	VTAILQ_INIT(&pp->poolsocks);
-	for (i = 0; i < TASK_QUEUE__END; i++)
+	for (i = 0; i < TASK_QUEUE_RESERVE; i++)
 		VTAILQ_INIT(&pp->queues[i]);
 	AZ(pthread_cond_init(&pp->herder_cond, NULL));
 	AZ(pthread_create(&pp->herder_thr, NULL, pool_herder, pp));
diff --git a/bin/varnishd/cache/cache_pool.h b/bin/varnishd/cache/cache_pool.h
index 04a026e61..207e275b1 100644
--- a/bin/varnishd/cache/cache_pool.h
+++ b/bin/varnishd/cache/cache_pool.h
@@ -48,7 +48,7 @@ struct pool {
 	struct lock			mtx;
 	unsigned			nidle;
 	struct taskhead			idle_queue;
-	struct taskhead			queues[TASK_QUEUE__END];
+	struct taskhead			queues[TASK_QUEUE_RESERVE];
 	unsigned			nthr;
 	unsigned			lqueue;
 	uintmax_t			sdropped;
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index ca09c4f73..9bbd8f3f7 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -216,8 +216,8 @@ pool_reserve(void)
 		if (cache_param->wthread_reserve < lim)
 			lim = cache_param->wthread_reserve;
 	}
-	if (lim < TASK_QUEUE__END)
-		return (TASK_QUEUE__END);
+	if (lim < TASK_QUEUE_RESERVE)
+		return (TASK_QUEUE_RESERVE);
 	return (lim);
 }
 
@@ -231,7 +231,7 @@ pool_getidleworker(struct pool *pp, enum task_prio prio)
 
 	CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
 	Lck_AssertHeld(&pp->mtx);
-	if (pp->nidle > (pool_reserve() * prio / TASK_QUEUE__END)) {
+	if (pp->nidle > (pool_reserve() * prio / TASK_QUEUE_RESERVE)) {
 		pt = VTAILQ_FIRST(&pp->idle_queue);
 		if (pt == NULL)
 			AZ(pp->nidle);
@@ -387,8 +387,8 @@ Pool_Work_Thread(struct pool *pp, struct worker *wrk)
 		Lck_Lock(&pp->mtx);
 		reserve = pool_reserve();
 
-		for (i = 0; i < TASK_QUEUE__END; i++) {
-			if (pp->nidle < (reserve * i / TASK_QUEUE__END))
+		for (i = 0; i < TASK_QUEUE_RESERVE; i++) {
+			if (pp->nidle < (reserve * i / TASK_QUEUE_RESERVE))
 				break;
 			tp = VTAILQ_FIRST(&pp->queues[i]);
 			if (tp != NULL) {
@@ -760,6 +760,6 @@ WRK_Log(enum VSL_tag_e tag, const char *fmt, ...)
 void
 WRK_Init(void)
 {
-	assert(cache_param->wthread_min >= TASK_QUEUE__END);
+	assert(cache_param->wthread_min >= TASK_QUEUE_RESERVE);
 	CLI_AddFuncs(debug_cmds);
 }
diff --git a/include/tbl/params.h b/include/tbl/params.h
index 9cf5de581..1d3416daa 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -1312,7 +1312,7 @@ PARAM_THREAD(
 	/* name */	thread_pool_min,
 	/* field */	min,
 	/* type */	thread_pool_min,
-	/* min */	"5" /* TASK_QUEUE__END */,
+	/* min */	"5" /* TASK_QUEUE_RESERVE */,
 	/* max */	NULL,
 	/* def */	"100",
 	/* units */	"threads",
@@ -1323,9 +1323,9 @@ PARAM_THREAD(
 	"situations or when threads have expired.\n"
 	"\n"
 	"Technical minimum is 5 threads, but this parameter is "
-	/*                    ^ TASK_QUEUE__END */
+	/*                    ^ TASK_QUEUE_RESERVE */
 	"strongly recommended to be at least 10",
-	/*               2 * TASK_QUEUE__END ^^ */
+	/*            2 * TASK_QUEUE_RESERVE ^^ */
 	/* flags */	DELAYED_EFFECT,
 	/* dyn_min_reason */	NULL,
 	/* dyn_max_reason */	"thread_pool_max"
@@ -1350,7 +1350,7 @@ PARAM_THREAD(
 	"priority tasks from running even under high load.\n"
 	"\n"
 	"The effective value is at least 5 (the number of internal "
-	/*                               ^ TASK_QUEUE__END */
+	/*                               ^ TASK_QUEUE_RESERVE */
 	"priority classes), irrespective of this parameter.",
 	/* flags */	DELAYED_EFFECT,
 	/* dyn_min_reason */	NULL,


More information about the varnish-commit mailing list