MINOR: quic: Allocate listener RX buffers

At this time we allocate an RX buffer by thread.
Also take the opportunity offered by this patch to rename TX related variable
names to distinguish them from the RX part.
This commit is contained in:
Frédéric Lécaille 2021-10-20 11:09:58 +02:00 committed by Amaury Denoyelle
parent a62f184d3d
commit c1029f6182
4 changed files with 60 additions and 13 deletions

View File

@ -68,8 +68,10 @@ struct receiver {
struct eb_root odcids; /* QUIC original destination connection IDs. */
struct eb_root cids; /* QUIC connection IDs. */
__decl_thread(HA_RWLOCK_T cids_lock); /* RW lock for connection IDs tree accesses */
struct qring *qrings; /* Array of rings (one by thread) */
struct mt_list tx_qrings; /* The same as ->qrings but arranged in a list */
struct qring *tx_qrings; /* Array of rings (one by thread) */
struct mt_list tx_qring_list; /* The same as ->qrings but arranged in a list */
struct rxbuf *rxbufs; /* Array of buffers for RX (one by thread) */
struct mt_list rxbuf_list; /* The same as ->rxbufs but arranged in a list */
#endif
/* warning: this struct is huge, keep it at the bottom */
struct sockaddr_storage addr; /* the address the socket is bound to */

View File

@ -232,9 +232,12 @@ enum quic_pkt_type {
/* Size of the internal buffer of QUIC TX ring buffers (must be a power of 2) */
#define QUIC_TX_RING_BUFSZ (1UL << 12)
/* Size of the internal buffer of QUIC RX buffer. */
#define QUIC_RX_BUFSZ (1UL << 18)
extern struct trace_source trace_quic;
extern struct pool_head *pool_head_quic_tx_ring;
extern struct pool_head *pool_head_quic_rxbuf;
extern struct pool_head *pool_head_quic_rx_packet;
extern struct pool_head *pool_head_quic_tx_packet;
extern struct pool_head *pool_head_quic_frame;
@ -587,6 +590,12 @@ struct qring {
struct mt_list mt_list;
};
/* QUIC RX buffer */
struct rxbuf {
struct buffer buf;
struct mt_list mt_list;
};
/* The number of buffers for outgoing packets (must be a power of two). */
#define QUIC_CONN_TX_BUFS_NB 8
#define QUIC_CONN_TX_BUF_SZ QUIC_PACKET_MAXLEN

View File

@ -528,19 +528,19 @@ static void quic_add_listener(struct protocol *proto, struct listener *listener)
/* Allocate the TX ring buffers for <l> listener.
* Return 1 if succeeded, 0 if not.
*/
static int quic_alloc_rings_listener(struct listener *l)
static int quic_alloc_tx_rings_listener(struct listener *l)
{
struct qring *qr;
int i;
l->rx.qrings = calloc(global.nbthread, sizeof *l->rx.qrings);
if (!l->rx.qrings)
l->rx.tx_qrings = calloc(global.nbthread, sizeof *l->rx.tx_qrings);
if (!l->rx.tx_qrings)
return 0;
MT_LIST_INIT(&l->rx.tx_qrings);
MT_LIST_INIT(&l->rx.tx_qring_list);
for (i = 0; i < global.nbthread; i++) {
unsigned char *buf;
struct qring *qr = &l->rx.qrings[i];
struct qring *qr = &l->rx.tx_qrings[i];
buf = pool_alloc(pool_head_quic_tx_ring);
if (!buf)
@ -552,17 +552,51 @@ static int quic_alloc_rings_listener(struct listener *l)
goto err;
}
MT_LIST_APPEND(&l->rx.tx_qrings, &qr->mt_list);
MT_LIST_APPEND(&l->rx.tx_qring_list, &qr->mt_list);
}
return 1;
err:
while ((qr = MT_LIST_POP(&l->rx.tx_qrings, typeof(qr), mt_list))) {
while ((qr = MT_LIST_POP(&l->rx.tx_qring_list, typeof(qr), mt_list))) {
pool_free(pool_head_quic_tx_ring, qr->cbuf->buf);
cbuf_free(qr->cbuf);
}
free(l->rx.qrings);
free(l->rx.tx_qrings);
return 0;
}
/* Allocate the RX buffers for <l> listener.
* Return 1 if succeeded, 0 if not.
*/
static int quic_alloc_rxbufs_listener(struct listener *l)
{
int i;
struct rxbuf *rxbuf;
l->rx.rxbufs = calloc(global.nbthread, sizeof *l->rx.rxbufs);
if (!l->rx.rxbufs)
return 0;
MT_LIST_INIT(&l->rx.rxbuf_list);
for (i = 0; i < global.nbthread; i++) {
char *buf;
rxbuf = &l->rx.rxbufs[i];
buf = pool_alloc(pool_head_quic_rxbuf);
if (!buf)
goto err;
rxbuf->buf = b_make(buf, QUIC_RX_BUFSZ, 0, 0);
MT_LIST_APPEND(&l->rx.rxbuf_list, &rxbuf->mt_list);
}
return 1;
err:
while ((rxbuf = MT_LIST_POP(&l->rx.rxbuf_list, typeof(rxbuf), mt_list)))
pool_free(pool_head_quic_rxbuf, rxbuf->buf.area);
free(l->rx.rxbufs);
return 0;
}
@ -596,8 +630,9 @@ static int quic_bind_listener(struct listener *listener, char *errmsg, int errle
goto udp_return;
}
if (!quic_alloc_rings_listener(listener)) {
msg = "could not initialize tx rings";
if (!quic_alloc_tx_rings_listener(listener) ||
!quic_alloc_rxbufs_listener(listener)) {
msg = "could not initialize tx/rx rings";
err |= ERR_WARN;
goto udp_return;
}

View File

@ -139,6 +139,7 @@ INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE);
static BIO_METHOD *ha_quic_meth;
DECLARE_POOL(pool_head_quic_tx_ring, "quic_tx_ring_pool", QUIC_TX_RING_BUFSZ);
DECLARE_POOL(pool_head_quic_rxbuf, "quic_rxbuf_pool", QUIC_RX_BUFSZ);
DECLARE_STATIC_POOL(pool_head_quic_conn_ctx,
"quic_conn_ctx_pool", sizeof(struct ssl_sock_ctx));
DECLARE_STATIC_POOL(pool_head_quic_conn, "quic_conn", sizeof(struct quic_conn));
@ -3016,7 +3017,7 @@ static struct quic_conn *qc_new_conn(unsigned int version, int ipv4,
if (scid_len)
memcpy(qc->dcid.data, scid, scid_len);
qc->dcid.len = scid_len;
qc->tx.qring_list = &l->rx.tx_qrings;
qc->tx.qring_list = &l->rx.tx_qring_list;
qc->li = l;
}
/* QUIC Client (outgoing connection to servers) */