Home >Operation and Maintenance >Linux Operation and Maintenance >What is the command to view memory under Linux?
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.
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:
The third line (-/ buffers/cached):
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:
So from the perspective of the application, available memory = system free memory buffers cached.
As in the above example:
##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/meminfoThe 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 kBThe 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 1921View the size of the /proc/kcore file (memory mirror):
$ ll -h /proc/kcore -r-------- 1 root root 4.1G Jun 12 12:04 /proc/kcoreNote: 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.
$ 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/statusSize (pages) The size of the task virtual address space VmSize/4Resident(pages) The size of the physical memory being used by the application VmRSS/4Shared(pages) The number of shared pages 0Trs(pages) The executable owned by the program The size of virtual memory VmExe/4Lrs(pages) The size of the library that is mapped to the virtual memory space of the task VmLib/4Drs(pages) The program data segment and user-mode stack The size of (VmData VmStk) 4dt(pages) 04View the available memory of the machine/proc/28248/>freetotal used free shared buffers cachedMem: 1023788 926400 97388 0 134668 503688-/ buffers/cache: 288044 735744Swap: 1959920 89608 1870312Linux 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!