Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to release the caching which is used by Mongodb?

Tags:

Mongodb use the Memory Mapped File ,when I use a long time , I see the free memory has left less by command 'free -m' in ubuntu and the caching use a lot. Then kill the Mongodb the caching still cost a lot ? how can I release the caching ?

like image 447
Ted Avatar asked Dec 17 '10 08:12

Ted


People also ask

Does MongoDB use caching?

Does MongoDB handle caching? Yes. MongoDB keeps most recently used data in RAM. If you have created indexes for your queries and your working data set fits in RAM, MongoDB serves all queries from memory.

Does MongoDB have in-memory cache?

The short answer is MongoDB relies on both its internal memory caches as well as the operating system's cache. The OS cache generally is seen as “Unallocated” by sysadmins, dba's, and devs. This means they steal memory from the OS and allocate it internally to MongoDB.


1 Answers

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.)
like image 180
Justin Jenkins Avatar answered Sep 20 '22 14:09

Justin Jenkins