how to release the caching which is used by Mongodb?

Starting in 3.2, MongoDB uses the WiredTiger as the default storage engine. Previous versions used the MMAPv1 as the default storage engine.

With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache. In MongoDB 3.2, the WiredTiger internal cache, by default, will use the larger of either: 60% of RAM minus 1 GB, or 1 GB. For systems with up to 10 GB of RAM, the new default setting is less than or equal to the 3.0 default setting (For MongoDB 3.0, the WiredTiger internal cache uses either 1 GB or half of the installed physical RAM, whichever is larger). For systems with more than 10 GB of RAM, the new default setting is greater than the 3.0 setting.


to limit the wiredTriggered Cache Add following line to .config file :

wiredTigerCacheSizeGB = 1


We were experiencing a similar issue on a live/production server which was a member of a replica set, so restarting the process was not an option. Eventho it is not a good idea to flush RES memory (Residence memory), in our use case we had to do it, via following command:

yes | tr \\n x | head -c $((1024*1024*1000)) | grep n

It create a process that will take over the RAM for 1GB, forcing mongodb to release memory for this process. This was for a system with 2GB of ram. If for example your system is using 20GB of RAM, you might need to run this for 10GB or 15GB:

yes | tr \\n x | head -c $((1024*1024*15000)) | grep n

MongoDB will (at least seem) to use up a lot of available memory, but it actually leaves it up to the OS's VMM to tell it to release the memory (see Caching in the MongoDB docs.)

You should be able to release any and all memory by restarting MongoDB.

However, to some extent MongoDB isn't really "using" the memory.

For example from the MongoDB docs Checking Server Memory Usage ...

Depending on the platform you may see the mapped files as memory in the process, but this is not strictly correct. Unix top may show way more memory for mongod than is really appropriate. The Operating System (the virtual memory manager specifically, depending on OS) manages the memory where the "Memory Mapped Files" reside. This number is usually shown in a program like "free -lmt".

It is called "cached" memory.

MongoDB uses the LRU (Least Recently Used) cache algorithm to determine which "pages" to release, you will find some more information in these two questions ...

  • MongoDB limit memory
  • MongoDB index/RAM relationship
  • Mongod start with memory limit (You can't.)