When you use free-m to view the server memory during server running, it is often found that the free value is very small, and some students are very nervous and always want to take some measures, so that the free value looks a little higher, it is a bit better. In fact, I personally think this is just a quick time, and there is no substantive purpose.
I. Volkswagen memory release method
1. First use free-m to view the remaining memory
View plaincopy to clipboardprint?
Linux-8v2i :~ # Free-m
Total used free shared buffers cached
Mem: 3952 2773 178 0 130 1097
-/+ Buffers/cache: 1545 2406
Swap: 2055 0 2055
Linux-8v2i :~ # Free-m
Total used free shared buffers cached
Mem: 3952 2773 178 0 130 1097
-/+ Buffers/cache: 1545 2406
Swap: 2055 0 2055
2. Run the sync command.
Use the sync command to ensure the integrity of the file system. Run the sync command to run the sync subroutine and write all unwritten system buffers to the disk, contains modified I-node, delayed block I/O, and read/write ing files.
View plaincopy to clipboardprint?
Linux-8v2i :~ # Sync
Linux-8v2i :~ # Sync
3. Modify/proc/sys/vm/drop_caches
View plaincopy to clipboardprint?
Echo 3>/proc/sys/vm/drop_caches
Echo 3>/proc/sys/vm/drop_caches
Note:
1>./proc is a virtual file system. We can use its read/write operations as a means of communication with the kernel object. In other words, you can modify the file in/proc to adjust the current kernel behavior. In other words, we can adjust/proc/sys/vm/drop_caches to release the memory.
2>. Official descriptions of drop_caches are as follows:
Writing to this file causes the kernel to drop clean caches, dentries and inodes from memory, causing that memory to becomefree.
To free pagecache, use echo 1>/proc/sys/vm/drop_caches;
To free dentries and inodes, use echo 2>/proc/sys/vm/drop_caches;
To free pagecache, dentries and inodes, use echo 3>/proc/sys/vm/drop_caches.
Because this is a non-destructive operation and dirty objects are not freeable, the user shocould run sync first.
3>. the Linux kernel caches the recently accessed file pages in the memory for a period of time. This File Cache is called pagecache.
4. Use free-m to view the remaining memory as follows:
View plaincopy to clipboardprint?
Linux-8v2i :~ # Free-m
Total used free shared buffers cached
Mem: 3952 1773 2325 0 0 80
-/+ Buffers/cache: 1545 2406
Swap: 2055 0 2055
Linux-8v2i :~ # Free-m
Total used free shared buffers cached
Mem: 3952 1773 2325 0 0 80
-/+ Buffers/cache: 1545 2406
Swap: 2055 0 2055
Ii. Linux memory Analysis
1. First, analyze the free-m view results
View plaincopy to clipboardprint?
Linux-8v2i :~ # Free-m
Total used free shared buffers cached
Mem: 3952 2773 178 0 130 1097
-/+ Buffers/cache: 1545 2406
Swap: 2055 0 2055
Linux-8v2i :~ # Free-m
Total used free shared buffers cached
Mem: 3952 2773 178 0 130 1097
-/+ Buffers/cache: 1545 2406
Swap: 2055 0 2055
Meanings of parameters:
Total: total physical memory
Used: memory used
Free: completely unused memory
Shared: application shared memory
Buffers: cache, mainly used for directories, inode values, etc.
Cached: cache for opened files
-Buffers/cache: memory size used by the application, used minus the cache Value
+ Buffers/cache: memory size available for all supply applications, free plus cache Value
Where:
Total = used + free
-Buffers/cache = used-buffers-cached, which is the actual memory size used by the application.
+ Buffers/cache = free + buffers + cached, which is the actual available memory size of the server
2. Linux memory allocation method
We all know that the Linux server will apply for memory in advance to improve efficiency. Even if the memory is not used by specific applications, Linux will apply for the memory in advance and use the memory for caching, the file system that is about to be opened will be saved to the cache, so that the free value of the corresponding server will become fewer and fewer, and the buffers and cached will become larger and larger, so we can see that the memory will become fewer and fewer, everyone is nervous. In fact, we don't need to be nervous at all. When the Linux server finds that the memory is insufficient, it will automatically clean up the cached area, release the memory, and then continue to increase the cache, free and continue to decrease. Therefore, the way to manually reduce the memory usage is actually a quick one.