Linux system performance analysis (top command) and more accurate interpretation of memory occupancy (free-m command)

Source: Internet
Author: User


I. System performance analysis (Top command)


The top command is a common performance analysis tool under Linux that shows the resource usage of each process in real time, and refreshes the list of processes by default for 5 seconds, so it is similar to the Task manager for Windows.

650) this.width=650; "src=" Http://my.csdn.net/uploads/201207/10/1341935470_9855.jpg "width=" 576 "height=" 445 "style = "border:0px;"/>

Statistical information about the current system as a whole

The top five elements of the first command display are statistical information about the system as a whole.

650) this.width=650; "src=" http://my.csdn.net/uploads/201207/11/1341936016_2341.jpg "style=" border:0px; "/>

The first line is the task queue information, with the execution result of the uptime command. eg.

top-15:09:51 up + days, 3:38, 4 users, Load average:1.09, 3.39, 4.76

15:09:51 Current time
up + days, 3:38 system run time, format last:
4 users currently logged on
Load average:1.09, 3.39, 4.76 system payload, which is the average length of the task queue.
The three values were 1 minutes, 5 minutes, and 15 minutes ago to the present average.

The second to third behavior process and CPU information. When there are multiple CPUs, the content may be more than two lines. eg.

tasks:115 Total, 1 running, sleeping, 0stopped, 0zombie
Cpu (s): 16.1% us, 2.0% sy, 0.0% ni, 79.5% ID, 1.4% wa, 0.0% Hi, 1.0% si

tasks:115 Total   Number of processes
1 running   Running processes
114  Sleeping    number of sleep processes
0  stopped    stop processes
0  Zombie    Zombie process
Cpu (s): 16.1%  US   Percentage of CPU occupied by user space
2.0%  sy    core space occupied CPU percent
0.0%  ni   processes that have changed priority in user process space consume CPU percentage
79.5%  ID   Idle CPU percent
1.4%  wa   Percentage of CPU time waiting for input and output
0.0%  hi
0.0%  si

The last two behavior memory information. eg.

mem:8169876 k Total, 7686472 K used, 483404 K free, 35272 K buffers
swap:4096532 k Total, K-used, 4096372 K free, 2477532 K Cached

mem:8169876 ktotal Total Physical Memory
7686472 K used total amount of physical memory used
483404 k free memory Total
35272 k buffers memory used as the kernel cache
swap:4096532 k Total Total Swap partition
Total swap area used by used K
4096372 k Free swap area total
2477532 K Cached buffers The total number of swap areas.

The in-memory content is swapped out to the swap area and then swapped in to memory, but the used swap area has not been overwritten, which is the size of the swap area where the content already exists in memory. When the corresponding memory is swapped out again, it is no longer necessary to write to the swap area.

Process information

650) this.width=650; "src=" http://my.csdn.net/uploads/201207/11/1341936416_2137.jpg "width=" 566 "height=" 292 "style = "border:0px;"/>

The details of each process are shown below the statistics area. Let's start by understanding the meaning of the columns.

PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND

Ordinal column name meaning
PID Process ID
PPID Parent Process ID
Ruser Realusername
User ID of the UID process owner
Username of user Process Owner
Group Process Owner's name
The terminal name of the TTY startup process. Processes that are not started from the terminal are displayed as?
PR-Priority
The Ninice value. Negative values indicate high priority, positive values indicate low priority
P last used CPU, only meaningful in multi-CPU environment
%cpu percentage of CPU time that was last updated to current
The total CPU time, in seconds, used by the duration process
Total CPU time used by the time+ process, Unit 1/100 sec
Percentage of physical memory used by the%MEM process
The total amount of virtual memory used by the VIRT process, in kilobytes. Virt=swap+res
The swap process uses the amount of virtual memory that is swapped out, in kilobytes.
The size, in kilobytes, of the physical memory used by the RES process and not swapped out. Res=code+data
The amount of physical memory the code executable consumes, in kilobytes per kb
The amount of physical memory that is used outside the data executable code (segment + stack), in kilobytes
SHR shared memory size, in kilobytes
Nflt Number of page faults
NDRT the number of pages that were modified the last time it was written to.

S process state.
d= non-disruptive sleep state
R= Run
S= Sleep
t= Tracking/Stopping
z= Zombie Process

Command name/command line
Wchan If the process is sleeping, the system function name in sleep is displayed
Flags task flag, reference sched.h


Sort by specified column

Top can be set to sort by an item, by default it is sorted by CPU usage,

M, (note upper case), sorted by memory usage

P, sort based on percent CPU usage

T, sorted by Time/accumulated time.


How to end a process

Enter the letter k(lowercase), and then enter the PID you want to kill

Of course you can also run the command directly, kill the PID

Top Other uses

Other uses of top, can be in the top interface, Lose "H", you can go to the top command Help interface



Second, more accurate interpretation of memory occupancy rate (free command)


How to check memory information under Linux, such as the total amount of memory, the amount of usage, can be used.

Often use Windows operating system friends, have been accustomed to if the free memory more, the heart more practical.
When using Linux, it is possible that the Linux physical memory is quickly exhausted (such as when files are accessed frequently) and the memory is not released when the program ends. The lack of free memory of poor, the heart is always not practical.
Unlike Windows, the Linux operating system's memory is managed in a way that Linxu uses as much memory as possible, allowing as much memory to work (doing the cache) to improve performance.
So you see the free memory is always very small, when your program needs more memory, the LINXU system will do cache memory back to you, let you run your program.

Figure 1

650) this.width=650; "Src=" http://dl2.iteye.com/upload/attachment/0092/5529/ 0cd507b7-9d5e-3bd8-a50d-261537c76fb6.jpg "style=" border:0px; "/>

FREE-M: Check the memory situation, (-m) for megabytes.
Total Memory Totals
used the number of memory used (my program uses the amount of memory + the number of internal uses of the system cache)
Free physical memory (real idle, not in use by any program)
Shared memory totals for multiple processes
Buffers the size of the disk cache (buffer cache) (which improves the performance of system I/O calls)
Cached the size of the disk cache (Page cache) (which improves the performance of system I/O calls)
-buffers/cache represents the number of memory that has been used by our program, calculated by: used-buffers-cached
+buffers/cache indicates the number of memory that can also be used by me, calculation method: Free + buffers + Cached

Operating system currently available memory total =free + buffers + cached, is 1155M

Buffers is used to buffer the size of the block device, buffers is used to store the contents of the directory, permissions and so on
Cached is used to buffer files to remember the files we open.


The Cache memory will not be released automatically even after your program has finished running.
This will cause you to read and write files frequently in your Linux system, and you will find that the available physical memory (free) is very small.
In fact, this cache memory is automatically released when you need to use memory, so you don't have to worry about not having memory available.
If you want to release the cache memory manually, there is a way.

manually releasing the cache
---------------------------------------
/proc is a virtual file system, which can be used as a means of communicating with kernel entities through its read and write operations. This means that you can make adjustments to the current kernel behavior by modifying the files in the/proc. Then we can release the memory by adjusting the/proc/sys/vm/drop_caches. The operation is as follows:

Cat/proc/sys/vm/drop_caches Viewing default values

To perform the sync command manually, the Sync command writes all the non-writable system buffers to disk, including modified I-node, deferred block I/O, and read-write mapping files.

# echo 3 >/proc/sys/vm/drop_caches
# cat/proc/sys/vm/drop_caches
3
Set the/proc/sys/vm/drop_caches value to 3

Run the free command again. It can be seen that buffer and cache are released effectively.


Linux system performance analysis (top command) and more accurate interpretation of memory occupancy (free-m command)

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.