Home > Article > Operation and Maintenance > Detailed explanation of Linux view memory command
linux view memory command
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.
Recommendation: "Linux Tutorial"
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 an explanation of the output of the free command to view memory:
total: the total size of physical memory.
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 From a perspective:
The second line is from the perspective of the OS. Because for the OS, buffers/cached are all used, so its available memory is 16176KB and the used memory is 3250004KB, including , the kernel (OS) uses the buffers cached used by Application (X, oracle, etc).
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 the performance of file reading. 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.
Same as the above example:
2795064=16176+110652+2668236
How to exchange memory
The next step is to explain when the memory will be exchanged, and in what way. 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
Remarks:
Measurement of occupied memory
To measure how much memory a process occupies, Linux provides us with a very convenient method. The /proc directory provides us with All information is obtained. In fact, tools such as top also obtain corresponding information through here.
/proc/meminfo 机器的内存使用信息 /proc/pid/maps pid为进程号,显示当前进程所占用的虚拟地址。 /proc/pid/statm 进程所占用的内存 $ 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:
参数 解释 /proc/status Size (pages) 任务虚拟地址空间的大小 VmSize/4 Resident(pages) 应用程序正在使用的物理内存的大小 VmRSS/4 Shared(pages) 共享页数 0 Trs(pages) 程序所拥有的可执行虚拟内存的大小 VmExe/4 Lrs(pages) 被映像到任务的虚拟内存空间的库的大小 VmLib/4 Drs(pages) 程序数据段和用户态的栈的大小 (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 view memory and memory usage summary:
us When you check the free memory of the machine through the free command, you 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
For more programming related content, please pay attention to the Programming Introduction column on the php Chinese website!
The above is the detailed content of Detailed explanation of Linux view memory command. For more information, please follow other related articles on the PHP Chinese website!