Linux memory cleanup command and linux cleanup command
1. memory usage before cleanup
Free-m
2. Start cleaning
Echo 1>/proc/sys/vm/drop_caches
3. memory usage after cleaning
Free-m
4. Done!
Run the following command to view the number of memory entries:
# Sync
# Echo 1>/proc/sys/vm/drop_caches
Echo 2>/proc/sys/vm/drop_caches
Echo 3>/proc/sys/vm/drop_caches
Release cache:
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: It is best to sync before release to prevent data loss.
Because of the Linux kernel mechanism, you generally do not need to release the used cache. The cached content can increase the file and read/write speed.
Let's talk about how to view memory with 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 usage of the system from a global perspective:
Total -- total physical memory
Used -- memory used. Generally, this value is relatively large because it includes the memory used by the cache + application.
Free -- completely unused memory
Shared-application shared memory
Buffers -- cache, mainly used for directories and inode values (this value can be seen in large ls Directories)
Cached-Cache for opened files
Note:
Total = used + free
Used = buffers + cached (maybe add shared also)
The second line describes the memory usage of the application:
The previous value indicates-buffers/cache-the memory size used by the application, and used minus the cache Value
The last value indicates + buffers/cache-all memory sizes available for the application, free and cache values
Note:
-Buffers/cache = used-buffers-cached
+ Buffers/cache = free + buffers + cached
The third line indicates the usage of swap:
Used -- used
Free -- unused
Run the sync command manually (Description: The sync command runs the sync subroutine. If you must stop the system, run the sync command to ensure the integrity of the file system. The sync command writes all unwritten system buffers to the disk, including modified I-nodes, delayed block I/O, and read/write ing files)
[Root @ server test] # echo 3>/proc/sys/vm/drop_caches
[Root @ server test] # cat/proc/sys/vm/drop_caches
3
! Set/proc/sys/vm/drop_caches 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 that memory to become
Free.
To free pagecache, use echo 1>/proc/sys/vm/drop_caches;
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