Monday, June 3, 2013

lowmem_reserve understanding

2.6 kernel zone structure a member variable lowmem_reserve
  1. struct  {Zone  
  2.     / * Fields commonly accessed by the page allocator * /  
  3.   
  4.     / * Zone watermarks, access with * _wmark_pages (zone) macros * /  
  5.     unsigned  Long  Watermark [NR_WMARK];  
  6.   
  7.     / * 
  8.      * We don't know if the memory that we're going to allocate will be freeable 
  9.      * Or / and it will be released eventually, so to avoid totally wasting several 
  10.      * GB of ram we must reserve some of the lower zone memory (otherwise we risk 
  11.      * To run OOM on the lower zones despite there's tons of freeable ram 
  12.      * On the higher zones). This array is recalculated at runtime if the 
  13.      * Sysctl_lowmem_reserve_ratio sysctl changes. 
  14.      * /  
  15.     unsigned  Long        lowmem_reserve [MAX_NR_ZONES];   
kernel when allocating memory, it may involve multiple zone, will try to allocate the first zone from zonelist allocation, if that fails it will try the next lower priority zone. We can imagine the application process and add lock memmap allocation, if this Highmem zone can not satisfy the allocation, an attempt is carried out from the Normal distribution. That there is a problem, a request from Highmem Normal zone may run out of memory, and it may well not be recovered, the end result is Normal zone no memory available to the kernel of the normal distribution, and by having a lot of recyclable Highmem memory can not be used effectively.
Therefore, for this case, so Normal zone in the face of the allocation request from Highmem, you can lowmem_reserve Disclaimer: Can I use my memory, but must be reserved lowmem_reserve [HIGHMEM] give me their own use.
Similarly, when from Normal fails, it will try to apply from the DMA allocation zonelist by lowmem_zone [DMA], restrictions and Normal from HIGHMEM allocation request.

  1. /* 
  2.  * results with 256, 32 in the lowmem_reserve sysctl: 
  3.  *  1G machine -> (16M dma, 800M-16M normal, 1G-800M high) 
  4.  *  1G machine -> (16M dma, 784M normal, 224M high) 
  5.  *  NORMAL allocation will leave 784M/256 of ram reserved in the ZONE_DMA 
  6.  *  HIGHMEM allocation will leave 224M/32 of ram reserved in ZONE_NORMAL 
  7.  *  HIGHMEM allocation will (224M+784M)/256 of ram reserved in ZONE_DMA 
  8.  * 
  9.  * TBD: should special case ZONE_DMA32 machines here - in those we normally 
  10.  * don't need any ZONE_NORMAL reservation 
  11.  */  
  12.  #ifdef CONFIG_ZONE_DMA  
  13.      256,  
  14. #endif  
  15. #ifdef CONFIG_ZONE_DMA32  
  16.      256,  
  17. #endif  
  18. #ifdef CONFIG_HIGHMEM  
  19.      32,  
  20. #endif  
  21.      32,  

Note: From this zone assignment, without lowmem_reserve restrictions.

No comments:

Post a Comment