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.
|
memory.wmark_high | A read-only interface.
|
memory.wmark_low | A read-only interface.
|
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
|
Configuration examples
Create a test file.
mkdir /sys/fs/cgroup/memory/test/
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
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
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
.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
.