MINOR: config: round up global.tune.bufsize to the next multiple of 2 void*

Since HTX casts the buffer to a struct and stores relative pointers at the
end, it is mandatory that its end is properly aligned. This patch enforces
a buffer size rounding up to the next multiple of two void*, thus 8 on
32-bit and 16 on 64-bit, to match what malloc() already does on the beginning
of the buffer. In pratice it will never be really noticeable since default
sizes already are such multiples.
This commit is contained in:
Willy Tarreau 2018-12-12 06:19:42 +01:00
parent 3815b227fe
commit c77d364905
3 changed files with 7 additions and 3 deletions

View File

@ -1532,7 +1532,9 @@ tune.bufsize <number>
addition, use of HTTP/2 mandates that this value must be 16384 or more. If an
HTTP request is larger than (tune.bufsize - tune.maxrewrite), haproxy will
return HTTP 400 (Bad Request) error. Similarly if an HTTP response is larger
than this size, haproxy will return HTTP 502 (Bad Gateway).
than this size, haproxy will return HTTP 502 (Bad Gateway). Note that the
value set using this parameter will automatically be rounded up to the next
multiple of 8 on 32-bit machines and 16 on 64-bit machines.
tune.chksize <number>
Sets the check buffer size to this size (in bytes). Higher values may help

View File

@ -206,6 +206,8 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
goto out;
}
global.tune.bufsize = atol(args[1]);
/* round it up to support a two-pointer alignment at the end */
global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
if (global.tune.bufsize <= 0) {
ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
err_code |= ERR_ALERT | ERR_FATAL;

View File

@ -149,9 +149,9 @@ struct global global = {
}
},
.tune = {
.bufsize = BUFSIZE,
.bufsize = (BUFSIZE + 2*sizeof(void *) - 1) & -(2*sizeof(void *)),
.maxrewrite = -1,
.chksize = BUFSIZE,
.chksize = (BUFSIZE + 2*sizeof(void *) - 1) & -(2*sizeof(void *)),
.reserved_bufs = RESERVED_BUFS,
.pattern_cache = DEFAULT_PAT_LRU_SIZE,
#ifdef USE_OPENSSL