Como o kernel oom score é calculado?

9

Visualizou no Google e não conseguiu encontrar nada que explicasse como a pontuação em proc/<pid>/oom_score é calculada. Por que usar essa pontuação em vez de usar apenas a memória total usada?

    
por James Kingsbery 31.01.2014 / 16:45

1 resposta

15

Veja o artigo de 2009 de Goldwyn Rodrigues para a implementação na época, artigo de 2010 pelo que acredito ser o comportamento atual, e o artigo de 2013 de Jonathan Corbet para ideias sobre futuras mudanças.

Do artigo de 2010:

In David's patch set, the old badness() heuristics are almost entirely gone. Instead, the calculation turns into a simple question of what percentage of the available memory is being used by the process. If the system as a whole is short of memory, then "available memory" is the sum of all RAM and swap space available to the system. If, instead, the OOM situation is caused by exhausting the memory allowed to a given cpuset/control group, then "available memory" is the total amount allocated to that control group. A similar calculation is made if limits imposed by a memory policy have been exceeded. In each case, the memory use of the process is deemed to be the sum of its resident set (the number of RAM pages it is using) and its swap usage.

This calculation produces a percent-times-ten number as a result; a process which is using every byte of the memory available to it will have a score of 1000, while a process using no memory at all will get a score of zero. There are very few heuristic tweaks to this score, but the code does still subtract a small amount (30) from the score of root-owned processes on the notion that they are slightly more valuable than user-owned processes.

One other tweak which is applied is to add the value stored in each process's oom_score_adj variable, which can be adjusted via /proc. This knob allows the adjustment of each process's attractiveness to the OOM killer in user space; setting it to -1000 will disable OOM kills entirely, while setting to +1000 is the equivalent of painting a large target on the associated process.

    
por 31.01.2014 / 17:03

Tags