Linux Cleanup Memory command

Source: Internet
Author: User

1. Memory usage before cleanup
Free-m

2. Start cleaning up
Echo 1 >/proc/sys/vm/drop_caches

3. Memory usage after cleanup
Free-m

4. Complete!

To view the number of memory bars command:

# 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 that it is best to sync before releasing to prevent data loss.

Because of the kernel mechanism of Linux, it is generally not necessary to deliberately release the cache that is already in use. These cache contents can increase the file and read and write speed.
Let's see how the free command looks at memory.

[[email protected] 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 state used by the system in a global perspective:
total--Total Physical Memory
used--already uses memory, this value is generally larger because this value includes the memory used by the cache+ application
free--memory that is not fully used
shared--Application Shared Memory
buffers--cache, mainly used for directory aspects, Inode value, etc. (LS Large directory can see this value increase)
cached--cache, for files that have been opened
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 the memory size used by the-buffers/cache--application, used minus the cached value
The latter value indicates the amount of memory +buffers/cache--all available to the application, free plus the cached value
Note
-buffers/cache=used-buffers-cached
+buffers/cache=free+buffers+cached

The third line represents the use of swap:
used--already in use
free--not used

Perform the sync command manually (description: 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 the non-writable system buffers to disk, including modified I-node, deferred block I/O, and read-write mapping files.

[Email protected] test]# echo 3 >/proc/sys/vm/drop_caches
[Email protected] 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 the memory to become
Free.

To free Pagecache with 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

Linux Cleanup Memory command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.