Article Title: detailed explanation of memory view in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Use free in Linux to view the system memory usage status. The default unit is k.
blue_stone@blueice:~$ freetotal used free shared buffers cachedMem: 2075320 1879172 196148 0 533484 952588-/+ buffers/cache: 393100 1682220Swap: 2008084 0 2008084
|
The Mem row shows the memory usage from the system perspective. total indicates the available memory size of the system, which is equal to the physical memory of the system minus the memory reserved by the kernel. buffers and cached are the buffer memory used by the system. buffers is associated with a block device. It contains metadata of the file system and tracks block changes. the cache only contains the file itself.
-/+ The buffers/cache row displays the memory information from the user's perspective. The number of available memory is equal to the used column value of the mem row minus the size of the buffers and cached memory. since buffers and cached are set by the operating system to speed up system running, they can only be used as needed by users.
Top and vmstat also display the system memory information, similar to the free display result.
These commands READ memory information from/proc/meminfo.
blue_stone@blueice:~$ cat /proc/meminfoMemTotal: 2075320 kBMemFree: 25016 kBBuffers: 763564 kBCached: 879860 kBSwapCached: 0 kBActive: 1056968 kBInactive: 843136 kBHighTotal: 917440 kBHighFree: 13892 kBLowTotal: 1157880 kBLowFree: 11124 kBSwapTotal: 2008084 kBSwapFree: 2008084 kBDirty: 4708 kBWriteback: 0 kBMapped: 707152 kBSlab: 102728 kBCommitLimit: 3045744 kBCommitted_AS: 691808 kBPageTables: 2936 kBVmallocTotal: 114680 kBVmallocUsed: 14800 kBVmallocChunk: 98800 kB
|
The meanings of each line in/proc/meminfo are described in the Documentation/filesystems/proc.txt file of the kernel source code, the actual memory size of the system can be viewed in dmesg | grep [mM] [eE] [mM.
blue_stone@blueice:~$ dmesg |grep [mM][eE][mM]895MB HIGHMEM available.1152MB LOWMEM available.HighMem zone: 229360 pages, LIFO batch:31Memory: 2073292k/2097088k available (1493k kernel code, 21648k reserved, 546k data, 196k init, 917440k highmem)Freeing initrd memory: 1079k freedMEM window: f8000000-f80fffffhighmem bounce pool size: 64 pagesFreeing unused kernel memory: 196k freedehci_hcd 0000:00:10.4: irq 177, io mem 0xf8121000/dev/vmnet: hub 0 does not exist, allocating memory.[fglrx] Maximum main memory to use for locked dma buffers: 1898 MBytes./dev/vmnet: hub 3 does not exist, allocating memory./dev/vmnet: hub 1 does not exist, allocating memory./dev/vmnet: hub 2 does not exist, allocating memory.
|
The memory used by the process can be viewed by top and ps. There are three columns in the top virt res shr, which indicate the memory usage of the process. VIRT indicates the total memory size that can be used by the process, including the memory actually used by the process, the mapped files, and the memory shared with other processes. RES indicates the memory occupied by the process. SHR identifies the memory and library size that can be shared with other processes.
/Proc/pid/status shows the detailed status of a process. The following is an example:
blue_stone@blueice:~$ cat /proc/5346/statusName: bashState: S (sleeping)SleepAVG: 98%Tgid: 5346Pid: 5346PPid: 5343TracerPid: 0Uid: 1000 1000 1000 1000Gid: 104 104 104 104FDSize: 256Groups: 6 24 29 44 104 113 1000 1001VmPeak: 6528 kBVmSize: 6528 kBVmLck: 0 kBVmHWM: 1976 kBVmRSS: 1976 kBVmData: 752 kBVmStk: 84 kBVmExe: 644 kBVmLib: 1788 kBVmPTE: 16 kBThreads: 1SigQ: 0/4294967295SigPnd: 0000000000000000ShdPnd: 0000000000000000SigBlk: 0000000000000000SigIgn: 0000000000384004SigCgt: 000000004b813efbCapInh: 0000000000000000CapPrm: 0000000000000000CapEff: 0000000000000000
|
VmSize indicates the total memory size of the process, which is consistent with the VIRT in the top output.