New notes-view memory usage in linux

Source: Internet
Author: User

New notes-view memory usage in linux

There are various software on windows that can perform operations such as "one-click acceleration" and release some memory (although I do not know what to do for the time being, I need to learn it later ). The task manager can also conveniently view the memory usage of various processes, such:

 

Similarly, there are some methods in linux to view memory usage.

 

 

I. free

For the free command, you can add the-m parameter so that the display unit is Mb. As follows:

[ccx@ubuntu ~]$>free             total       used       free     shared    buffers     cachedMem:       1008504     547364     461140      12836      53984     254508-/+ buffers/cache:     238872     769632Swap:      1046524          0    1046524

 

[ccx@ubuntu ~]$>free -m             total       used       free     shared    buffers     cachedMem:           984        534        450         12         52        248-/+ buffers/cache:        233        751Swap:         1021          0       1021

 

Some nouns appear here, some of which I don't know. I specifically checked their meanings.

 

  Total Used Free Shared Buffers Cached
Mem Total physical memory

Indicates the total quantity allocated to the cache (including buffers and cache), but some of the caches are not actually used.

Unallocated memory Shared Memory Number of buffers allocated by the system but not used Number of cache allocated but not used by the System
    The actual amount of buffers and cache used is also the actual total amount of memory used. The sum of unused buffers, cache, and unallocated memory, which is the actual available memory of the system.      
Swap            

 

What is the difference between buffers and cache?

So I checked some information and found that buffers is actually called "buffer". The English explanation is:A buffer is something that has yet to be "written" to disk.

That is to say, buffers will write data into the hard disk cache.

The cache explanation is as follows:A cache is something that has been "read" from the disk and stored for later use.

That is to say, the cache reads data from the hard disk or storage device into the computer and then caches the data in the memory.

When I think of computer composition principles, I can see that Intel's cpu and memory have caches. What is the difference between them.

Continue to query the data and find the page cache and 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, operations on the file will cache the data to the page cache. If you directly use dd or other tools to read and write the disk, the data will be cached to the buffer cache.

For cache and buffer, cached is between the cpu and the memory, and the buffer is between the memory and the disk to solve the problem of unequal speed.

In free, buffer is the memory of the buffer cache, the read and write buffer of Block devices, and the cache is the memory of the page cache and the cache of the file system.

I will not talk about the buffer and chche here. The final link 5 is quite clear.

 

There is also a term, Swap, that is, virtual memory. When the physical memory is insufficient, it is necessary to release some space for the current running program to use. The released memory data is temporarily stored in the virtual memory. However, not all data is saved. Only those objects generated using malloc or new do not have the corresponding "reserve" file in the file, which is called anonymous memory data, it must be temporarily stored in Swap. Therefore, Swap is also called an anonymous data exchange space. See the description in link 3.

As for shared, no relevant information is found, but it is not commonly used in a link.

 

Links for learning:

1. http://www.splaybow.com/post/linuxmemusage.html

2. http://ludihua.blog.51cto.com/4601284/1569816

3. http://www.cnblogs.com/my_life/articles/4629555.html

4. http://www.jb51.net/LINUXjishu/10945.html

5. http://www.cnblogs.com/chenpingzhao/p/5161844.html

 

 

Ii. top Command

The top command is like "Task Manager in linux ":

 

 

The content of the first line is the same as that of the uptime command.

[ccx@ubuntu ~]$>uptime 10:05:01 up 34 min,  1 user,  load average: 0.00, 0.11, 0.16

 

The terms in the second line are also quite understandable, that is, the total number of processes and the number of processes in the R, S, T, and Z states:

Tasks Total Running Sleeping Stopped Zombie
  Total Run Waiting (sleep) Pause Botnets
  181 2 179 0 0

 

The third line is the CPU usage, as shown below:


 

% Cpu (s)  
Us CPU usage percentage of user space
Sy CPU usage of kernel space
Ni CPU usage percentage of processes that have changed their priorities in the process space
Id Idle CPU percentage
Wa Percentage of CPU time waiting for Input and Output
Hi Total time spent on CPU service hardware interruption
Si Total time spent on Soft Interrupt of CPU Service
St Steal Time

 

 

 

The fourth line is the memory usage, similar to the free command.

 

Then the meaning of the list:

 

PID Process ID
USER Process owner
PR Priority
NI Nice value, negative value indicates high priority, positive value indicates low priority
VIRT Total virtual memory used by the Process
RES Physical memory used by the process, not swapped out
SHR Shared Memory size
S Process status
% CPU CPU usage from the last update to the present
% MEM Percentage of physical memory used by the Process
TIME + Total CPU usage time of processes
COMMAND Command name and command line

 

 

 

By default, only important information is displayed. On the TOP page, press f to modify the displayed content. I don't quite understand this interface, so I won't describe it.

 

Links for learning:

Http://bbs.linuxtone.org/forum.php? Mod = viewthread & tid = 1684 & fromuid = 34304

Http://jingyan.baidu.com/article/4d58d5412917cb9dd4e9c0ed.html

 

 

Iii. vmstat command

[ccx@ubuntu ~]$>vmstatprocs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st 0  0     76 187932 154112 372228    0    0   143    32   36   90  1  1 94  3  0

 

The specific parameters are as follows:

R The number of processes waiting for run time. Number of kernel threads in the running Queue (number of processes ).
B The number of processes in uninterruptible sleep. Number of kernel threads placed in the waiting queue (waiting for resources, waiting for input/output. Number of uninterruptible processes in the block queue
Swpd The amount of virtual memory used. Available virtual swap memory
Free The amount of idle memory. Idle memory
Buff The amount of memory used as buffers. Buffer Used
Cache The amount of memory used as cache. Cache used
Si Amount of memory swapped in from disk (/s ). Number of swap pages from disk to memory (Unit/S)
So Amount of memory swapped to disk (/s ). Number of pages switched from swap memory to disk (Unit/S)
Bi Blocks received ed from a block device (blocks/s ). Number of blocks received by the block device (Block/second)
Bo Blocks sent to a block device (blocks/s ). Number of blocks sent to the block device (Block/second)
In The number of interrupts per second, including the clock. Number of interrupts per second, including clock interruptions
Cs The number of context switches per second. Context switches per second
Us Time spent running non-kernel code. (user time, including nice time) User time, percentage of time in user mode
Sy Time spent running kernel code. (system time) System Time, percentage of time in kernel mode
Id Time spent idle. Prior to Linux 2.5.41, this includes des IO-wait time. CPU idle time, percentage of idle time
Wa Time spent waiting for IO. Prior to Linux 2.5.41, sorted in idle. CPU idle time, during which the system has unfinished Disk/nfs I/O requests
Wt Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown. Percentage of CPU stolen from the Virtual Machine (this will not translate ...)

 

 

Links for learning:

Http://blog.csdn.net/zhuying_linux/article/details/7336869

Http://www.cnblogs.com/ggjucheng/archive/2012/01/05/2312625.html

 

 

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.