We should add a note here: https://docs.mongodb.com/manual/core/wiredtiger/#memory-use
Which says that if the database has memory limits placed on it which are lower than the system memory, for example when running in a container, then that is used as the maximum RAM available rather than the total system memory.
We should do something similar anywhere else that we call out memory calculations anywhere else that are used for actions/defaults related to the memory available to MongoDB.
We should note that the hostInfo command contains a new field, memLimitMB, which tells you if the host is placing any memory usage limit on the process (for example when using containers).
Note: this work was backported to 4.0 and 3.6.
- We set the default WiredTiger cache_size to approximately 1/2 of the memory size
- When ephemeral storage is in use we consider the memory limit in place to determine the default oplog size
- We set the tcmalloc cache size to 1/8th of the available memory
In all of these cases we should take the actual memory constraint that we're operating under into account rather than the total system memory – for example when running MongoDB within containers.