This topic describes the memcg global minimum watermark rating feature provided in
Alibaba Cloud Linux 2 kernel version
4.19.91-18.al7 or later.
Global memory reclaim has a great impact on system performance of the Linux kernel. When latency-sensitive tasks and resource-consuming tasks are deployed together, resource-consuming tasks request a large amount of memory instantly, causing the free memory of the system to reach the global minimum watermark (global wmark_min). As a result, direct memory reclaim is enabled for all system tasks, causing performance jitters for latency-sensitive tasks. Neither global kswapd backend reclaim nor memcg backend reclaim can resolve this problem.
In this context, Alibaba Cloud Linux 2 provides the memcg global minimum watermark rating feature. The global wmark_min of resource-consuming tasks is increased to trigger direct memory reclaim. The global wmark_min of latency-sensitive tasks is decreased to avoid direct memory reclaim. In this way, when a resource-consuming task requests a large amount of memory instantly, an increase in the global wmark_min throttles the resources used for the task for a short period to avoid direct memory reclaim for latency-sensitive tasks. After a certain amount of memory is reclaimed through global kswapd backend reclaim, the throttling of the resource-consuming task is stopped.
- This interface file inherits a value of 0 from its parent group when the interface file is created. The default value is 0.
- A negative value is a percent of adjustment over the range
[0, WMARK_MIN], where
WMARK_MINis the value of global wmark_min. Example:
memory.wmark_min_adj=-25, memcg WMARK_MIN is "WMARK_MIN + (WMARK_MIN - 0) * (-25%)"Note A negative value also indicates a decrease of global wmark_min to increase the memcg QoS of latency-sensitive tasks.
- A positive value is a percent of adjustment over the range
[WMARK_MIN, WMARK_LOW], where
WMARK_LOWare values of global wmark_min and global wmark_low. Example:
memory.wmark_min_adj=50, memcg WMARK_MIN is "WMARK_MIN + (WMARK_LOW - WMARK_MIN) * 50%"Note A positive value also indicates an increase of global wmark_min to decrease the memcg QoS of resource-consuming tasks.
- When the offset global wmark_min is triggered, throttling is performed, and the throttling time is linearly proportional to the excessive memory usage. Valid values of throttling time: 1 to 1000. Unit: ms.
effective memory.wmark_min_adj, which is the final effective value of memory.wmark_min_adj. The values of memory.wmark_min_adj at all levels are traversed to obtain the maximum value. Intermediate nodes with the default value 0 are excluded. The following hierarchy shows an example.
The following table describes the mapping between the values of memory.wmark_min_adj at each level and the final effective value.
root / \ A D / \ B C / \ E F
|Level||Value||Final effective value|
- The value displayed in the output of the cat /sys/fs/cgroup/memory/<memcg path>/memory.wmark_min_adj command is the final effective value. In the command,
<memcg path>indicates the root path of the memcg.
- We recommend that you use the global minimum watermark rating feature together with global wmark_min. For example, you can set global wmark_min to 2 GB or more in /proc/sys/vm/min_free_kbytes.
Example 1: Configure global minimum watermark rating for the memcg of latency-sensitive tasks.
- Run the mkdir /sys/fs/cgroup/memory/test-lc command to create a test file.
- Run the echo -25 > /sys/fs/cgroup/memory/test-lc/memory.wmark_min_adj command to write the value
-25to the interface file to increase the memcg QoS of latency-sensitive tasks.
Example 2: Configure global minimum watermark rating for the memcg of resource-consuming tasks.
- Run the mkdir /sys/fs/cgroup/memory/test-be command to create a test file.
- Run the echo 25 > /sys/fs/cgroup/memory/test-be/memory.wmark_min_adj command to write the value
25to the interface file to decrease the memcg QoS of resource-consuming tasks.