Skip to content

Commit 64b27c4

Browse files
fanquakelaanwj
andcommitted
docs: add reduce-memory.md
Co-Authored-By: Wladimir J. van der Laan <[email protected]>
1 parent dfdcb3d commit 64b27c4

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

doc/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ The Bitcoin repo's [root README](/README.md) contains relevant information on th
7474
- [bitcoin.conf Configuration File](bitcoin-conf.md)
7575
- [Files](files.md)
7676
- [Fuzz-testing](fuzzing.md)
77+
- [Reduce Memory](reduce-memory.md)
7778
- [Reduce Traffic](reduce-traffic.md)
7879
- [Tor Support](tor.md)
7980
- [Init Scripts (systemd/upstart/openrc)](init.md)

doc/reduce-memory.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Reduce Memory
2+
3+
There are a few parameters that can be dialed down to reduce the memory usage of `bitcoind`. This can be useful on embedded systems or small VPSes.
4+
5+
## In-memory caches
6+
7+
The size of some in-memory caches can be reduced. As caches trade off memory usage for performance, reducing these will usually have a negative effect on performance.
8+
9+
- `-dbcache=<n>` - the UTXO database cache size, this defaults to `450`. The unit is MiB (1024).
10+
- The minimum value for `-dbcache` is 4.
11+
- A lower `-dbcache` makes initial sync time much longer. After the initial sync, the effect is less pronounced for most use-cases, unless fast validation of blocks is important, such as for mining.
12+
13+
## Memory pool
14+
15+
- In Bitcoin Core there is a memory pool limiter which can be configured with `-maxmempool=<n>`, where `<n>` is the size in MB (1000). The default value is `300`.
16+
- The minimum value for `-maxmempool` is 5.
17+
- A lower maximum mempool size means that transactions will be evicted sooner. This will affect any uses of `bitcoind` that process unconfirmed transactions.
18+
19+
- To completely disable mempool functionality there is the option `-blocksonly`. This will make the client opt out of receiving (and thus relaying) transactions completely, except as part of blocks.
20+
21+
- Do not use this when using the client to broadcast transactions as any transaction sent will stick out like a sore thumb, affecting privacy. When used with the wallet it should be combined with `-walletbroadcast=0` and `-spendzeroconfchange=0`. Another mechanism for broadcasting outgoing transactions (if any) should be used.
22+
23+
- Since `0.14.0`, unused memory allocated to the mempool (default: 300MB) is shared with the UTXO cache, so when trying to reduce memory usage you should limit the mempool, with the `-maxmempool` command line argument.
24+
25+
## Number of peers
26+
27+
- `-maxconnections=<n>` - the maximum number of connections, this defaults to `125`. Each active connection takes up some memory. Only significant if incoming
28+
connections are enabled, otherwise the number of connections will never be more than `8`.
29+
30+
## Thread configuration
31+
32+
For each thread a thread stack needs to be allocated. By default on Linux,
33+
threads take up 8MiB for the thread stack on a 64-bit system, and 4MiB in a
34+
32-bit system.
35+
36+
- `-par=<n>` - the number of script verification threads, defaults to the number of cores in the system minus one.
37+
- `-rpcthreads=<n>` - the number of threads used for processing RPC requests, defaults to `4`.
38+
39+
## Linux specific
40+
41+
By default, since glibc `2.10`, the C library will create up to two heap arenas per core. This is known to cause excessive memory usage in some scenarios. To avoid this make a script that sets `MALLOC_ARENA_MAX` before starting bitcoind:
42+
43+
```bash
44+
#!/bin/bash
45+
export MALLOC_ARENA_MAX=1
46+
bitcoind
47+
```
48+
49+
The behavior was introduced to increase CPU locality of allocated memory and performance with concurrent allocation, so this setting could in theory reduce performance. However, in Bitcoin Core very little parallel allocation happens, so the impact is expected to be small or absent.

0 commit comments

Comments
 (0)