What do I do if the memory usage of a container on an Alibaba Cloud Linux 3 host is higher than the memory usage of the host?

Updated at: 2024-10-21 07:33

This topic describes the cause of the following issue and how to resolve the issue: The free command output indicates that the memory usage of a container running on an Alibaba Cloud Linux 3 host is higher the memory usage of the host.

Problem description

The memory usage of a container that is deployed on a host running Alibaba Cloud Linux 3 is higher than the memory usage of the host.

Cause

Memory usage is calculated by using the following formula: mem_used = kb_main_total - kb_main_free - kb_main_cached - kb_main_buffers, which does not properly treat shared memory (shmem). As a result, the calculated memory usage of the container is inaccurate.

Parameters in the formula used to calculate memory usage

  • mem_used: the amount of memory in use.

  • kb_main_total: the total amount of memory.

  • kb_main_free: the amount of free memory.

  • kb_main_cached: the amount of cached memory, such as file system cache, which helps accelerate data access.

  • kb_main_buffers: the mount of memory used for buffers, which usually holds temporary data, such as network packets.

Shared memory is a memory region that has the properties of anonymous pages and page cache and cannot be reclaimed as free memory when no swap space is configured. Shared memory (shmem) must be regarded as memory in use, instead of free memory to be included in the value of the kb_main_free parameter in the preceding formula. To obtain the accurate amount of memory in use (mem_used), exclude shared memory from the value of the kb_main_free parameter in the formula.

Solution

Run the following command on the host to update procps-ng to version 3.3.15-14.0.3.al8 or later:

sudo yum update procps-ng 
Note

Update procps-ng to make the new formula used to calculate memory usage take effect and resolve the preceding issue. For information about procps, see procps-ng>procps.

  • On this page (1, T)
  • Problem description
  • Cause
  • Solution
Feedback