Linux Cleanup Memory command detailed introduction _linux

Source: Internet
Author: User
Tags memory usage

Linux Cleanup Memory command

1. Memory usage before cleaning

Free-m

2. Start cleaning up

Echo 1 >/proc/sys/vm/drop_caches

3. Memory usage after cleaning

Free-m

4. Finish it!

To view the number of memory lines command:

# Sync
# echo 1 >/proc/sys/vm/drop_caches
 echo 2 >/proc/sys/vm/drop_caches
 echo 3 >/proc/sys/v M/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,
Dentrie S and inodes from memory, causing this 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

Thank you for reading, I hope to help you, thank you for your support for this site!

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.