[52794.911008] lowmemorykiller: Killing 'FinalizerDaemon' (17589), adj 904,
[52794.911008] to free 53160kB on behalf of 'kworker/3:4' (18339) because
[52794.911008] cache 199320kB is below limit 221184kB for oom_score_adj 900
[52794.911008] Free memory is 24024kB above reserved.
[52794.911008] Free CMA is 0kB
[52794.911008] Total reserve is 42396kB
[52794.911008] Total free pages is 32556kB
[52794.911008] Total file cache is 234748kB
[52794.911008] Total zcache is 0kB
[52794.911008] GFP mask is 0x24080c0
1, choose oom_score_adj
221184kB : 55296 pages
129024kB : 32256 pages
other_free: 24024kB
other_file: 199320kB
1.1 choose condition:
other_file > lowmem_minfree[i-1] || other file > lowmem_minfree[i-1]
and
other_file < lowmem_minfree[i] && other file > lowmem_minfree[i]
for (i = 0; i < array_size; i++) {
minfree = lowmem_minfree[i];
if (other_free < minfree && other_file < minfree) {
min_score_adj = lowmem_adj[i];
break;
}
}
1.2
cache 199320kB is below limit 221184kB for oom_score_adj 900
root@ailsa_ii:/sys/module/lowmemorykiller/parameters # cat adj
0,58,117,176,900,1000
root@ailsa_ii:/sys/module/lowmemorykiller/parameters # cat minfree
18432,23040,27648,32256,55296,80640
221184kB : 55296 pages
129024kB : 32256 pages
other_free: 24024kB
other_file: 199320kB
selected_oom_score_adj = 900
2, choose the process which have largest oom_score_adj with largest tasksize .
for_each_process(tsk) {
struct task_struct *p;
short oom_score_adj;
...
oom_score_adj = p->signal->oom_score_adj;
if (oom_score_adj < min_score_adj) {
task_unlock(p);
continue;
}
tasksize = get_mm_rss(p->mm);
task_unlock(p);
if (tasksize <= 0)
continue;
if (selected) {
if (oom_score_adj < selected_oom_score_adj)
continue;
if (oom_score_adj == selected_oom_score_adj &&
tasksize <= selected_tasksize)
continue;
}
selected = p;
selected_tasksize = tasksize;
selected_oom_score_adj = oom_score_adj;
lowmem_print(3, "select '%s' (%d), adj %hd, size %d, to kill\n",
p->comm, p->pid, oom_score_adj, tasksize);
}
3, kill
if (selected) {
long cache_size, cache_limit, free;
task_lock(selected);
send_sig(SIGKILL, selected, 0);
...
task_unlock(selected);
cache_size = other_file * (long)(PAGE_SIZE / 1024);
cache_limit = minfree * (long)(PAGE_SIZE / 1024);
free = other_free * (long)(PAGE_SIZE / 1024);
trace_lowmemory_kill(selected, cache_size, cache_limit, free);
lowmem_print(1, "Killing '%s' (%d), adj %hd,\n" \
" to free %ldkB on behalf of '%s' (%d) because\n" \
" cache %ldkB is below limit %ldkB for oom_score_adj %hd\n" \
" Free memory is %ldkB above reserved.\n" \
" Free CMA is %ldkB\n" \
" Total reserve is %ldkB\n" \
" Total free pages is %ldkB\n" \
" Total file cache is %ldkB\n" \
" Total zcache is %ldkB\n" \
" GFP mask is 0x%x\n",
selected->comm, selected->pid,
selected_oom_score_adj,
selected_tasksize * (long)(PAGE_SIZE / 1024),
current->comm, current->pid,
cache_size, cache_limit,
min_score_adj,
free,
global_page_state(NR_FREE_CMA_PAGES) *
(long)(PAGE_SIZE / 1024),
totalreserve_pages * (long)(PAGE_SIZE / 1024),
global_page_state(NR_FREE_PAGES) *
(long)(PAGE_SIZE / 1024),
global_page_state(NR_FILE_PAGES) *
(long)(PAGE_SIZE / 1024),
(long)zcache_pages() * (long)(PAGE_SIZE / 1024),
sc->gfp_mask);