Linux command (002)--Free

Source: Internet
Author: User

First, the preparation of knowledge

Linux and Windows systems differ greatly in memory management mechanisms. In Linux often found that the free memory is very small, it seems that all the memory is occupied by the system, the surface of the memory is not enough to use, it is not. This is an excellent feature of Linux memory management, which differs from Windows memory management in this regard. The main feature is that no matter how large the physical memory is, Linux is fully utilized to read some program-called hard disk data into memory, using the high-speed features of memory read and write to improve the data access performance of Linux system. Instead, Windows allocates memory for the application only when it needs memory, and does not take full advantage of the large capacity of the memory space.

In a Linux system, there is also the concept of a swap partition. The purpose of the swap partition is to swap the memory block information temporarily unused by the system kernel into the swap partition, freeing up physical memory. When you need to use this part of the data, you can swap that part of the information from the swap partition into physical memory.
(1), the system will occasionally make a page exchange operation to maintain as much free physical memory as possible, even if there is no need for memory, Linux will also swap out the memory of the temporarily unused pages. This avoids the time required to wait for the interchange.
(2), the page exchange based on some type of "LRU" algorithm.

Second, Memory monitoring command--free

The free command is used to display the amount of memory used and idle in the system. Take a look at the description of the free command in the man page: "The use and idle of the physical memory in the system and the use and idle of the swap partition are displayed." ”

#语法free [-B |-k |-m |-G |-h] [-O] [-s delay] [-c Count] [-a] [-t] [-l] [-v] #选项-B: Display memory in bytes-K: Display memory in KB-M: units showing memory For M-o: Ignore-/+ buffers/cache line-t: Sum information-s< time;: Executes a command every specified time, in S-h: Displays capacity in readable form, requires free-v display version greater than 3.3-V: version information

Third, free command output analysis

# free-m       Total used       free     shared    buffers     cachedmem:          7871       1851       6020          0       1419-/+ buffers/cache:       7551Swap:         8191          0       8191

The free command column means:
Total: Overall size of physical memory
Used: The amount of physical memory already in use
Free: idle physical memory size
Shared: The amount of memory that multiple processes share
buffers/cached: Size of the disk cache

The free command line means:
Second line of Mem: representing physical memory usage
Third row (-/+ buffers/cached): Represents the disk cache usage status
Line four: Swap indicates swap space memory usage state

The memory state of the free command output can be viewed in two angles: one from the kernel point of view, one from the application layer perspective.

(1), from the kernel point of view system memory usage Status:
Refers to the kernel currently can be directly assigned to, do not need additional operations, namely the free command output of the second line of Mem value, from the above output can be seen: The total system memory 7871MB, has used 1851MB, the remaining 6020MB. namely: 7871-1851=6020

(2), from the point of view of the application layer system memory usage state
Refers to the amount of memory that an application running on the system can use, that is, the output of the third row of-/+ buffers/cached in the output of the free command, and you can see that the memory used by the system is 320MB, while the idle memory reaches 7551MB. That is: 6020+110+1419=7549MB, for the application, buffers/cached occupies the memory is available, because buffers/cached is to improve the performance of the file read, when the application needs to use memory, buffers/ Cached will be quickly recycled for use by the application.

Iv. the similarities and differences between buffer and cache

Buffers and cached are memory operations that are used to save files and file attribute information that have been opened by the system, so that when the operating system needs to read some files, it will first look in the buffers and cached memory areas, and if found, read them directly to the application. If you do not find the data needed to read from disk, this is the operating system caching mechanism, through the cache, greatly improve the performance of the operating system. But the content of buffers and cached buffer is different.

Buffers is used to buffer the block device, it only records the file system metadata (metadata) and tracking in-flight pages, and cached is used to buffer the file. More commonly said: buffers is mainly used to store content in the directory, file attributes and permissions and so on. and cached is used directly to memorize the files and programs we have opened.

Linux command (002)--Free

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.