Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: Work around (virtual) memory exhaustion on 32-bit w/ glibc #10120

Merged
merged 1 commit into from Mar 31, 2017

Conversation

Projects
None yet
4 participants
@laanwj
Copy link
Member

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">
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.

@laanwj laanwj added this to the 0.14.1 milestone Mar 30, 2017

@gmaxwell
Copy link
Member

gmaxwell left a comment

utACK.

@JeremyRubin

This comment has been minimized.

Copy link
Contributor

JeremyRubin commented Mar 30, 2017

utACK.

@laanwj laanwj added this to For backport in High-priority for review Mar 30, 2017

@theuni

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

laanwj added a commit that referenced this pull request Mar 31, 2017

Merge #10120: util: Work around (virtual) memory exhaustion on 32-bit…
… 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

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: 625488a

@laanwj laanwj removed the Needs backport label Mar 31, 2017

@laanwj laanwj removed this from For backport in High-priority for review Apr 20, 2017

codablock added a commit to codablock/dash that referenced this pull request Jan 26, 2018

Merge bitcoin#10120: util: Work around (virtual) memory exhaustion on…
… 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 added a commit to lateminer/bitcoin that referenced this pull request Jan 5, 2019

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: bitcoin#10120
Rebased-From: 625488a

andvgal added a commit to energicryptocurrency/energi that referenced this pull request Jan 6, 2019

Merge bitcoin#10120: util: Work around (virtual) memory exhaustion on…
… 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 added a commit to absolute-community/absolute that referenced this pull request Feb 27, 2019

Merge bitcoin#10120: util: Work around (virtual) memory exhaustion on…
… 32-bit w/ glibc

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

Tree-SHA512: 99b610a8cf9561998af90e16fc19320fddd30c987e8f33325d63df0f56d70235b94d9482e80f28154d4b33a3ecf4961686380c444ec18d1da5e8804a8b6f4de1

PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Mar 15, 2019

Merge bitcoin#10120: util: Work around (virtual) memory exhaustion on…
… 32-bit w/ glibc

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

Tree-SHA512: 99b610a8cf9561998af90e16fc19320fddd30c987e8f33325d63df0f56d70235b94d9482e80f28154d4b33a3ecf4961686380c444ec18d1da5e8804a8b6f4de1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.