[LINUX-06-1] Linux memory recycling mechanism

Analysis 1:

1 Two reasons for recycling

There are two main reasons why the kernel needs to recycle memory:

  1. The kernel needs to provide enough memory for any memory application that comes suddenly at any time, so that the use of cache and other related memory will not leave the remaining memory of the system in a long-term state.
  2. When there is really an application that is larger than the free memory, it will trigger a forced memory reclamation.

2 Recycling two goals

One is for the zone, the other is for a memcg;

3 For zone

There are three types of memory recycling, namely fast memory recycling, direct memory recycling, and kswapd memory recycling.

  1. Fast memory reclamation: in the get_page_from_freelist () function, in the process of traversing the zonelist, each zone is judged before allocation. If the amount of free memory of the zone after allocation <threshold + number of reserved page frames, then this zone Perform fast memory reclamation. The threshold may be any of min / low / high, because in the process of fast memory allocation, slow memory allocation and oom allocation, if the page frames recovered are sufficient, the get_page_from_freelist () function will be called, so fast memory recovery is not only This happens only during fast memory allocation, and also during slow memory allocation.
  2. Direct memory reclamation: In the slow allocation process, direct memory reclamation is only used in one case. In slow allocation, page frames cannot be allocated from all zones in the zonelist with a min threshold, and after asynchronous memory compression, it is still When it cannot be allocated to the page frame, a direct memory collection is performed on all zones in the zonelist. Note that direct memory reclamation is for all zones in the zonelist. It is not like fast memory reclamation and kswapd memory reclamation. It only performs memory reclamation for zones in the free page frame of the zonelist that do not meet the standard. In direct memory reclamation, it is possible to wake up the flush kernel thread.
  3. kswapd memory recycling: occurs in the kswapd kernel thread, each node has a swapd kernel thread, that is, the memory recycling in the kswapd kernel thread, is only for the node, and only for the free page after the order page frame number The number of frames <the high threshold of this zone + the number of pages in the reserved frame for memory reclamation, and no memory reclamation for all zones of this node.

 

 

Analysis 2:

 

 

 

 

 

 

 

 

Original: https://www.jianshu.com/p/7ab51b8a6368

 

Guess you like

Origin www.cnblogs.com/Ph-one/p/12737859.html