All Products
Search
Document Center

Alibaba Cloud Linux:Memcg backend asynchronous reclaim

Last Updated:Oct 16, 2023

The memcg backend asynchronous reclaim feature is supported in Alibaba Cloud Linux 2 starting from the 4.19.81-17.al7 kernel version and Alibaba Cloud Linux 3. This topic describes the interfaces that implement the memcg backend asynchronous reclaim feature.

Background information

In community versions of the Linux kernel, the system allocates memory and triggers memcg-level direct memory reclamation when the memory reaches an upper limit set by a memcg. Direct memory reclamation is a synchronous reclamation that occurs in the context of memory allocation and affects the performance of the current process.

To resolve this problem, Alibaba Cloud Linux provides the backend asynchronous reclaim feature for memcgs. This feature differs from the global kswapd kernel thread in that this feature uses the workqueue mechanism instead of creating a corresponding memcg kswapd kernel thread. Additionally, four memcg control interfaces are added to each of the cgroup v1 and cgroup v2 interfaces.

Take note of the following items:

  • Memory allocation of the current memcg may recursively trigger the backend asynchronous reclamation of the parent group.

  • When backend asynchronous reclamation is triggered, it starts from the memcg on which the feature is triggered and is performed in sequence down the hierarchy.

  • When memory.high is configured and the value of memory.high is smaller than that of memory.limit_in_bytes, the values of memory.wmark_high and memory.wmark_low are calculated based on memory.high instead of memory.limit_in_bytes.

Interface description

Interface

Description

memory.wmark_ratio

Specifies whether to enable the memcg backend asynchronous reclaim feature and sets the memcg memory watermark for the asynchronous reclamation to start. Unit: percent of the memcg memory upper limit. Valid values: 0 to 100.

  • The default value is 0, which indicates that the memcg backend asynchronous reclaim feature is disabled.

  • When the value is not 0, the memcg backend asynchronous reclaim feature is enabled and a watermark is set.

memory.wmark_high

A read-only interface.

  • When the memcg memory usage exceeds the value of this interface, backend asynchronous reclamation is started.

  • The value of this interface is calculated based on the following formula: (memory.limit_in_bytes × memory.wmark_ratio/100).

  • When the memcg backend asynchronous reclaim feature is disabled, the default value of memory.wmark_high is the maximum value and the backend asynchronous reclaim feature is never triggered.

  • This interface file is not stored in the memcg root directory.

memory.wmark_low

A read-only interface.

  • When the memcg memory usage is less than the value of this interface, backend asynchronous reclamation is ended.

  • The value of this interface is calculated based on the following formula: memory.wmark_high - memory.limit_in_bytes × memory.wmark_scale_factor/10000.

  • This interface file is not stored in the memcg root directory.

memory.wmark_scale_factor

Controls the difference between values of memory.wmark_high and memory.wmark_low. Unit: 0.01 percent of the memcg memory upper limit. Valid values: 1 to 1000

  • This interface inherits the value of its parent group when the interface is created. The inherited value is 50, which indicates 0.50% of the memcg memory upper limit. This is also the default value.

  • This interface file is not stored in the memcg root directory.

Configuration examples

  1. Create a test file.

    mkdir /sys/fs/cgroup/memory/test/
  2. Specify the value of memory.limit_in_bytes.

    In this example, the value is 1 G.

    echo 1G > /sys/fs/cgroup/memory/test/memory.limit_in_bytes
  3. Configure memory.wmark_ratio.

    In this example, the memcg memory watermark where asynchronous reclamation starts is set to 95% of the memcg memory upper limit.

    echo 95 > /sys/fs/cgroup/memory/test/memory.wmark_ratio
  4. Run the following command to check the value of memory.wmark_scale_factor:

    cat /sys/fs/cgroup/memory/test/memory.wmark_scale_factor

    The default value is 0.50% of the memcg memory upper limit. Sample output: 50.

  5. Query the values of memory.wmark_high and memory.wmark_low.

    If the following values are displayed for memory.wmark_high and memory.wmark_low in the command outputs, the configurations are correct.

    • Run the following command:

      cat /sys/fs/cgroup/memory/test/memory.wmark_high

      Sample output: 1020051456.

    • Run the following command:

      cat /sys/fs/cgroup/memory/test/memory.wmark_low

      Sample output: 1014685696.