Linux view memory and how mongodb uses memory

1.
Linux memory check
Use the free command to check the memory usage
shell>free -m + Enter to
display the memory

total: the total size

of the physical memory used: the size of the physical memory that has been used

free: the size of the free physical memory

shared: shared by multiple processes The memory size of

buffers/cached: the size of the disk cache. The

second line Mem: represents the physical memory usage.

The third line (-/+ buffers/cached): represents the disk cache usage status.

The fourth line: Swap represents the swap space memory usage

status . If you see that the value in the used column is too large, and the value in the free column is too small, you often think that the memory is used up. In fact, this is not the case. The reason for this is that whenever we operate a file, Linux will cache the file in the memory as much as possible, so that the next time we access, we can directly fetch the result from the memory, so the cached column The value is very large, but don't worry, this part of memory is recyclable, and the virtual memory manager of the operating system will eliminate cold data according to the LRU algorithm. There is also a buffer, which is also recyclable, but it is reserved for block devices.

We can calculate that the available memory of the system is free + buffers + cached: 2723+239+25880=28842

The actual memory used by the system is used – buffers – cached: 29377-239-25880=3258

2.
How mongodb uses memory:
mongodb Using a memory-mapped storage engine,

It will map the data file to the memory. If it is a read operation, the data in the memory acts as a cache. If it is a write operation, the memory can also convert random write operations into sequential write operations. In short, it can be greatly improved. performance. MongoDB does not interfere with memory management work, but leaves these tasks to the virtual memory manager of the operating system. The advantage of this is to simplify the work of MongoDB, but the disadvantage is that you have no way to easily control how much memory MongoDB occupies. , Fortunately, the existence of the virtual memory manager makes us do not need to care about this problem most of the time.
MongoDB's memory usage mechanism makes it more advantageous in cache reconstruction. In short: if the process is restarted, the cache is still valid. If the system is restarted, the cache can be reconstructed by copying the data files to /dev/null

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326402993&siteId=291194637