Source code is based on: Android R
1. cat /proc/meminfo
MemTotal: All available RAM sizes (i.e. physical memory minus some reserved bits and kernel binary code size)
MemFree: The sum of LowFree and HighFree
Buffers: The buffer size used to make for block devices (only record the metadata and tracking in-flight pages of the file system, that is, buffers are used to store, what content is in the directory, permissions, etc.)
Cached: Used to buffer files (used directly to remember the files we opened). It does not include SwapCached
SwapCached: The memory that has been swapped out, but is still stored in the swapfile. Used to be replaced quickly when needed without opening the I/O port again.
Active: Memory that has been used frequently recently will not be moved for other purposes unless it is very necessary.
Inactive: Memory that is not often used recently, very useful may be used in other ways.
HighTotal:
HighFree: High memory refers to all memory spaces above 860MB. This area is mainly used for user space programs or cache pages. The kernel must use this segment of memory using different methods, so it is a bit slower than the low-bit memory.
LowTotal:
LowFree: Low bits can achieve the same effect as high bit memory, and it can also be used by the kernel to record some of its own data structures.
Among many other things, it is where everything from the Slab is
allocated. Bad things happen when you're out of lowmem.
SwapTotal: Sum of swap spaces
SwapFree: Replaced from RAM the size of space temporarily existing on disk
Dirty: The memory size that is waiting to be written back to disk.
Writeback: The memory size that is being written back to disk.
Mapped: Alluding to the size of the file.
Slab: Kernel data structure cache
VmallocTotal: vmalloc memory size
VmallocUsed: The size of virtual memory that has been used.
VmallocChunk: large contigious block of vmalloc area which is free
CommitLimit:
Committed_AS:
For details, you can view:Linux kernel parameters: meminfo
2. dumpsys meminfo
View in detail:dumpsys meminfo details
3. procrank
root@h15:/ # procrank
PID Vss Rss Pss Uss cmdline
4034 744312K 80076K 63779K 61188K
3887 691700K 69676K 54293K 51784K
3749 709572K 36112K 20045K 17728K system_server
2586 55280K 15424K 10098K 8804K /system/bin/tvserver
2594 68848K 14268K 8235K 6124K /system/bin/mediaserver
4151 665424K 20184K 7157K 6016K
...
...
...
2599 3512K 452K 180K 168K /system/bin/sdcard
2595 1000K 444K 165K 152K /system/bin/installd
2608 1500K 176K 160K 160K /sbin/adbd
2580 1428K 148K 136K 136K /sbin/healthd
2582 1008K 348K 118K 108K /system/bin/servicemanager
2588 364K 96K 80K 80K /system/bin/dig
------ ------ ------
236736K 207864K TOTAL
RAM: 753344K total, 260444K free, 6788K buffers, 187252K cached, 348K shmem, 11480K slab
Android procrank (/system/xbin/procrank) tool can list the memory usage occupied by the process. The order is from high to low.
The memory sizes occupied by each process are listed in the form of VSS, RSS, PSS, USS.
To simplify description, memory footprints are expressed in pages, not bytes. Usually 4096 bytes per page.
VSS(equivalent to VSZ listed in the ps command) is the address space that a single process can access.
Its size includes parts that may not have resided in memory yet. For example, the address space has been allocated by malloc, but has not been actually written yet.
VSS is of little use for determining the actual memory usage size of a single process.
RSS It is the actual memory occupied by a single process.
The reason why RSS is easily misleading is that it includes the full memory size of all shared libraries used by the process. For a single shared library, although no matter how many processes are used,
In fact, the shared library will only be loaded into memory once.
RSS is not an exact description of the memory usage size of a single process.
PSSUnlike RSS, it simply includes the shared library size it uses in proportion.
For example, three processes use the same shared library that consumes 30 pages of memory. For any of the three processes, PSS will only include 10 memory pages.
PSS is a very useful number because all processes in the system are counted in a holistic way, which is a good description of the overall memory usage in the system.
If a process is terminated, the shared library size used in its PSS will be reproportionally allocated to the remaining processes that are still running and still using the shared library.
This calculation method has slight errors because when a process aborts, the PSS does not accurately represent the memory size returned to the entire system.
USSis the entire private memory size of a single process. That is, the memory size that is all exclusive to the process.
USS is a very, very useful number because it reveals the true memory increment size of running a particular process.
If the process is terminated, USS is the memory size actually returned to the system.
USS is the best number to detect when a process starts to have suspicious memory leaks.
4. free command
# free -k && cat /proc/meminfo
total used free shared buffers
Mem: 3746320 1332348 2413972 73544 8360
-/+ buffers/cache: 1323988 2422332
Swap: 1048572 0 1048572
MemTotal: 3746320 kB
MemFree: 2414212 kB
MemAvailable: 2942420 kB
Buffers: 8360 kB
Cached: 537244 kB
SwapCached: 0 kB
Active: 81092 kB
Inactive: 820852 kB
Active(anon): 432 kB
Inactive(anon): 426576 kB
Active(file): 80660 kB
Inactive(file): 394276 kB
Active(purg): 0 kB
Inactive(purg): 0 kB
Pined(purg): 0 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 1048572 kB
SwapFree: 1048572 kB
...
Shmem: 73544 kB
KReclaimable: 106700 kB
Slab: 131380 kB
SReclaimable: 46604 kB
SUnreclaim: 84776 kB
KernelStack: 16736 kB
The free command counts the information in /proc/meminfo:
Let’s look at the first line:
total used free shared buffers
Mem: 3746320 1332348 2413972 73544 8360
- total:The total memory available to the system;
- free:The remaining available memory in the system is equal to MemFree in /proc/meminfo; (The data above is slightly different, which is considered normal)
- used:total - free;
- shared:Shared memory, equal to Shmem in /proc/meminfo;
- buffers:Block cache, equal to Buffers in /proc/meminfo;
Let’s look at the second line:
total used free shared buffers
Mem: 3746320 1332348 2413972 73544 8360
-/+ buffers/cache: 1323988 2422332
Statistics are buffers/cache data:
- used:equal to the first line used - buffers;
- free:equals free + buffers on the first line;
Let’s look at the third line:
total used free shared buffers
Mem: 3746320 1332348 2413972 73544 8360
-/+ buffers/cache: 1323988 2422332
Swap: 1048572 0 1048572
The third line counts the data in the swap area:
- total:SwapTotal equal to /proc/meminfo;
- free:SwapFree equal to /proc/meminfo;
- used:total - free;