Memory Management
Basic Concepts
The memory is an important component of a computer, and is used to temporarily store operation data in the CPU and data exchanged with an external memory such as hardware. In particular, a non-uniform memory access architecture (NUMA) is a memory architecture designed for a multiprocessor computer. The memory access time depends on the location of the memory relative to the processor. In NUMA mode, a processor accesses the local memory faster than the non-local memory (the memory is located in another processor or shared between processors).
Viewing Memory
free: displays the system memory status. Example:
# Display the system memory status in MB. free -m
The output is as follows:
[root@openEuler ~]# free -m total used free shared buff/cache available Mem: 2633 436 324 23 2072 2196 Swap: 4043 0 4043
The fields in the command output are described as follows:
Field Description total Total memory size. used Used memory. free Free memory. shared Total memory shared by multiple processes. buff/cache Total number of buffers and caches. available Estimated available memory to start a new application without swapping. vmstat: dynamically monitors the system memory and views the system memory usage.
Example:
# Monitor the system memory and display active and inactive memory. vmstat -a
The output is as follows:
[root@openEuler ~]# vmstat -a procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free inact active si so bi bo in cs us sy id wa st 2 0 520 331980 1584728 470332 0 0 0 2 15 19 0 0 100 0 0
In the command output, the field related to the memory is described as follows:
Field Description memory Memory information.
-swpd: usage of the virtual memory, in KB.
-free: free memory capacity, in KB.
-inact: inactive memory capacity, in KB.
-active: active memory capacity, in KB.sar: monitors the memory usage of the system.
Example:
# Monitor the memory usage in the sampling period in the system. Collect the statistics every two seconds for three times. sar -r 2 3
The output is as follows:
[root@openEuler ~]# sar -r 2 3 04:02:09 PM kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kb dirty 04:02:11 PM 332180 2249308 189420 7.02 142172 1764312 787948 11.52 470404 1584924 36 04:02:13 PM 332148 2249276 189452 7.03 142172 1764312 787948 11.52 470404 1584924 36 04:02:15 PM 332148 2249276 189452 7.03 142172 1764312 787948 11.52 470404 1584924 36 Average: 332159 2249287 189441 7.03 142172 1764312 787948 11.52 470404 1584924 36
The fields in the command output are described as follows:
Field Description kbmemfree Unused memory space. kbmemused Used memory space. %memused Percentage of the used space. kbbuffers Amount of data stored in the buffer. kbcached Data access volume in all domains of the system. numactl: displays the NUMA node configuration and status.
Example:
# Check the current NUMA configuration. numactl -H
The output is as follows:
[root@openEuler ~]# numactl -H available: 1 nodes (0) node 0 cpus: 0 1 2 3 node 0 size: 2633 MB node 0 free: 322 MB node distances: node 0 0: 10
The server contains one NUMA node. The NUMA node that contains four cores and 6 GB memory. The command also displays the distance between NUMA nodes. The further the distance, the higher the latency of cross-node memory accesses, which should be avoided as much as possible.
numastat: displays NUMA node status.
# Check the NUMA node status. numastat
[root@openEuler ~]# numastat node0 numa_hit 5386186 numa_miss 0 numa_foreign 0 interleave_hit 17483 local_node 5386186 other_node 0
The the fields in the command output and their meanings are as follows:
Field Description numa_hit Number of times that the CPU core accesses the local memory on a node. numa_miss Number of times that the core of a node accesses the memory of other nodes. numa_foreign Number of pages that were allocated to the local node but moved to other nodes. Each numa_foreign corresponds to a numa_miss event. interleave_hit Number of pages of the interleave policy that are allocated to this node. local_node Size of memory that was allocated to this node by processes on this node. other_node Size of memory that was allocated to other nodes by processes on this node.