Home  >  Article  >  Operation and Maintenance  >  What is the command to view memory under Linux?

What is the command to view memory under Linux?

青灯夜游
青灯夜游Original
2020-08-21 13:46:386340browse

The command to view memory is the free command. The Linux free command can display system memory usage, including physical memory, swap memory (swap) and kernel buffer memory.

What is the command to view memory under Linux?

Course recommendation: "linux course"

Under Linux, we often use the top command to view system processes. top can also display system memory. The special tool we commonly use to view content under Linux is the free command.

Detailed explanation of free memory view command under Linux:

To view memory under Linux, we generally use the free command:

$ 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 to view free memory Explanation of the command output:

  • total: Total physical memory size.
  • used: How big 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.

The third line (-/ buffers/cached):

  • used: How big has been used.
  • free: How many are available.

The fourth line will not be explained much.

-/ buffers/cache meaning and difference:

The difference between used/free in the second line (mem) and used/free in the third line (-/ buffers/cache) lies in the used Perspective:

  • The second line is from the perspective of the OS, because for the OS, buffers/cached They are all used, so its available memory is 16176KB and used memory is 3250004KB, including the kernel (OS) using Application(X, oracle, etc) buffers cached.
  • The third line refers to the application point of view, for the application, buffers/cached is equal to available, because buffer/cached is to improve File reading performance, when the application needs to use memory, buffer/cached will be recycled quickly.

So from the perspective of the application, available memory = system free memory buffers cached.

As in the above example:

  • 2795064=16176 110652 2668236

##How to exchange memory

Next Explain when memory will be swapped, and in what direction. When the available memory is less than the rated value, a swap will occur. How to check the rating:

cat /proc/meminfo

The output is:

$ cat /proc/meminfo
MemTotal:      3266180 kB
MemFree:         17456 kB
Buffers:        111328 kB
Cached:        2664024 kB
SwapCached:          0 kB
Active:         467236 kB
Inactive:      2644928 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:      3266180 kB
LowFree:         17456 kB
SwapTotal:     2048276 kB
SwapFree:      1968116 kB
Dirty:               8 kB
Writeback:           0 kB
Mapped:         345360 kB
Slab:           112344 kB
Committed_AS:   535292 kB
PageTables:       2340 kB
VmallocTotal: 536870911 kB
VmallocUsed:    272696 kB
VmallocChunk: 536598175 kB
HugePages_Total:     0
HugePages_Free:      0
Hugepagesize:     2048 kB

The result of using free -m:

[root@scs-2 tmp]# free -m
             total       used       free     shared    buffers     cached
Mem:          3189       3173         16          0        107       2605
-/+ buffers/cache:        460       2729
Swap:         2000         78       1921

View the size of the /proc/kcore file (memory mirror):

$ ll -h /proc/kcore
-r-------- 1 root root 4.1G Jun 12 12:04 /proc/kcore

Note:

Measurement of occupied memory

Linux provides us with a very convenient method to measure how much memory a process occupies. The /proc directory provides us with all Information, in fact tools such as top also use this to obtain corresponding information.

    /proc/meminfo Machine memory usage information
  • /proc/pid/maps pid is the process number, showing the virtual address occupied by the current process.
  • /proc/pid/statm Memory occupied by the process
  • $ cat /proc/self/statm
    654 57 44 0 0 334 0

Output explanation

CPU and CPU0. . . The meaning of each parameter in each line (taking the first line as an example) is:

Parameter explanation/proc/status

Size (pages) The size of the task virtual address space VmSize/4

Resident(pages) The size of the physical memory being used by the application VmRSS/4

Shared(pages) The number of shared pages 0

Trs(pages) The executable owned by the program The size of virtual memory VmExe/4

Lrs(pages) The size of the library that is mapped to the virtual memory space of the task VmLib/4

Drs(pages) The program data segment and user-mode stack The size of (VmData VmStk) 4

dt(pages) 04

View the available memory of the machine

/proc/28248/>free

total used free shared buffers cached

Mem: 1023788 926400 97388 0 134668 503688

-/ buffers/cache: 288044 735744

Swap: 1959920 89608 1870312

Linux Summary of Viewing Memory and Memory Usage:

When we use the free command to view the free memory of the machine, we will find that the value of free is very small. This is mainly because there is a thought in Linux that memory is not used in vain, so it caches and buffers some data as much as possible to facilitate next use. But in fact, these memories can be used immediately.

So free memory=free buffers cached=total-used

Related recommendations: "

Linux Operation and Maintenance"

The above is the detailed content of What is the command to view memory under Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn