mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-05 14:47:07 +02:00
BUG/MEDIUM: fd: prevent memory waste in fdtab array
In97ea9c49f1
("BUG/MEDIUM: fd: always align fdtab[] to 64 bytes"), the patch doesn't do what the message says. The intent was only to align the base fdtab addr on 64 bytes so that all fdtab entries are aligned and thus don't share the same cache line. For that, fdtab pointer is adjusted from fdtab_addr (unaligned) address after it is allocated. Thus, all we need is an extra 64 bytes in the fdtab_addr array for the aligment. Because we use calloc() to perform the allocation, a dumb mistake was made: the '+64' was added on <size> calloc argument, which means EACH fdtab entry is allocated with 64 extra bytes. Given that a single fdtab entry is 64 bytes, since97ea9c49f1
each fdtab entry now takes 128 bytes! We doubled fdtab memory consumption. To give you an idea, on my laptop, when looking at memory consumption using 'ps -p `pidof haproxy` -o size' right after starting haproxy process with default settings (no maxsock enforced): before97ea9c49f1
: -> 118440 (KB, ~= 118MB) after97ea9c49f1
: -> 183976 (KB, ~= 184MB) To fix this, use calloc with 1 <nmemb> and manually provide the size with <size> as we would do if we used malloc(). With this patch, we're back to pre-97ea9c49f1 for fdtab memory consumption (with 64 extra bytes the whole array, which is insignificant). It should be backported to all stable versions.
This commit is contained in:
parent
e84c8dee1a
commit
b9915a745e
2
src/fd.c
2
src/fd.c
@ -1158,7 +1158,7 @@ int init_pollers()
|
||||
int p;
|
||||
struct poller *bp;
|
||||
|
||||
if ((fdtab_addr = calloc(global.maxsock, sizeof(*fdtab) + 64)) == NULL) {
|
||||
if ((fdtab_addr = calloc(1, global.maxsock * sizeof(*fdtab) + 64)) == NULL) {
|
||||
ha_alert("Not enough memory to allocate %d entries for fdtab!\n", global.maxsock);
|
||||
goto fail_tab;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user