View memory footprint with free command in Linux __linux

Source: Internet
Author: User
Tags memory usage

The free command displays the idle, used physical memory and swap memory in the Linux system, and the buffer used by the kernel. In the Linux system Monitoring tool, the free command is one of the most frequently used commands.

1. Command format:

free [parameters]

2. Command function:

The free command displays the system's use and idle memory, including physical memory, interactive area memory (swap), and kernel buffer memory. Shared memory will be ignored

3. Command parameters:

-B Displays memory usage in byte.

-K displays memory usage in kilobytes.

-m displays memory usage in MB.

-G displays memory usage in GB.

-O does not display buffer throttling columns.

-s< interval seconds > Continuous observation of memory usage.

-T displays the memory sum column.

-V Displays version information.

4. Use instance:

Example 1: Displaying memory usage

command:

Free

Free-g

Free-m

Output:

[Root@sf1150 service]# Free

Total used free shared buffers Cached

mem:32940112 30841684 2098428 0 4545340 11363424

-/+ buffers/cache:14932920 18007192

swap:32764556 1944984 30819572

[Root@sf1150 service]# Free-g

Total used free shared buffers Cached

Mem:31 29 2 0 4 10

-/+ buffers/cache:14 17

Swap:31 1 29

[Root@sf1150 service]# Free-m

Total used free shared buffers Cached

mem:32168 30119 2048 0 4438 11097

-/+ buffers/cache:14583 17584

swap:31996 1899 30097

Description:

The following is an explanation of these values:

Total: The amount of physical memory.

Used: How big it has been used.

Free: How many are available.

Shared: The total amount of memory shared by multiple processes.

Buffers/cached: The size of the disk cache.

(-buffers/cache) used memory: Refers to the first part of the Mem line in the used-buffers-cached
(+buffers/cache) Free memory: Refers to the first part of the Mem line in the Free + buffers + Cached
Visible-buffers/cache reflects the memory that is actually eaten by the program, and +buffers/cache reflects the total amount of memory that can be misappropriated.

The Forth line is swap partition swap, which is what we usually call virtual memory.

Difference: The difference between the used/free of the second line (MEM) and the used/free of the third row (-/+ Buffers/cache). The difference between the two is that the first line is from the OS point of view, because for os,buffers/cached is used, so his available memory is 2098428KB, the used memory is 30841684KB, which includes, the kernel (OS) uses + Application (X, oracle,etc) used by +buffers+cached.

The third line refers to the application from the point of view of the application, buffers/cached is equal to available, because buffer/cached is to improve the performance of file read, when the application needs to use memory, the buffer/cached will be quickly recycled.

So from an application perspective, the available memory = System Free memory+buffers+cached.

The available memory, such as the native case, is:

18007156=2098428kb+4545340kb+11363424kb

then explain when memory will be exchanged and by what side.

When the available memory is less than the rated value, the meeting is exchanged. How to look at the rating:

Command:

Cat/proc/meminfo

Output:

[Root@sf1150 service]# Cat/proc/meminfo

memtotal:32940112 KB

memfree:2096700 KB

buffers:4545340 KB

cached:11364056 KB

swapcached:1896080 KB

active:22739776 KB

inactive:7427836 KB

hightotal:0 KB

highfree:0 KB

lowtotal:32940112 KB

lowfree:2096700 KB

swaptotal:32764556 KB

swapfree:30819572 KB

dirty:164 KB

writeback:0 KB

anonpages:14153592 KB

mapped:20748 KB

slab:590232 KB

pagetables:34200 KB

nfs_unstable:0 KB

bounce:0 KB

commitlimit:49234612 KB

committed_as:23247544 KB

vmalloctotal:34359738367 KB

vmallocused:278840 KB

vmallocchunk:34359459371 KB

hugepages_total:0hugepages_free:0hugepages_rsvd:0hugepagesize:2048 KB

Swapping will reduce the number of physical pages used in the system in three ways:

1. Reduce buffer and page cache size,

2. Swap the System V type of memory page out,

3. Swap or discard the page. (The memory page that application occupies, that is, insufficient physical memory).

In fact, a small amount of swap use does not affect system performance.

that buffers and cached are all caches, what's the difference between them.

In order to improve disk access efficiency, Linux has done a number of careful design, in addition to the Dentry cache (for VFS, speed file path name to the Inode conversion), but also took two main Cache: Buffer cache and Page cache. The former is read and write to disk block, the latter is read and write to the file inode. These cache effectively shorten the time of the I/O system call (such as read,write,getdents).

The operation of a disk has a logical level (file system) and a physical level (disk block), both of which cache logical and physical level data separately.

Page cache is actually for the file system, the cache of files, and the data at the file level is cached to page cache. The logical layer of the file needs to be mapped to the actual physical disk, which is done by the file system. When page cache data needs to be refreshed, the data in page cache is given to the buffer cache, because buffer caches are cached disk blocks. But this processing in the 2.6 version of the kernel after the change is very simple, there is no real sense of the cache operation.

Buffer cache is for disk block caching, that is, in the case of no file system, directly to the operation of the disk data will be cached in buffer cache, for example, file system metadata will be cached in buffer cache.

Simply put, page cache is used to cache file data, and buffer caches are used to cache disk data. In the case of a file system, the file operation, then the data will be cached to page cache, if the direct use of DD and other tools to read and write the disk, then the data will be cached to buffer cache.

So we look at Linux, as long as the swap space without swap, there is no need to worry about their own memory too little. If you use a lot of swap, you might want to consider adding physical memory. This is also the standard for Linux to see if memory is enough.

If it is an application server, usually only look at the second line, +buffers/cache, that is, for the application free memory is too little, it is also to consider the optimizer or add memory.

Instance 2: Displays memory usage information as a sum

command:

Free-t

Output:

[Root@sf1150 service]# Free-t

Total used free shared buffers Cached

mem:32940112 30845024 2095088 0 4545340 11364324

-/+ buffers/cache:14935360 18004752swap:32764556 1944984 30819572total:65704668 32790008 oot@sf1150 service]#

Description:

Example 3: Periodic query memory usage information

command:

Free-s 10

Output:

[root@sf1150 service]# free-s 10

Total used free shared buffers Cached

mem:32940112 30844528 2095584 0 4545340 11364380

-/+ buffers/cache:14934808 18005304swap:32764556 1944984 30819572

Total used free shared buffers Cached

mem:32940112 30843932 2096180 0 4545340 11364388

-/+ buffers/cache:14934204 18005908swap:32764556 1944984 30819572

Description:

Execute one command per 10s

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.