The free command can display idle and used physical memory, swap memory, and buffer used by the kernel in Linux. In Linux system monitoring tools, the free command is one of the most frequently used commands. This topic describes how to use the free command and how to explain the value.
In Windows, it is very easy to view the memory usage. I think everyone is familiar with it. How can I check the memory usage in Linux? The following is a free command for checking memory usage in Linux:
51cto editing recommendations: Linux monitoring tools
- [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: total physical memory size.
Used: used.
Free: available.
Shared: The total memory shared by multiple processes.
Buffers/cached: disk cache size.
Row 3 (-/+ buffers/cached ):
Used: used.
Free: available.
The fourth line won't be explained much.
Difference: used/free of the second row (MEM) differs from used/free of the third row (-/+ buffers/cache. The difference between the two is that from the perspective of usage, the first line is from the OS perspective, because for OS, buffers/cached is used, so its available memory is 16176kb, the memory used is kb, including the + buffers + cached used by the kernel (OS) + application (x, Oracle, etc.
The third line indicates that, from the application perspective, for applications, buffers/cached is equivalent to available, because buffer/cached is designed to improve file read performance, when the application needs to use the memory, buffer/cached will be quickly recycled.
From the application perspective, the available memory = system free memory + buffers + cached.
For example:
2795064 = 16176 + 110652 + 2668236
Next, we will explain when the memory will be exchanged and by which side. When the available memory is less than the rated value, a meeting will be held for exchange.
Rating:
- cat /proc/meminfo
- [root@scs-2 tmp]# 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
View the result in 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 image ):
- [root@scs-2 tmp]# ll -h /proc/kcore
- -r——– 1 root root 4.1G Jun 12 12:04 /proc/kcore
Note: memory usage Measurement
Measure how much memory a process occupies. Linux provides us with a very convenient method. The/proc Directory provides us with all the information, in fact, the top tool also obtains the corresponding information here.
- /Proc/meminfo memory usage information of the machine
- /Proc/Pid/maps PID is the process number and displays the virtual address occupied by the current process.
- Memory occupied by/proc/Pid/statm Process
- [Root @ localhost ~] # Cat/proc/self/statm
- 654 57 44 0 0 334 0
Output description
CPU and CPU 0... The meaning of each parameter in each row (in the first behavior example) is:
Parameter description/proc // status
Size (pages) task virtual address space size vmsize/4
The size of the physical memory that the resident (pages) application is using vmrss/4
Shared (pages) shared pages 0
Size of executable virtual memory owned by the TRS (pages) program vmexe/4
The size of the library that the LRS (pages) is mapped 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 available machine memory
- /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 run the free command to view the idle memory of the machine, we will find that the free value is very small. This is mainly because there is such an idea in the Linux system that the memory does not need to be white, so it tries its best to cache and buffer some data to facilitate the next use. But in fact, these memories can also be used immediately.
So free memory = free + buffers + cached = total-used
Linux usually loads common data into the system's virtual memory buffers and cached according to certain algorithms, so that user programs can access system resources faster. The buffers viewed by free are used to store metadata, while cached is used to store real file content.
Top --- and ---- PS
These two tools have great similarity in memory monitoring, so let's talk about them together:
In the topVirtEquivalent to PSVsz: Indicates the total virtual memory used for this task (the virtual memory includes the physical memory and swap partition), including all code, Data, shared libraries, and data that has been out to the swap partition. /* The total amount of virtual memory used by the task. It contains des
All code, data and shared libraries plus pages that have been swapped out .*/
In the topResEquivalent to PSRSS: Indicates the total physical memory used for this task that is not out to the swap partition/* resident set size, the non-swapped physical memory that a task has used */
% MEM in top: Percentage of RES in this task to the total physical memory/* memory usage (RES) A task's currently used share of available physical memory .*/
Vmstat is short for virtual MEOMORY statistics (Virtual Memory Statistics). It can monitor virtual memory, processes, and CPU activity of the operating system. It collects statistics on the overall situation of the system. The disadvantage is that a process cannot be thoroughly analyzed. Generally, vmstat is used.
1 10 (indicates refreshing every 1 second, 10 times in total) command test. A summary of the data to reflect the real system conditions.
The displayed value is similar to the value displayed using the free tool. Generally, the number of Si/so values in the SWAp Column cannot exceed 1024.
Swap
Si: amount of memory swapped in from disk (/s ).
So: amount of memory swapped to disk (/s ).
Http://shop104965075.taobao.com