How to view free memory/physical memory usage/remaining memory in a Linux system __linux

Source: Internet
Author: User
Tags memory usage cpu usage
View free memory/physical memory usage/remaining memory in a Linux system


There are many ways to view system memory, but the main is to use the top command and free command
How do you see the results when you execute the top command? Here is a description:
mem:666666k Total, 55555k used, does not represent your application already uses 55555k of memory, which 55555k is included: application memory + buffer + cache memory.
See more directly with the free command:
The following is an example (in megabytes):
[ROOT@LINUXZGF ~]# Free-m
Total used free shared buffers Cached
mem:7982 6811 1171 0 350 5114
-/+ buffers/cache:1346 6636
swap:16935 11 16924


In this example, the application uses only 1346MB of memory, and 6636MB of free memory is available.
Some simple methods of calculation:
Physical used memory = actual used memory-buffer-cache = 6811m-350m-5114m


Physical free memory = Total physical memory-Actual memory + buffer + Cache


Application free memory = Total physical memory-actual memory used


Application used memory = actual used memory-buffer-cache


The result of the top command is detailed
The top command is a commonly used performance analysis tool under Linux to display the resource consumption status of each process in real time, similar to the Task Manager of Windows. The following is a detailed description of how it is used.


Top-02:53:32 up, 6:34, users, load average:0.24, 0.21, 0.24
tasks:481 Total, 3 running, 474 sleeping, 0 stopped, 4 zombie
Cpu (s): 10.3%us, 1.8%sy, 0.0%ni, 86.6%id, 0.5%wa, 0.2%hi, 0.6%si, 0.0%st
mem:4042764k Total, 4001096k used, 41668k free, 383536k buffers
swap:2104472k Total, 7900k used, 2096572k free, 1557040k cached


PID USER PR NI virt RES SHR S%cpu%mem time+ COMMAND
32497 Jacky 0 669m 222m 31m R 5.6 29:27.62 Firefox
4788 yiuwing 0 257m 18m 13m S 5 0.5 5:42.44 Konsole
5657 liuxiaof 0 585m 159m 30m S 4 4.0 5:25.06 Firefox
4455 XIEFC 0 542m 124m 30m R 4 3.1 7:23.03 Firefox
6188 liuxiaof 0 191m 17m 13m S 4 0.5 0:01.16 Konsole





The first five elements in the statistical information area are the statistical information of the whole system. The first line is the task queue information, with the execution result of the uptime command. Its contents are as follows:


01:06:48 Current Time
Up 1:22 system run time, format last: Min
1 User Current Logged-in users
Load average:0.06, 0.60, 0.48 system load, that is, the average length of the task queue.
Three values are 1 minutes, 5 minutes, and 15 minutes ago to the current average.




The second to third behavior process and CPU information. When you have more than one CPU, the content can be more than two lines. The contents are as follows:


Total Process tasks:29
1 running number of processes running
Number of sleeping sleep processes
0 stopped number of processes stopped
0 Zombie Zombie Process number
CPU (s): 0.3% US user space uses CPU percent
1.0% sy kernel space occupies CPU percent
0.0% ni% of processes in user process space that have changed priority
98.7% ID Idle CPU percent
0.0% wa% CPU time waiting for input output
0.0% hi
0.0% si




The last two acts of memory information. The contents are as follows:


Total physical memory of mem:191272k
Total physical memory used by 173656k used
17616k free Memory Total
22052k buffers as the kernel cache memory
Total Exchange area of swap:192772k
Total number of swap areas used by 0k used
192772K free Idle swap area total
123988k cached the total number of swap areas buffered.
The content in memory is swapped out to the swap area and then swapped into memory, but the used swap area has not been overwritten,
The value is the size of the swap area where the content already exists in memory.
When the corresponding memory is swapped out again, you do not have to write to the swap area again.




The details of each process are shown below the process information area statistics area. First of all, to understand the meaning of the columns.


Ordinal column name meaning
A PID process ID
b PPID Parent Process ID
C Ruser Real user name
D UID Process Owner's user ID
The user name of the e user process owner
Group name of the F group Process owner
G TTY starts the process's terminal name. Processes that are not started from the terminal are displayed as?
H-PR Priority
I NI nice value. A negative value indicates a high priority, and a positive value indicates a low priority
The last CPU used by J P is meaningful only in a multi-CPU environment
K%cpu percentage of CPU time last updated to now
The total amount of CPU time used by the L/O process, in seconds
Total CPU time used by the M time+ process, in units 1/100 seconds
N%mem percent of physical memory used by the process
o The total amount of virtual memory used by the virt process, in kilobytes. Virt=swap+res
The amount of virtual memory that the P swap process uses, the size of which is swapped out, the unit KB.
The amount of physical memory used by the Q RES process that is not swapped out, in kilobytes. Res=code+data
The physical memory size, in kilobytes, that the code executable uses
The amount of physical memory (data segment + stack) occupied by parts other than the S data executable code, in kilobytes
T SHR shared memory size, per kb
U Nflt page Error times
V NDRT last written to now, the number of pages that have been modified.
W S process status.
D = Non-disruptive sleep state
R = Run
S = Sleep
T = trace/Stop
Z = Zombie Process
x command name/command line
Y Wchan If the process is sleeping, show the name of the system function in sleep
Z Flags task flags, reference sched.h




By default, only the more important PID, USER, PR, NI, Virt, RES, SHR, S,%cpu,%mem, time+, COMMAND columns are displayed. You can change the display by using the shortcut keys below.
Change the display by using the F key, you can select what to display. Press the F key to display a list of columns, A-Z to show or hide the corresponding columns, and then press ENTER to determine.
Press the O key to change the order in which the columns are displayed. A A-Z in lowercase can move the corresponding column to the right, while an uppercase A-Z moves the corresponding column to the left. Finally press ENTER to determine.
Press the F or O key in uppercase, and then press A-Z to sort the process by the appropriate column. The uppercase R key can reverse the current sort.
When the top command is in use, you can also use some interactive commands to perform the functions of other parameters. These commands are started by using a shortcut key.
Space: Refresh immediately.
P: Sort According to CPU usage size.
T: Sorted by Time, cumulative time.
Q: Exit Top command.
M: Toggle display memory information.
T: Toggles the display of process and CPU state information.
C: Toggle display command name and full command line.
M: Sort based on the size of memory used.
W: Writes the current settings to the ~/.TOPRC file. This is the recommended method for writing the top configuration file.
As you can see, the top command is a powerful monitoring system tool that is especially important for system administrators. However, its disadvantage is that it consumes a lot of system resources.




The following instructions are also used to view the memory:
To view the number of CPUs
# Cat/proc/cpuinfo | grep "Physical ID" | Uniq | Wc-l
To view the number of CPU cores
# Cat/proc/cpuinfo | grep "CPU Cores" | Uniq
View CPU Model
# Cat/proc/cpuinfo | grep ' model name ' |uniq
Well, the server has 2 4 core CPUs, model Intel (R) Xeon (r) CPU E5630 @ 2.53GHz


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.
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

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.