티스토리 뷰

개발/Linux

OOM killer

Jaeyeon Baek 2011. 9. 21. 08:38


시스템 운영 중에 메모리 할당이 실패하면 kernel은 OOM killer에서 다른 process를 죽여 메모리를 확보합니다. 이때 아무 process나 종료시키는것이 아니라 각 process마다 점수를 매겨 가장 적합한(?) process를 죽이게 되는데 이 점수를 매기는것은 아래와 같습니다, (mm/oom_kill.c)

/**             
 * badness - calculate a numeric value for how bad this task has been
 * @p: task struct of which task we should calculate
 * @uptime: current uptime in seconds
 *                      
 * The formula used is relatively simple and documented inline in the
 * function. The main rationale is that we want to select a good task
 * to kill when we run out of memory.
 *      
 * Good in this context means that:
 * 1) we lose the minimum amount of work done
 * 2) we recover a large amount of memory
 * 3) we don't kill anything innocent of eating tons of memory
 * 4) we want to kill the minimum amount of processes (one)
 * 5) we try to kill the process the user expects us to kill, this
 *    algorithm has been meticulously tuned to meet the principle
 *    of least surprise ... (be careful when you change it)
 */


이 과정은 badness()에서 계산되고, task의 pointer를 return 합니다. 그리고 oom_kill_task() 쪽에서 SIGKILL을 task로 보내고 실제 process가 종료되는 과정을 거칩니다.

/proc/'pid num'/oom_score
/proc/'pid num'/oom_adj

위 두 경로의 값을 임의로 지정해서 OOM killer를 잠시 피해 갈 수는 있습니다. 그렇지만, 실제로 OOM killer가 돌기 시작한 이상... 사실 서버의 상태가 이미 좋지(?) 않은 상태 이기 때문에 오래 피해갈 수는 없습니다.

참고 : http://linux-mm.org/OOM_Killer

'개발 > Linux' 카테고리의 다른 글

shell에 종속적이지 않은 상태의 Process?  (1) 2011.09.22
/dev/null 2>&1 의미  (0) 2011.09.21
pid의 최대값  (0) 2011.09.16
kernel thread 목록  (0) 2011.09.05
drop_caches (caches flush)  (0) 2011.09.05
댓글
최근에 올라온 글
최근에 달린 댓글
글 보관함
Total
Today
Yesterday