Linux Release Memory command usage detailed

Source: Internet
Author: User
Tags memory usage

Running the WebLogic server on a Linux server, but every once in a while, the system memory footprint is more likely to cause performance degradation, which can be resolved by freeing up system memory.

To achieve the goal of freeing caching, we first need to understand the key configuration file/proc/sys/vm/drop_caches. The cache-freed parameter is recorded in this file, with the default value of 0, which is not releasing the cache. His value can be any number between 0~3, representing different meanings:

0– not released
The last page cache release
2– release Dentries and Inodes
3– Releases all Caches

Once we know the parameters, we can use the following instructions to do the work according to our needs.

First we need to use the Sync directive to write all the unused system buffers to disk, including modified I-node, deferred block I/O, and read-write mapping files. Otherwise, unsaved files may be lost during the release of the cache.

#sync

Next, we need to write the required parameters into the/proc/sys/vm/drop_caches file, for example, if we need to release all the caches, enter the following command:

#echo 3 >/proc/sys/vm/drop_caches

This instruction will take effect immediately after input, you can query the current available memory significantly more.

To query the current cache-freed parameters, you can enter the following directive:

#cat/proc/sys/vm/drop_caches

Free system memory by executing the following command:

Sync
Echo 3 >/proc/sys/vm/drop_caches

If it is too much trouble to execute the command every time, you can set up a timed task, automatic execution every once in a while.
Save the above code as a clear_mem.sh file, giving permission to execute

chmod u+x clear_mem.sh

Add timed task, execute

Crontab-e

Tasks are as follows (performed at three O ' Day):

* 3 * * */opt/clear_mem.sh

Save the scheduled task.

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?

Linux <wbr> memory cleanup/release commands

[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

Linux <wbr> memory cleanup/release commands

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
3

! 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

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.