One Linux command per day (--free) command

Source: Internet
Author: User

The free command displays the idle, easy-to-use physical memory and swap memory in the Linux system, as well as the buffer used by the kernel. In Linux system monitoring tools, the free command is one of the most frequently used commands.

1. Command format:

free [parameters]

2. Command function:

The free command displays system usage and idle memory conditions, including physical memory, interactive area memory (swap), and kernel buffer memory, and shared memory is ignored

3. Command parameters:

-B Displays memory usage in bytes.

-K displays memory usage in kilobytes.

-m displays memory usage in megabytes.

-G displays memory usage in gigabytes.

-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. Usage examples:

Example 1: Show memory usage

Command: Free

Free-g

Free-m

Description: Total: The overall size of the physical memory.

Used: How large is used.

Free: How much is available.

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

Buffers/cached: The size of the disk cache.

Second line (MEM), which is from the OS point of view, for the OS, buffers/cached are all used, so the OS available memory is not included. The +buffers/cached= memory size used by the kernel (OS) +application (X, ORACLE).

The third line (-/+ buffers/cached), this is from the application perspective, for the application, buffers/cached is equal to the available, because buffers/cached is to improve the performance of the file read, when the application needs to use memory , the buffers/cached will soon be recycled.

So from the application's point of view, available memory = System Free memory+buffers+cached.

Line four is swap memory swap. Why do---exchange, in what way?

When the memory is less than the rated value, it will start to exchange, how to see the rating?

Command: Cat/proc/meminfo

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

1. Reduce the size of the buffer and the page cache

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

3. Swap out or discard pages, (application memory pages, which is insufficient physical memory).

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

That buffers and cached are caches, what's the difference between them?

In order to improve disk access efficiency, Linux has done some careful design, in addition to the Dentry cache (for VFS, speed up the file path name to Inode conversion), but also adopted two main cache methods:

Buffer cache and page cache. The former is for the disk block read and write, the latter for the file inode read and write. This cache effectively shortens the time for I/O system calls (such as read, write,getdents).

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

The page cache is actually for the file system, the file cache, 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, and this mapping is done by the file system. When the page cache data needs to be refreshed, the data in the page cache is given to buffer cache because the buffer cache is the cached disk block. But this kind of processing after the 2.6 version of the kernel has become very simple, there is no real meaning of the flower girl's cache operation.

Buffer cache is a caching of disk blocks that, in the absence of a filesystem, caches data directly into the buffer cache, for example, the file system's metadata is cached in buffer cache.

In short, page cache is used to cache file data, and buffer cache is used to cache disk data. In the case of a file system, the data is cached to the page cache, and if the disk is read and written directly using tools such as DD, the data is cached to buffer cache.

So we look at Linux, as long as no swap swap space, you do not have to worry about their memory too little, if often swap a lot, you might want to consider adding physical memory. This is also the standard for Linux to see if memory is adequate.

In the case of an application server, the general only looks at the second line, +buffers/cache, which is too little memory for the application, and it is time to consider optimizing the program or adding memory.

Example 2: Displaying memory usage information as a sum

Command: FREE-T

Example 3: Periodic query Memory usage information

Command: Free-s 10 does not execute once in 10 seconds.

  

      

One Linux command per day (--free) command

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.