A summary of memory exhaustion:
1) before the process receives an oom, the kernel refreshes the file system's cache to free up space.
2) Move the Swap area page to disk.
3) When memory becomes small, virtualization enables each process to make a simple context switch through the swap area.
4) Out-of-memory (OOM) is raised to kill those processes when the process consumes the memory to swap.
Therefore, we still need to manually do the release of memory under Linux operation, in fact, the release of the cache operation.
To achieve the purpose of releasing the cache, we first need to understand the key configuration file/proc/sys/vm/drop_caches. This file records the parameters of the cache release, the default value is 0, which is not to release the cache. His value can be any number between 0~3, which represents a different meaning:
0– not release
-Free Page Cache
Release Dentries and Inodes
3– Release All Caches
Once we know the parameters, we can use the following instruction to operate according to our needs.
First we need to use the Sync command to write all the non-writable system buffers to disk, including modified I-node, deferred block I/O, and read-write mapping files. Otherwise, unsaved files may be lost during the release of the cache.
# Sync
Next, we need to write the required parameters into the/proc/sys/vm/drop_caches file, for example, we need to release all the caches, enter the following command:
# echo 3 >/proc/sys/vm/drop_caches
This command will take effect immediately after input, can query the current available memory significantly more.
To query the parameters released by the current cache, you can enter the following directives:
# cat/proc/sys/vm/drop_caches
Overview of Swap
The role of swap can be described simply as:
When memory is not enough, the data blocks in the memory are moved from DRAM to the swap disk space to free up more space for the current process to use.
When that data is needed again, the data in the swap disk can be re-moved to memory, and the unused chunks of data are moved from memory to swap.
2) The behavior of data from the memory mobile swap area is called a page call, and the page that occurs in the background is called without interference from the application.
3) Swap space is paged, and the size of each page is the same as the size of the memory page.
4) It's not necessarily a swap for each system, like most embedded without swap.
# #在执行以上操作以后, check your swap partition or full, you first look at how much space you actually have left in the memory, and then in view of your swap space with how much, first of all in advance to ensure that the actual remaining memory than your swap memory space is larger, and then perform the operation, otherwise it will go down!
First we stop the swap partition,
Will check to see where your swap partition is hanging!
# swapon-s
And then, for example, mine is hanging to/dev/dm-1.
# swapoff/dev/dm-1
It takes a while to stop, because he will release the memory into the actual memory,
And then start our swap partition.
# swapon-a
Our swap partition memory has been successfully released into real memory!
This article is from the "Home_tang" blog, make sure to keep this source http://yagetang.blog.51cto.com/1780698/1743066
Free memory under Linux, swap swap cache