About mogodb cache

  mongodb, question
With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache.
 
 Starting in 3.4, the WiredTiger internal cache, by default, will use the larger of either:
 
 50% of (RAM - 1 GB), or
 256 MB.

Mongodb4.0 document, probably means mongodb usesinternal cache and the filesystem cache,
(1) Please ask if the internal catche will occupy 512m according to the above calculation if the memory of the machine is 2g. If the data increases and the memory occupies more than 512m, will you start to enable filesystem cache and put the data cache on the free memory at this time? Is there any sequence between the two?
(2) Since both are stored in memory, why are there two types of caches? Is it true that the memory occupied by internal cache cannot be released and the memory occupied by filesystem cache will be squeezed out by other services?
(3) Are these caches also compressed?

Almost all the answers were given upstairs. Add some:
Filesystem cache is an operating system behavior that is not controlled by the application. This part of the cache will be allocated to other processes when necessary. Because filesystem cache is a faithful mapping of disk files and MongoDB’s files stored on disk are compressed, this means that the contents in filesystem cache are compressed.
Internal cache is the part controlled by MongoDB, which stores recently used data, indexes, etc. and is decompressed.
1) This is actually knowledge of operating system principles. MongoDB will load the data into the memory by first reading the original file from the disk, then the file content will enter the filesystem cache. Then it will convert the file content into a format that WiredTiger can directly use, i.e. decompress and decrypt, and then the content will enter the internal cache. Therefore, if you must say the order, the contents in the internal cache must come from the filesystem cache, which loads first.
2) internal cache is the process memory and filesystem cache is the operating system cache. The latter will be expelled from memory by LRU algorithm at a certain time. If it is read again, it will be loaded from the disk. However, the former is also likely to be evicted from memory, because the data capacity may be larger than the cache, so it is to retain the required content and release the temporarily unused part. This is also the LRU.
3)internal cache is not compressed, filesystem cache is compressed.

Additional issues to be noted:

  1. The index is compressed in both internal cache and filesystem cache, and the key of the index is compressed.
  2. The impact of filesystem cache on performance is also crucial, so don’t ignore its effect.