Memcg Reclaim Prioritization for Faster Linux Memory Recovery
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Conventional Linux memory reclaim methods in memcg (Memory Cgroup) are inefficient due to varying reclaim rates among different groups, leading to excessive time consumption and poor user experience, especially for foreground applications.
Innovation Solution
Configure memory reclaim levels based on the efficiency of each memory control group, prioritizing groups with higher reclaim efficiency for initial scanning to avoid excessive reclaim and improve overall efficiency, with special considerations for commonly used and foreground applications.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Productivity
If the Linux system traverses each memcg during memory reclaim to reclaim reclaimable memory, then memory can be recovered, but some memcgs consume long time for memory reclaim while reclaiming small amounts of memory, resulting in low overall memory reclaim efficiency
Solution Approach 1:
The patent changes the parameter of memory reclaim priority by introducing a priority value for each memcg based on its reclaim efficiency. This parameter change allows the system to differentiate between memcgs that are easy to reclaim from and those that are difficult, thereby optimizing the overall reclaim process by focusing time on high-efficiency memcgs first.
Solution Approach 2:
The patent implements a feedback mechanism where the system records historical memory reclaim data for each memcg, calculates reclaim efficiency based on this data, and uses this efficiency metric to dynamically adjust reclaim priorities. This feedback loop enables continuous optimization of memory reclaim operations based on actual performance outcomes.
2Reliability
If memory reclaim is performed uniformly across all memory control groups, then all applications are treated equally, but this causes excessive time consumption on applications with low reclaim efficiency, degrading user experience
Solution Approach 1:
The patent applies local quality by assigning different reclaim priorities to different memcgs based on their individual reclaim efficiency characteristics. Instead of uniform treatment, each memcg receives a customized priority level that reflects its specific reclaim behavior, allowing the system to allocate reclaim resources more intelligently and preserve user experience by minimizing reclaim operations on foreground applications.
3Quantity of substance
If the system performs comprehensive memory reclaim scanning on all memory control groups, then maximum memory can be reclaimed, but this leads to excessive reclaim operations that impact foreground applications and commonly used applications
Solution Approach 1:
The patent segments the memory reclaim process by dividing memcgs into different priority groups based on their reclaim efficiency and application importance. This segmentation allows the system to perform reclaim operations in a structured manner, targeting low-priority memcgs first while protecting foreground and commonly used applications from excessive reclaim operations.
Solution Approach 2:
The patent performs preliminary action by pre-calculating and recording the reclaim efficiency of each memcg before actual reclaim operations. This advance preparation enables the system to identify which memcgs are good candidates for reclaim and which should be protected, allowing reclaim operations to be initiated with optimized priority settings from the outset.
Data Source
Figure 1
Figure 2
Figure 3A
AI summary
This application provides a memory reclaim method and an electronic device. The method includes: obtaining, based on historical data of memory reclaim, memory reclaim efficiency of a memory control group corresponding to each application on the current electronic device, if a trigger condition for a memory reclaim procedure is satisfied; setting, based on the obtained memory reclaim efficiency, a reclaim level of the memory control group corresponding to each application; and determining, based on a reclaim priority and the reclaim level of each memory control group, a target memory control group that needs to be traversed, scanning the target memory control group, and reclaiming a scanned reclaimable memory. In this way, the memory reclaim level is configured based on the memory reclaim efficiency of the memory control group corresponding to each application, so that memory of a top application is reclaimed first. In this way, reclaim is first performed for a memory control group whose memory is easy to reclaim, to effectively avoid excessive memory reclaim, to improve overall memory reclaim efficiency.