Skip to content

Conversation

@laanwj
Copy link
Member

@laanwj laanwj commented Mar 30, 2017

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.

I documented this before in Reducing bitcoind memory usage but with the reported OOM issues in 0.14 it seems more pressing to do it by default when there is low virtual memory space (e.g. on 32 bit).

To test:

bitcoin-cli getmemoryinfo mallocinfo | grep "<heap"

This will show an entry per heap.

Tested on 32-bit ARM, 4-core:

<heap nr="0">

Tested on 64-bit x86, 6-core:

<heap nr="0">
<heap nr="1">
<heap nr="2">
<heap nr="3">
<heap nr="4">
<heap nr="5">
<heap nr="6">
<heap nr="7">
<heap nr="8">
<heap nr="9">
<heap nr="10">
<heap nr="11">
<heap nr="12">

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.
Copy link
Contributor

@gmaxwell gmaxwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK.

@JeremyRubin
Copy link
Contributor

utACK.

@theuni
Copy link
Member

theuni commented Mar 31, 2017

I'm not familiar with the intricacies here, so I'll defer judgement on the root issue.

The implementation suggests that it's meant to apply to glibc only, but there's no obvious check for that. Is M_ARENA_MAX itself glibc specific, or do we need some macro to check for it?

@laanwj
Copy link
Member Author

laanwj commented Mar 31, 2017

I'm not familiar with the intricacies here, so I'll defer judgement on the root issue.

The root issue is that freed object stay around for a while for reuse, so having 8 heaps means that they can potentially stick around 8 times. This is extremely bad considering e.g. how large the consecutive objects are that leveldb allocates.

The implementation suggests that it's meant to apply to glibc only, but there's no obvious check for that. Is M_ARENA_MAX itself glibc specific, or do we need some macro to check for it?

As always, feel free to suggest a better way to do the autoconf stuff. Yes, M_ARENA_MAX is specific to glibc (or anything deriving from it).

@theuni
Copy link
Member

theuni commented Mar 31, 2017

I didn't mean to imply that anything was incorrect, just wanted to clarify the assumptions. Thanks for explaining. Code looks good. utACK 625488a

@laanwj laanwj merged commit 625488a into bitcoin:master Mar 31, 2017
laanwj added a commit that referenced this pull request Mar 31, 2017
… w/ glibc

625488a util: Work around (virtual) memory exhaustion on 32-bit w/ glibc (Wladimir J. van der Laan)

Tree-SHA512: 99b610a8cf9561998af90e16fc19320fddd30c987e8f33325d63df0f56d70235b94d9482e80f28154d4b33a3ecf4961686380c444ec18d1da5e8804a8b6f4de1
laanwj added a commit that referenced this pull request Mar 31, 2017
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: 625488a
codablock pushed a commit to codablock/dash that referenced this pull request Jan 26, 2018
… 32-bit w/ glibc

625488a util: Work around (virtual) memory exhaustion on 32-bit w/ glibc (Wladimir J. van der Laan)

Tree-SHA512: 99b610a8cf9561998af90e16fc19320fddd30c987e8f33325d63df0f56d70235b94d9482e80f28154d4b33a3ecf4961686380c444ec18d1da5e8804a8b6f4de1
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Jan 5, 2019
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: bitcoin#10120
Rebased-From: 625488a
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
… 32-bit w/ glibc

625488a util: Work around (virtual) memory exhaustion on 32-bit w/ glibc (Wladimir J. van der Laan)

Tree-SHA512: 99b610a8cf9561998af90e16fc19320fddd30c987e8f33325d63df0f56d70235b94d9482e80f28154d4b33a3ecf4961686380c444ec18d1da5e8804a8b6f4de1
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Feb 27, 2019
… 32-bit w/ glibc

625488a util: Work around (virtual) memory exhaustion on 32-bit w/ glibc (Wladimir J. van der Laan)

Tree-SHA512: 99b610a8cf9561998af90e16fc19320fddd30c987e8f33325d63df0f56d70235b94d9482e80f28154d4b33a3ecf4961686380c444ec18d1da5e8804a8b6f4de1
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants