I saw this in another thread and I decided to post a clarification.
5120 seems to be reasonable size as
firstly it is divisible by 1024
otherwise RAM might be used inefficiently and
secondly it is slightly more than 1/4 RAM which left the space for other OS operation.However, if the system isn't heavily used for other tasks it's safe to allocate more memory to dbcache. In such cases, increasing it to 1/2
dbcache = 8192 or even 3/4
dbcache = 12288 of RAM might improve performance. User should test what is the best option for him.
Should -dbcache be set to a value divisible by 1024?It's a very normal misconception and I thought I should clear it out. Because trying to put a number that's divisible by 1024 is wrong. In fact, the default value is 450 MiB, which is obviously not divisible by 1024, but still, I don't think Core developers would put a default value that would make RAM be used inefficiently.
There is actually no problem at all, setting the
-dbcache to any integer value. You can put -dbcache=8000 or -dbcache=8192, it won't make a difference.
Memory is broken into pages which are normally 4 KiB each. This happens because any program that requests memory won't get a big continuous block, but smaller 4 KiB chunks for memory.
When we say to Bitcoin Core that we need 8000 MiB, it will do the following:
8000 MiB = 8,388,608,000 bytes
4 KiB = 4096 bytes
So there will be 8,388,608,000 / 4096 = 2,048,000 pages of memory allocated for Bitcoin Core.
Let's also explain mathematically why
any number that you put as dbcache won't cause a problemdbcache is an integer and it's measured in MiB (mebibytes).
1 MiB = 1,048,576 bytes = 2^20 bytes.
Every page in memory is 4 KiB = 4096 bytes = 2^12 bytes.
Since 2^20 / 2^12 = 2^8 = 256, it means that
1 MiB = 256 pages of 4 KiB each.
So, go ahead and try it. Put any integer for -dbcache. Let's say you pick
n.
Then, the number of pages will be n MiB = n * 1,048,576 bytes. Since 1,048,576 is divisible by 4096, then any
n that you choose, the divisibility will be preserved.
To conclude, use any number for -dbcache, without worrying.
About the proper dbcache size, there is a good read here:
https://blog.lopp.net/effects-dbcache-size-bitcoin-node-sync-speed/, but in general I agree with satscraper.