Linux memory command free

Source: Internet
Author: User
[root@centos192 ~]# free             total       used       free     shared    buffers     cachedMem:       3924792    2390256    1534536          0     372432    1623832-/+ buffers/cache:     393992    3530800Swap:      7574520          0    7574520 
1 free output explanation

The default memory unit is kb.

The first line is the title, the second line is the operating system's understanding of the physical memory usage of the machine, the third line is a process's understanding of the physical memory usage of the machine, and the fourth line is the swap partition usage.

First look at the 2nd rows

Total physical memory of the current machine: 3924792kb;

(Used) has used 2390256kb;

There is also 1534536kb which is (free) idle.

Apparently, total = used + free.

Shared is a legacy item reserved for compatibility with the output format. It is meaningless and always 0.

Buffers is the operating system that caches some data to be written to the hard disk to improve Io performance. The size of this part of the memory is buffers.

Like buffers, cached only caches data read from the hard disk.

 

Row 3 shows the memory that can be used by the program, because the operating system can write data from buffers to the hard disk at any time and then release the memory. You can also release the memory of cahced at any time, therefore, these two memories are only required to improve performance. From the perspective of a process, you can ignore the existence of these two parts. The third line is the physical memory usage seen from the perspective of a process, that is to say, the buffers and cached parts are treated as idle and available.

 

The second row refers to the usage of swap partitions. When the physical memory is insufficient, swap partitions are used without further explanation.

2 manually release buffers and cached memory

Before releasing buffers, remember to use sync to update data not written to the hard disk to prevent data loss.

# Sync

# Echo 3>/proc/sys/Vm/drop_caches

Let's take a look at the released results:

[root@centos192 ~]# echo 3 > /proc/sys/vm/drop_caches [root@centos192 ~]# free -m             total       used       free     shared    buffers     cachedMem:          3832        299       3533          0          0         23-/+ buffers/cache:        275       3557Swap:         7396          0       7396

As you can see, buffers is completely released, and some cached may not be released.

/Proc/sys/Vm/drop_caches is a switch. setting its content can control the kernel's processing of the cache. The specific meanings are as follows:

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, unless in special cases, you do not need to manually clear the cache. The operating system should determine how to use the cache.

To change the default system action, you can set the/etc/sysctl. conf file.

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.