]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-quic: define buf_in_flight
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 13 Aug 2024 06:51:46 +0000 (08:51 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 20 Aug 2024 15:17:17 +0000 (17:17 +0200)
Define a new QCC counter named <buf_in_flight>. Its purpose is to
account the current sum of all allocated stream buffer size used on
emission.

For this moment, this counter is updated and buffer allocation and
deallocation. It will be used to replace <avail_bufs> once congestion
window is used as limit for buffer allocation in a future commit.

include/haproxy/mux_quic-t.h
include/haproxy/mux_quic.h
src/mux_quic.c
src/quic_stream.c

index 22fd1b910538ff8d71605dcb48afbcccc51b0dcb..de68a40ff4812de6ea8d4207f0f3f13b871411a0 100644 (file)
@@ -68,6 +68,7 @@ struct qcc {
        struct {
                struct quic_fctl fc; /* stream flow control applied on sending */
                int avail_bufs; /* count of available buffers for this connection */
+               uint64_t buf_in_flight; /* sum of currently allocated Tx buffer sizes */
        } tx;
 
        uint64_t largest_bidi_r; /* largest remote bidi stream ID opened. */
index c61044760837a3579abbbab3e03ad900b8c32469..f1ed218a54afe6438cdce91b62d3b6e0cc79ff8a 100644 (file)
@@ -23,7 +23,7 @@ int qcs_is_close_remote(struct qcs *qcs);
 int qcs_subscribe(struct qcs *qcs, int event_type, struct wait_event *es);
 void qcs_notify_recv(struct qcs *qcs);
 void qcs_notify_send(struct qcs *qcs);
-void qcc_notify_buf(struct qcc *qcc, int free_count);
+void qcc_notify_buf(struct qcc *qcc, int free_count, uint64_t free_size);
 
 struct buffer *qcc_get_stream_rxbuf(struct qcs *qcs);
 struct buffer *qcc_get_stream_txbuf(struct qcs *qcs, int *err);
index dd315d07816df83f895f9201066fb12b7f608004..d30ca29760f2b2242f5332d93e4df8120baa7325 100644 (file)
@@ -524,10 +524,10 @@ void qcs_notify_send(struct qcs *qcs)
        }
 }
 
-/* Report that <free_count> stream-desc buffer have been released for <qcc>
- * connection.
+/* Report that one or several stream-desc buffers have been released for <qcc>
+ * connection. <free_size> represent the sum of freed buffers sizes.
  */
-void qcc_notify_buf(struct qcc *qcc, int free_count)
+void qcc_notify_buf(struct qcc *qcc, int free_count, uint64_t free_size)
 {
        struct qcs *qcs;
 
@@ -536,6 +536,10 @@ void qcc_notify_buf(struct qcc *qcc, int free_count)
        BUG_ON(qcc->tx.avail_bufs + free_count > global.tune.quic_streams_buf);
        qcc->tx.avail_bufs += free_count;
 
+       /* Cannot have a negative buf_in_flight counter */
+       BUG_ON(qcc->tx.buf_in_flight < free_size);
+       qcc->tx.buf_in_flight -= free_size;
+
        if (qcc->flags & QC_CF_CONN_FULL) {
                TRACE_STATE("new stream desc buffer available", QMUX_EV_QCC_WAKE, qcc->conn);
                qcc->flags &= ~QC_CF_CONN_FULL;
@@ -1059,8 +1063,10 @@ struct buffer *qcc_get_stream_txbuf(struct qcs *qcs, int *err)
                        goto out;
                }
 
-               if (likely(!unlimited))
+               if (likely(!unlimited)) {
                        --qcc->tx.avail_bufs;
+                       qcc->tx.buf_in_flight += global.tune.bufsize;
+               }
        }
 
  out:
@@ -2728,6 +2734,7 @@ static int qmux_init(struct connection *conn, struct proxy *prx,
        qcc->rfctl.msd_uni_l = rparams->initial_max_stream_data_uni;
 
        qcc->tx.avail_bufs = global.tune.quic_streams_buf;
+       qcc->tx.buf_in_flight = 0;
 
        if (conn_is_back(conn)) {
                qcc->next_bidi_l    = 0x00;
index a0baa0b98baf1a1b1a319ecfada58bef2e4ec77d..c99266978c6958f6cff1733c4afd5195137cc00c 100644 (file)
@@ -28,6 +28,7 @@ static void qc_stream_buf_free(struct qc_stream_desc *stream,
 {
        struct quic_conn *qc = stream->qc;
        struct buffer *buf = &(*stream_buf)->buf;
+       uint64_t free_size;
 
        LIST_DEL_INIT(&(*stream_buf)->list);
 
@@ -35,6 +36,7 @@ static void qc_stream_buf_free(struct qc_stream_desc *stream,
        if (*stream_buf == stream->buf)
                stream->buf = NULL;
 
+       free_size = b_size(buf);
        b_free(buf);
        offer_buffers(NULL, 1);
        pool_free(pool_head_quic_stream_buf, *stream_buf);
@@ -44,7 +46,7 @@ static void qc_stream_buf_free(struct qc_stream_desc *stream,
        if (qc->mux_state == QC_MUX_READY) {
                if (!(stream->flags & QC_SD_FL_OOB_BUF)) {
                        /* notify MUX about available buffers. */
-                       qcc_notify_buf(qc->qcc, 1);
+                       qcc_notify_buf(qc->qcc, 1, free_size);
                }
        }
 }
@@ -200,6 +202,7 @@ void qc_stream_desc_free(struct qc_stream_desc *stream, int closing)
        struct quic_conn *qc = stream->qc;
        struct eb64_node *frm_node;
        unsigned int free_count = 0;
+       uint64_t free_size = 0;
 
        /* This function only deals with released streams. */
        BUG_ON(!(stream->flags & QC_SD_FL_RELEASE));
@@ -207,6 +210,7 @@ void qc_stream_desc_free(struct qc_stream_desc *stream, int closing)
        /* free remaining stream buffers */
        list_for_each_entry_safe(buf, buf_back, &stream->buf_list, list) {
                if (!(b_data(&buf->buf)) || closing) {
+                       free_size += b_size(&buf->buf);
                        b_free(&buf->buf);
                        LIST_DELETE(&buf->list);
                        pool_free(pool_head_quic_stream_buf, buf);
@@ -220,7 +224,7 @@ void qc_stream_desc_free(struct qc_stream_desc *stream, int closing)
                if (qc->mux_state == QC_MUX_READY) {
                        if (!(stream->flags & QC_SD_FL_OOB_BUF)) {
                                /* notify MUX about available buffers. */
-                               qcc_notify_buf(qc->qcc, free_count);
+                               qcc_notify_buf(qc->qcc, free_count, free_size);
                        }
                }
        }