linux memory cleanup release command

linux memory cleanup release command

1. Memory usage before cleaning

free -m

2. Start cleaning

echo 1 > /proc/sys/vm/drop_caches

3. Memory usage after cleaning

free -m

4. Done!

View the number of memory bars 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, it is best to sync before release to prevent data loss.

Because of the kernel mechanism of LINUX, in general, there is no need to release the cache that has been used. These cached contents can increase the read and write speed of files and files.
Let me talk about how to see the memory with the free command

[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 status used by the system from a global perspective:

total - total physical memory

used——used memory, in general, this value will be relatively large, because this value includes

cache + memory used by the application free - completely unused memory

shared - application shared memory

buffers——caching, mainly used for directories, inode values, etc. (ls large directories can see a value increase)

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 represents -buffers/cache—the memory size used by the application, and the
second value after the used minus the cache value represents +buffers/cache—all the memory available for the application Size, free plus cached value

note:
   -buffers/cache=used-buffers-cached
   +buffers/cache=free+buffers+cached

The third line indicates the use of swap:

used - used

free - not used

Manually execute 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 unwritten system buffers to disk, including modified i-nodes, delayed block I/O, and read-write mapped files)

[root@server test]# echo 3 > /proc/sys/vm/drop_caches
[root@server test]# cat /proc/sys/vm/drop_caches
3 

! Set the /proc/sys/vm/drop_caches value to 3

The usage of /proc/sys/vm/drop_caches is explained 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; 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

Guess you like

Origin blog.csdn.net/T_LOYO/article/details/128609691