This article describes the Linux memory cleanup/release commands, as follows:
1. Memory usage before cleaning
2. Start cleaning up
Echo 1 >/proc/sys/vm/drop_caches
3. Memory usage after cleaning
4. Finish it!
To view the number of memory lines command:
Dmidecode | Grep-a16 "Memory device$"
# sync
# echo 1 >/proc/sys/vm/drop_caches
echo 2 >/proc/sys/vm/drop_caches
echo 3 >/proc/sys/vm/drop_caches
Cache release:
To free Pagecache:
Echo 1 >/proc/sys/vm/drop_caches
To-free dentries and inodes:
Echo 2 >/proc/sys/vm/drop_caches
To free Pagecache, dentries and Inodes:
Echo 3 >/proc/sys/vm/drop_caches
Note, the best sync before release, to prevent loss of data.
Because the Linux kernel mechanism, generally do not need to deliberately release the cache already used. These cache content can increase the file and read and write speed.
How do I look at the memory at the free command first?
[Root@yuyii proc]# free
total used free shared buffers cached mem:515588 295452
220136 0 2060 64040
-/+ buffers/cache:229352 286236
swap:682720 112 682608
The first line describes the memory conditions used by the system in a global perspective:
total--Total Physical Memory
used--has used memory, this value will be larger in general, because this value includes the memory used by the cache+ application
free--memory that is completely unused
shared--Application Shared Memory
buffers--cache, mainly used in the directory, Inode value, etc. (LS Large directory can see this value increase)
cached--cache, for open files
Note
Total=used+free
used=buffers+cached (maybe add shared also)
The second line describes the application's memory usage:
The previous value represents the memory size used by the-buffers/cache--application, used minus the cached value
The latter value represents the amount of memory that +buffers/cache--can use for the application, free plus the cached value
Note
-buffers/cache=used-buffers-cached
+buffers/cache=free+buffers+cached
The third line indicates the use of swap:
used--already used
free--not used
Manually perform the sync command (description: The sync command runs the Sync subroutine.) If the system must be stopped, run the sync command to ensure the integrity of the file system. The Sync command writes all of the unused system buffers to disk, including modified I-node, deferred block I/O, and read-write mapping files.
[Root@server test]# echo 3 >/proc/sys/vm/drop_caches
[root@server test]# cat/proc/sys/vm/drop_caches
! Set the/proc/sys/vm/drop_caches value to 3
The usage of/proc/sys/vm/drop_caches is described below
/proc/sys/vm/drop_caches (since Linux 2.6.16)
Writing to this file causes the kernel to drop clean caches,
Dentries and inodes from memory, causing which memory to become
Free.
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
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.