From a582560da3dc0141f0fdf642d840735ec1117664 Mon Sep 17 00:00:00 2001 From: fanquake Date: Fri, 5 Jul 2019 09:07:00 +0800 Subject: [PATCH] docs: add reduce-memory.md Co-Authored-By: Wladimir J. van der Laan Plus adapted it to PIVX. Github-Pull: #2262 Rebased-From: caa67344d0824be17224556cfd238fb7b1eab45f --- doc/README.md | 1 + doc/reduce-memory.md | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 doc/reduce-memory.md diff --git a/doc/README.md b/doc/README.md index 9d607ca762b46..041aa96785bfb 100644 --- a/doc/README.md +++ b/doc/README.md @@ -64,6 +64,7 @@ The PIVX repo's [root README](/README.md) contains relevant information on the d ### Miscellaneous - [Assets Attribution](assets-attribution.md) - [Files](files.md) +- [Reduce Memory](reduce-memory.md) - [Tor Support](tor.md) - [Init Scripts (systemd/upstart/openrc)](init.md) diff --git a/doc/reduce-memory.md b/doc/reduce-memory.md new file mode 100644 index 0000000000000..dd137aef3cdab --- /dev/null +++ b/doc/reduce-memory.md @@ -0,0 +1,45 @@ +# Reduce Memory + +There are a few parameters that can be dialed down to reduce the memory usage of `pivxd`. This can be useful on embedded systems or small VPSes. + +## In-memory caches + +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. + +- `-dbcache=` - the UTXO database cache size, this defaults to `450`. The unit is MiB (1024). + - The minimum value for `-dbcache` is 4. + - 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. + +## Memory pool + +- In PIVX Core there is a memory pool limiter which can be configured with `-maxmempool=`, where `` is the size in MB (1000). The default value is `300`. + - The minimum value for `-maxmempool` is 5. + - A lower maximum mempool size means that transactions will be evicted sooner. This will affect any uses of `pivxd` that process unconfirmed transactions. + +- 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. + +## Number of peers + +- `-maxconnections=` - the maximum number of connections, this defaults to `125`. Each active connection takes up some memory. Only significant if incoming + connections are enabled, otherwise the number of connections will never be more than `8`. + +## Thread configuration + +For each thread a thread stack needs to be allocated. By default on Linux, +threads take up 8MiB for the thread stack on a 64-bit system, and 4MiB in a +32-bit system. + +- `-par=` - the number of script verification threads, defaults to the number of cores in the system minus one. +- `-rpcthreads=` - the number of threads used for processing RPC requests, defaults to `4`. + +## Linux specific + +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 pivxd: + +```bash +#!/usr/bin/env bash +export MALLOC_ARENA_MAX=1 +pivxd +``` + +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 PIVX Core very little parallel allocation happens, so the impact is expected to be small or absent.