When the usage of memory allocated by the system reaches the upper limit specified for a memcg, the system triggers memcg-level direct memory reclamation. 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 issue, Alibaba Cloud Linux provides the backend asynchronous reclaim feature for memcgs. This feature is supported by Alibaba Cloud Linux 2 with kernel version 4.19.81-17.al7
and later and Alibaba Cloud Linux 3 with kernel version 5.10.134-12.al8
and later. This feature helps you dynamically and efficiently manage cgroup memory usage and prevent resource exhaustion.
Memory allocation in an existing memcg may recursively trigger the backend asynchronous reclamation of the parent cgroup.
When backend asynchronous reclamation is triggered, it starts from the memcg in which the feature is triggered and is continuously performed in the memcg from top to down in the cgroup hierarchy.
When the
memory.high
interface is specifiedto a value that is less than the value of the
memory.limit_in_bytes
interface, the values of thememory.wmark_high
andmemory.wmark_low
interfaces are calculated based on thememory.high
interface instead of thememory.limit_in_bytes
interface.
Interface description
Interface | Description |
| Specifies whether to enable the memcg backend asynchronous reclaim feature and the memcg memory watermark that triggers asynchronous memory reclaim. Unit: percent of the Valid values: 0 to 100.
|
| When the memcg memory usage exceeds the value of this interface, backend asynchronous reclamation is triggered. A read-only interface.
|
| When the memcg memory usage is less than the value of this interface, backend asynchronous reclamation is terminated. A read-only interface.
|
| Controls the difference between the Unit: 0.01 percent of the memcg memory upper limit ( Valid values: 1 to 1000.
|
Configuration examples
Create a test file.
sudo mkdir /sys/fs/cgroup/memory/test/
Specify the value of the
memory.limit_in_bytes
interface.In this example, the value is set to 1 GB.
sudo sh -c 'echo 1G > /sys/fs/cgroup/memory/test/memory.limit_in_bytes'
Specify the value of the
memory.wmark_ratio
interface.In this example, the value is set to 95%. The memory watermark in the
memcg
for the asynchronous reclaim feature is 95% of the memcg memory upper limit (memcg limit
).sudo sh -c 'echo 95 > /sys/fs/cgroup/memory/test/memory.wmark_ratio'
View the values of interfaces in the memcg.
View the value of the
memory.wmark_scale_factor
interface.cat /sys/fs/cgroup/memory/test/memory.wmark_scale_factor
The default value is 0.50% of the memcg memory limit (
memcg limit
). Sample return value: 50.View the value of the
memory.wmark_high
interface.cat /sys/fs/cgroup/memory/test/memory.wmark_high
View the value of the
memory.wmark_low
interface.cat /sys/fs/cgroup/memory/test/memory.wmark_low