From 7393bf7e424d4cd2e0927bf4dc95eb799ec67dd4 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Fri, 17 Nov 2023 10:52:36 +0100 Subject: [PATCH] MINOR: htx: Use a macro for overhead induced by HTX The overhead induced by the HTX format was set to the HTX structure itself and two HTX blocks. It was set this way to optimize zero-copy during transfers. This value may (and will) be used at different places. Thus we now use a macro, called HTX_BUF_OVERHEAD. --- include/haproxy/htx-t.h | 6 ++++++ include/haproxy/htx.h | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/haproxy/htx-t.h b/include/haproxy/htx-t.h index 687e403c7..2ea6bc8b2 100644 --- a/include/haproxy/htx-t.h +++ b/include/haproxy/htx-t.h @@ -164,6 +164,12 @@ static forceinline char *hsl_show_flags(char *buf, size_t len, const char *delim #undef _ } +/* Overhead induced by HTX on buffers during transfers. In addition to the size + * of the HTX structure itself, and meta data for one block, another block is + * accounted to favored zero-copy xfer. + */ +#define HTX_BUF_OVERHEAD (sizeof(struct htx) + 2 * sizeof(struct htx_blk)) + /* HTX flags. * Please also update the htx_show_flags() function below in case of changes. */ diff --git a/include/haproxy/htx.h b/include/haproxy/htx.h index 59e885a67..c991c81e5 100644 --- a/include/haproxy/htx.h +++ b/include/haproxy/htx.h @@ -673,10 +673,10 @@ 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)) + if (room <= HTX_BUF_OVERHEAD) room = 0; else - room -= sizeof(struct htx) + 2 * sizeof(struct htx_blk); + room -= HTX_BUF_OVERHEAD; return room; }