aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-03-30 09:37:47 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2017-03-31 11:48:59 +0200
commite4c9a90fe9aa702d2e1f7d932fc29a9c9f23fd4a (patch)
tree5f97709bfea79eb0c829cb7b77ae48d060cb8c89 /src
parentf59e3dfc599ca9a30a1189e9a5bb033923498af2 (diff)
downloadbitcoin-e4c9a90fe9aa702d2e1f7d932fc29a9c9f23fd4a.tar.xz
util: Work around (virtual) memory exhaustion on 32-bit w/ glibc
glibc-specific: On 32-bit systems set the number of arenas to 1. By default, since glibc 2.10, the C library will create up to two heap arenas per core. This is known to cause excessive virtual address space usage in our usage. Work around it by setting the maximum number of arenas to 1. Github-Pull: #10120 Rebased-From: 625488ace5c41ccba1b68323a72588000782f820
Diffstat (limited to 'src')
-rw-r--r--src/util.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 78c353dfe5..6f812d9104 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -72,6 +72,10 @@
#include <sys/prctl.h>
#endif
+#ifdef HAVE_MALLOPT_ARENA_MAX
+#include <malloc.h>
+#endif
+
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
@@ -792,6 +796,16 @@ void RenameThread(const char* name)
void SetupEnvironment()
{
+#ifdef HAVE_MALLOPT_ARENA_MAX
+ // glibc-specific: On 32-bit systems set the number of arenas to 1.
+ // By default, since glibc 2.10, the C library will create up to two heap
+ // arenas per core. This is known to cause excessive virtual address space
+ // usage in our usage. Work around it by setting the maximum number of
+ // arenas to 1.
+ if (sizeof(void*) == 4) {
+ mallopt(M_ARENA_MAX, 1);
+ }
+#endif
// On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
// may be invalid, in which case the "C" locale is used as fallback.
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)