]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: add buf_room_for_htx_data() to help optimize buffer transfers
authorWilly Tarreau <w@1wt.eu>
Wed, 5 Dec 2018 06:56:25 +0000 (07:56 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 5 Dec 2018 09:57:42 +0000 (10:57 +0100)
The small HTX overhead is enough to make the system perform multiple
reads and unaligned memory copies. Here we provide a function whose
purpose is to reduce the apparent room in a buffer by the size of the
overhead for DATA blocks, which is the struct htx plus 2 blocks (one
for DATA, one for the end of message so that small blocks can fit at
once). The muxes using HTX will be encouraged to use this one instead
of b_room() to compute the available buffer room and avoid filling
their demux buf with more data than can fit at once into the HTX
buffer.

include/proto/htx.h

index b6f1042f45b3bca0e3857e1b99ef7d1164c03dec..fdd305646e29da1371cad6daaa1be3414abb0155 100644 (file)
@@ -524,6 +524,23 @@ static inline void htx_reset(struct htx *htx)
        htx->sl_off = -1;
 }
 
+/* returns the available room for raw data in buffer <buf> once HTX overhead is
+ * taken into account (one HTX header and two blocks). The purpose is to figure
+ * the optimal fill length to avoid copies.
+ */
+static inline size_t buf_room_for_htx_data(const struct buffer *buf)
+{
+       size_t room;
+
+       room = b_room(buf);
+       if (room <= sizeof(struct htx) + 2 * sizeof(struct htx_blk))
+               room = 0;
+       else
+               room -= sizeof(struct htx) + 2 * sizeof(struct htx_blk);
+
+       return room;
+}
+
 /* Returns an HTX message using the buffer <buf>. */
 static inline struct htx *htx_from_buf(struct buffer *buf)
 {