Linux Memory usage detailed

Source: Internet
Author: User

The results of the free command are as follows:

i2000:~ # free       total used       free     shared    buffers     cachedmem:      24157516   23714828     442688    7100040     881324   18425668-/+ buffers/cache:    4407836   19749680Swap:     12583332     178792   12404540

  

First line (can be understood as memory allocation from the operating system perspective)

Total

Total physical memory size.

Used

The allocated size, note that any memory used by the operating system is used.

Free

The size of the physical memory that has not been allocated.

Shared

Shared memory size, used primarily for interprocess communication, such as Oracle using up to GB of shared memory.

Buffers

It is mainly used for block device data buffering, such as recording the metadata (directory, permissions, etc.) of the file system.

Cached

Primarily for file content buffering

# Add a bit of common sense about file systems here ^_^

The file system can actually be roughly divided into two parts:

# (1) metadata: Commonly said metadata, including directory structure, file name, size, modification time, permissions and so on information.

# (2) Filedata: The content that is actually stored in the file.

# Because of the speed difference between the various parts of the computer, usually the cache of the fastest CPU, followed by memory, the slowest natural is the hard disk and other external devices.

# and the slower the cheaper the device, so the hard disk is used to store a large amount of data (one day the memory is not the money we will not be in the buffer, the cache this East < ( ̄︶ ̄) >).

# So the file system is placed on the hard drive (the inevitable tragedy ~ ~). But because the hard disk speed is too slow, in order to improve the IO performance, the end of the birth of the "cache" concept.

# "Cache" is actually in memory partition area as a buffer between the hard disk and process, write process to write the data here and then do other things, read the process need to find here first, can not find the hard disk, so that greatly improve the read and write efficiency, while shortening the IO waiting time, Otherwise you'll be waiting for n long when you run a command like Man iptables on Linux ...

# Here is also a "physical memory" and "virtual memory" concept, this concept is more difficult to say, we go to Google some Daniel's posts to see, involved in too many things ....

So, here, buffer is actually used to store the file system's metadata (so that we each time LS will quickly ^_^), and the cache caches the recently read-write files (the first time the file will be very slow, will soon, because there is a cache), This understanding of the free command is half the comprehension.

Second line (can be understood as memory allocation from an application perspective)

-/+ buffers/cached: 22556 102232

Here the-/+ actually refers to the--buffers/cached and + buffers/cached two parts respectively.

-Buffers/cached

= Used (first line)-buffers-cached

is actually the size of the "physical Memory" of the program's current "real use".

+ buffers/cached

= buffers + Cached

The combination of the two can be interpreted as "temporarily lending" the memory size used by the system as a "buffer".

The simple addition and subtraction of everyone is clear:

From an application perspective, the system can actually allocate so much memory to him:11356 (free) + 15308 (buffers) + 75568 (cached) = 102232 (free)

And the total physical memory size of the system 113432 = 22556 (-buffers/cached) + 102232 (+ buffers/cached)

So the first row of data is actually viewed from the operating system perspective.

The allocated memory representation of the operating system has been occupied by some data, but the specific data is used to do what he will not bother.

In fact, as previously mentioned, this part of the physical memory is taken to be "cached".

The shell script is:

#!/bin/bash#from os viewos_used=$ (Free | grep "mem" | awk ' {print $} ') total=$ (free | grep "mem" | awk ' {print $} ') Os_rat E=$ (echo "scale=4; $os _used/$total" |BC) percent_part1=$ (echo $os _rate | cut-c 2-3) percent_part2=$ (echo $os _rate | cut-c 4 -5) echo "Operation system Memery is already use: $percent _part1. $percent _part2%" #from user viewuser_free_tmp=$ (Free | gre P "Mem:" | awk ' {print $4 ' "$6" "$7} ') user_free=$ (echo $user _free_tmp | awk ' {print $1+$2+$3} ') user_used= ' expr $total-$user _free ' user_rate=$ (echo "scale=4; $user _used/$total" |BC) part1=$ ( echo $user _rate | Cut-c 2-3) part2=$ (echo $user _rate | cut-c 4-5) echo "User system Memery is already use: $part 1. $part 2%"

  

Linux Memory usage detailed

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.