Site Tools


start:memmanagement

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
start:memmanagement [2023/09/14 19:25] – created peterstart:memmanagement [2023/09/14 19:48] (current) peter
Line 1: Line 1:
 +DATE CHECKED THIS PAGE WAS VALID: 14/09/2023 
 +
 On Linux systems, especially Debian some very old defaults are used. While this made sense 10-15 years ago, they are less optimal today, and changing the defaults is a very slow process since the logic is "if it aint broke don't fix it". In some ways this is very useful as little changes, so you can expect a consistent experience between versions. However sometimes there is an issue. This is one of those times. On Linux systems, especially Debian some very old defaults are used. While this made sense 10-15 years ago, they are less optimal today, and changing the defaults is a very slow process since the logic is "if it aint broke don't fix it". In some ways this is very useful as little changes, so you can expect a consistent experience between versions. However sometimes there is an issue. This is one of those times.
  
Line 9: Line 11:
 The 2 tweakable values we will deal with are: The 2 tweakable values we will deal with are:
  
-vm.watermark_scale_factor +  * vm.watermark_scale_factor 
-vm.min_free_kbytes+  vm.min_free_kbytes
  
 Both of these are edited in your sysctrl.conf file and placed at the end. Both of these are edited in your sysctrl.conf file and placed at the end.
 To check your current values you would do something like: To check your current values you would do something like:
 <code> <code>
-cat cat /proc/sys/vm/watermark_scale_factor+cat /proc/sys/vm/watermark_scale_factor
 </code> </code>
  
Line 24: Line 26:
 {{:images:memoryimage.jpg|}} {{:images:memoryimage.jpg|}}
  
 +On the left is the default option. On the right an 8GB system that has had the optimizations I suggest is displayed. 
  
 +The min value is calculated from the min_free_kbytes. That is about 64MB. The scale factor determines the low and high value by multiplying the system RAM by the scale factor and adding it to the min_free_kbytes. In our example that is 8192*0.1% = 8MB. 64MB is thus the minimum value, and 64+8 = 72MB for the low value and +8 again for 80MB which is the high value.
 +
 +This determines that once the system falls below 72MB kswapd wakes up and starts trying to reclaim memory pages. It stops doing this when it gets back to 80MB. However as the next limit is very close (just 64MB) the possibility exists that the application requesting memory will likely request more than 8MB, meaning it will immediately hit the min limit. When this happens all memory requests are placed in a queue and served only when memory is freed up. This is very irritating for an end user on a desktop system.
 +
 +So lets set some different values. My testing has resulted in a suggestion of 2.5% of total memory for both the minimum and scale factors. This was done with trial and error so I am sure that more optimal values exist, however they serve as just fine values in my testing and do not cause any problems.
 +
 +So for an 8GB system, 2.5% is 8192*2.5% which is approximately 204MB or around 204000K. Please do not fixate on exact values, the computer does not care all that much.
 +
 +So what we want to do is set a minimum of 204000 min_free_kbytes per 8GB and scale factor of 2.5% which is a value of 250. This will result in the example on the right hand side of the diagram. To clarify, if you have some other multiple of RAM you can multiply the min_free_kbytes by the multiple. The scale factor will stay the same. So here are the values:
 +
 +  * 8GB - 204000
 +  * 16GB - 408000
 +  * 32GB - 816000
 +
 +And so on. This means that Your system will start reclaiming memory when 5% is left and stop when it reaches 7.5% of total RAM. This is more logical to me but you can set other values if you have some disagreement, Im just telling you what worked for me.
 +
 +To edit this simply:
 +<code>
 +sudo nano /etc/sysctl.conf
 +</code>
 +and add to the end of the file:
 +<code>
 +vm.watermark_scale_factor=250
 +vm.min_free_kbytes= INSERT YOUR VALUE HERE
 +</code>
  
 +After a reboot you can check the values are accepted and you have tweaked the memory performance of the system :)
  
 +=== Notes ===
 +Notes:
  
start/memmanagement.1694719514.txt.gz · Last modified: 2023/09/14 19:25 by peter