[core] config mallopt(M_ARENA_MAX, 2) (#3084)

Preemptively cap the max number of arenas that might be created by glibc

Each thread attempts to use the previously-used arena.
lighttpd is single-threaded, so in general, only one arena is used.

x-ref:
  "Memory fragmentation with HTTP/2 enabled"
  https://redmine.lighttpd.net/issues/3084
personal/stbuehler/tests-path
Glenn Strauss 2021-06-14 04:34:20 -04:00
parent 1783550154
commit 43f0106f81
1 changed files with 21 additions and 0 deletions

View File

@ -65,6 +65,15 @@ static const buffer default_server_tag = { CONST_STR_LEN(PACKAGE_DESC)+1, 0 };
# include <sys/prctl.h>
#endif
#ifdef HAVE_MALLOC_H
#ifndef LIGHTTPD_STATIC
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#endif
#endif
#include <malloc.h>
#endif
#include "sys-crypto.h"
#if defined(USE_OPENSSL_CRYPTO) \
|| defined(USE_MBEDTLS_CRYPTO) \
@ -1978,6 +1987,18 @@ int main (int argc, char **argv) {
}
#endif
#if defined(HAVE_MALLOPT) && defined(M_ARENA_MAX)
#ifdef LIGHTTPD_STATIC
mallopt(M_ARENA_MAX, 2); /*(ignore error, if any)*/
#else
{
int (*mallopt_fn)(int, int);
mallopt_fn = (int (*)(int, int))(intptr_t)dlsym(RTLD_DEFAULT,"mallopt");
if (mallopt_fn) mallopt_fn(M_ARENA_MAX, 2); /*(ignore error, if any)*/
}
#endif
#endif
/* for nice %b handling in strftime() */
setlocale(LC_TIME, "C");
tzset();