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).

Memory Monitoring

  1. free: displays the system memory status. Example:

    shell
    # Display the system memory status in MB.
    free -m

    The output is as follows:

    shell
    [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 as follows:

    FieldDescription
    totalTotal memory size.
    usedUsed memory.
    freeFree memory.
    sharedTotal memory shared by multiple processes.
    buff/cacheTotal number of buffers and caches.
    availableEstimated available memory to start a new application without swapping.
  2. vmstat: dynamically monitors the system memory and views the system memory usage.

    Example:

    shell
    # Monitor the system memory and display active and inactive memory.
    vmstat -a

    The output is as follows:

    shell
    [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 as follows:

    FieldDescription
    memoryMemory 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.
  3. sar: monitors the memory usage of the system.

    Example:

    shell
    # 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:

    shell
    [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:

    FieldDescription
    kbmemfreeUnused memory space.
    kbmemusedUsed memory space.
    %memusedPercentage of the used space.
    kbbuffersAmount of data stored in the buffer.
    kbcachedData access volume in all domains of the system.
  4. numactl: displays the NUMA node configuration and status.

    Example:

    shell
    # Check the current NUMA configuration.
    numactl -H

    The output is as follows:

    shell
    [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.

    shell
    # Check the NUMA node status.
    numastat
    shell
    [root@openEuler ~]# numastat
                            node0
    numa_hit                 5386186
    numa_miss                      0
    numa_foreign                   0
    interleave_hit             17483
    local_node               5386186
    other_node                     0

    The fields in the numastat command output are described as follows:

    FieldDescription
    numa_hitNumber of times that the CPU core accesses the local memory on a node.
    numa_missNumber of times that the core of a node accesses the memory of other nodes.
    numa_foreignNumber of pages that were allocated to the local node but moved to other nodes. Each numa_foreign corresponds to a numa_miss event.
    interleave_hitNumber of pages of the interleave policy that are allocated to this node.
    local_nodeSize of memory that was allocated to this node by processes on this node.
    other_nodeSize of memory that was allocated to other nodes by processes on this node.