From: Willy Tarreau Date: Mon, 29 Apr 2024 07:20:17 +0000 (+0200) Subject: MEDIUM: dynbuf/mux-h1: do not allocate the buffers in the callback X-Git-Tag: v3.0-dev11~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a160b3c50cd2eceb0dbb8e6a1f06d09e9b07b625;p=thirdparty%2Fhaproxy.git MEDIUM: dynbuf/mux-h1: do not allocate the buffers in the callback One of the problematic designs with the buffer_wait mechanism is that the callbacks pre-allocate the buffers and stay in the run queue for a while, resulting in all of the few buffers being assigned to waiting tasks instead of being all available to one task that needs them all at once. Here we simply stop doing this, the callback clears the waiting flags and wakes the task up so that it has a chance of still finding some buffers. --- diff --git a/src/mux_h1.c b/src/mux_h1.c index 1fafdfd260..79b6afef71 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -501,30 +501,25 @@ static int h1_buf_available(void *target) { struct h1c *h1c = target; - if ((h1c->flags & H1C_F_IN_ALLOC) && b_alloc(&h1c->ibuf, DB_MUX_RX)) { + if ((h1c->flags & H1C_F_IN_ALLOC) && h1_recv_allowed(h1c)) { TRACE_STATE("unblocking h1c, ibuf allocated", H1_EV_H1C_RECV|H1_EV_H1C_BLK|H1_EV_H1C_WAKE, h1c->conn); h1c->flags &= ~H1C_F_IN_ALLOC; - if (h1_recv_allowed(h1c)) - tasklet_wakeup(h1c->wait_event.tasklet); - return 1; + tasklet_wakeup(h1c->wait_event.tasklet); } - if ((h1c->flags & H1C_F_OUT_ALLOC) && b_alloc(&h1c->obuf, DB_MUX_TX)) { + if ((h1c->flags & H1C_F_OUT_ALLOC) && h1c->h1s) { TRACE_STATE("unblocking h1s, obuf allocated", H1_EV_TX_DATA|H1_EV_H1S_BLK|H1_EV_STRM_WAKE, h1c->conn, h1c->h1s); h1c->flags &= ~H1C_F_OUT_ALLOC; - if (h1c->h1s) - h1_wake_stream_for_send(h1c->h1s); - return 1; + h1_wake_stream_for_send(h1c->h1s); } - if ((h1c->flags & H1C_F_IN_SALLOC) && h1c->h1s && b_alloc(&h1c->h1s->rxbuf, DB_SE_RX)) { + if ((h1c->flags & H1C_F_IN_SALLOC) && h1c->h1s) { TRACE_STATE("unblocking h1c, stream rxbuf allocated", H1_EV_H1C_RECV|H1_EV_H1C_BLK|H1_EV_H1C_WAKE, h1c->conn); h1c->flags &= ~H1C_F_IN_SALLOC; tasklet_wakeup(h1c->wait_event.tasklet); - return 1; } - return 0; + return 1; } /*