Linux Process Memory Footprint view command

Source: Internet
Author: User
Tags memory usage

(1) Top mission

The code is as follows Copy Code

$ top-u Oracle

1. Top command

The code is as follows Copy Code
top-d 1-p pid [, pid ...]//set to delay 1s, default is delay 3s

If you want to sort by memory usage, you can shift + m (sort by memory usage)

(2) Pmap

You can view the memory usage of process-related information based on the process (the process number can be viewed through PS) as follows:

The code is as follows Copy Code
$ pmap-d 14596

(3) PS
  
As shown in the following example:

The code is as follows Copy Code
$ ps-e-O ' pid,comm,args,pcpu,rsz,vsz,stime,user,uid ' where Rsz is the actual memory
$ ps-e-o ' pid,comm,args,pcpu,rsz,vsz,stime,user,uid ' |  grep Oracle | Sort-nrk5

Where Rsz is the actual memory, the above example realizes by memory sort, from big to small

Static view of memory usage for a process

1, Pmap command

The code is as follows Copy Code
Pmap PID

2. PS command

The code is as follows Copy Code
PS Aux|grep process_name

3, view the status file under the/proc/process_id/folder

The code is as follows Copy Code
name:php
State:r (running)
sleepavg:0%
tgid:21574
pid:21574
ppid:10005
tracerpid:0
uid:1000 1000 1000 1000
GID:100 100 100 100
fdsize:256
Groups:16 100
vmpeak:161740 KB
vmsize:161740 KB
vmlck:0 KB
vmhwm:107144 KB
vmrss:107144 KB
vmdata:106192 KB
vmstk:84 KB
vmexe:5588 KB
vmlib:7884 KB
vmpte:268 KB
Threads:1
sigq:0/69632
sigpnd:0000000000000000
shdpnd:0000000000000000
sigblk:0000000000000000
sigign:0000000000001000
Sigcgt:00000001818040a7
capinh:0000000000000000
capprm:0000000000000000
capeff:0000000000000000
cpus_allowed:00000000,00000000,00000000,0000000f
Mems_allowed:1

The size of the task virtual address space Vmsize
The size of the physical memory the application is using Vmrss


View memory We generally use the free command:

The code is as follows Copy Code


[root@scs-2 tmp]# Free
             total        used       free     shared    buffers     Cached
mem:       3266180    3250004      16176          0      110652    2668236
-/+ buffers/cache:     471116     2795064
swap:      2048276      80160     1968116

The following is an explanation of these values:
Total: The amount of physical memory.
Used: How big it has been used.
Free: How many are available.
Shared: The total amount of memory shared by multiple processes.
Buffers/cached: The size of the disk cache.
Third line (-/+ buffers/cached):
Used: How big it has been used.
Free: How many are available.
The line four is not much explained.
Difference: The difference between the used/free of the second line (MEM) and the used/free of the third row (-/+ Buffers/cache). The difference between the two is that the first line is from the OS point of view, because for os,buffers/cached is used, so his available memory is 16176KB, the used memory is 3250004KB, which includes, the kernel (OS) uses + Application (X, oracle,etc) used by +buffers+cached.
The third line refers to the application from the point of view of the application, buffers/cached is equal to available, because buffer/cached is to improve the performance of file read, when the application needs to use memory, the buffer/cached will be quickly recycled.

Measurement of memory footprint

Measuring how much memory a process consumes, Linux provides us with a convenient way, the/proc directory provides us with all the information, in fact, top and other tools to get the appropriate information.

The code is as follows Copy Code

Memory usage information for/proc/meminfo machines

The/proc/pid/maps PID is the process number that displays the virtual address occupied by the current process.

Memory consumed by the/PROC/PID/STATM process

[Root@localhost ~]# CAT/PROC/SELF/STATM

654 57 44 0 0 334 0

Output explanation

CPU and CPU0 ... The meaning of each parameter (in the first act) of each row is:

Parameter Interpretation/proc//status

The code is as follows Copy Code

Size (pages) task virtual address space VMSIZE/4

The size of the physical memory that the resident (pages) application is using VMRSS/4

Shared (pages) share pages 0

The size of the executable virtual memory owned by the TRS (pages) program VMEXE/4

Lrs (pages) the size of the library that is imaged to the virtual memory space of the task VMLIB/4

Drs (pages) program data segment and user state stack size (vmdata+ VMSTK) 4

DT (pages) 04

View Machine available memory

The code is as follows Copy Code

/proc/28248/>free

Total used free shared buffers Cached

mem:1023788 926400 97388 0 134668 503688

-/+ buffers/cache:288044 735744

swap:1959920 89608 1870312

When we look at the idle memory of the machine by using the free command, we find that the value of the freed is very small. This is mainly because, in Linux, there is such a thought, not white memory, so it as much as possible cache and buffer some data to facilitate the next use. But in fact, these memory can also be used immediately.

So free memory =free+buffers+cached=total-used

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.