]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic_sock: index li->per_thr[] on local thread id, not global one
authorWilly Tarreau <w@1wt.eu>
Fri, 21 Apr 2023 08:46:45 +0000 (10:46 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 21 Apr 2023 15:41:26 +0000 (17:41 +0200)
There's a li_per_thread array in each listener for use with QUIC
listeners. Since thread groups were introduced, this array can be
allocated too large because global.nbthread is allocated for each
listener, while only no more than MIN(nbthread,MAX_THREADS_PER_GROUP)
may be used by a single listener. This was because the global thread
ID is used as the index instead of the local ID (since a listener may
only be used by a single group). Let's just switch to local ID and
reduce the allocated size.

include/haproxy/listener-t.h
src/listener.c
src/quic_sock.c

index 0f6adde3ad1e0295524d3aae0b293d5b82e093cd..f45c990a5a22608fdbe980c3070119b6ef8d1015 100644 (file)
@@ -246,7 +246,7 @@ struct listener {
                struct eb32_node id;    /* place in the tree of used IDs */
        } conf;                         /* config information */
 
-       struct li_per_thread *per_thr;  /* per-thread fields */
+       struct li_per_thread *per_thr;  /* per-thread fields (one per thread in the group) */
 
        EXTRA_COUNTERS(extra_counters);
 };
index ad72c8eccf743b13261cfc976fb112f69aa79220..d6e58ce69a3077d11bf36aafd4c875f93ef99247 100644 (file)
@@ -205,19 +205,21 @@ REGISTER_POST_DEINIT(accept_queue_deinit);
 
 #endif // USE_THREAD
 
-/* Memory allocation and initialization of the per_thr field.
+/* Memory allocation and initialization of the per_thr field (one entry per
+ * bound thread).
  * Returns 0 if the field has been successfully initialized, -1 on failure.
  */
 int li_init_per_thr(struct listener *li)
 {
+       int nbthr = MIN(global.nbthread, MAX_THREADS_PER_GROUP);
        int i;
 
        /* allocate per-thread elements for listener */
-       li->per_thr = calloc(global.nbthread, sizeof(*li->per_thr));
+       li->per_thr = calloc(nbthr, sizeof(*li->per_thr));
        if (!li->per_thr)
                return -1;
 
-       for (i = 0; i < global.nbthread; ++i) {
+       for (i = 0; i < nbthr; ++i) {
                MT_LIST_INIT(&li->per_thr[i].quic_accept.list);
                MT_LIST_INIT(&li->per_thr[i].quic_accept.conns);
 
index d7d40982edde515f83f54334c57b993948b2da24..196ad386d9e3977b103389fa6113cedf0abb129b 100644 (file)
@@ -147,7 +147,7 @@ int quic_sock_accepting_conn(const struct receiver *rx)
 struct connection *quic_sock_accept_conn(struct listener *l, int *status)
 {
        struct quic_conn *qc;
-       struct li_per_thread *lthr = &l->per_thr[tid];
+       struct li_per_thread *lthr = &l->per_thr[ti->ltid];
 
        qc = MT_LIST_POP(&lthr->quic_accept.conns, struct quic_conn *, accept_list);
        if (!qc || qc->flags & (QUIC_FL_CONN_CLOSING|QUIC_FL_CONN_DRAINING))
@@ -897,7 +897,7 @@ struct quic_accept_queue *quic_accept_queues;
 void quic_accept_push_qc(struct quic_conn *qc)
 {
        struct quic_accept_queue *queue = &quic_accept_queues[tid];
-       struct li_per_thread *lthr = &qc->li->per_thr[tid];
+       struct li_per_thread *lthr = &qc->li->per_thr[ti->ltid];
 
        /* early return if accept is already in progress/done for this
         * connection