Linux内存过量使用详细信息 [英] Linux memory overcommit details
问题描述
我正在开发用于嵌入式Linux的软件,并且由于OOM Killer会不时出现而使系统挂起.在超越之前,我想解决一些关于Linux内核如何分配动态内存的令人困惑的问题,假设/proc/sys/vm/overcommit_memory为0,/proc/sys/vm/min_free_kbytes为712,并且没有交换.
I am developing SW for embedded Linux and i am suffering system hangs because OOM Killer appears from time to time. Before going beyond i would like to solve some confusing issues about how Linux Kernel allocate dynamic memory assuming /proc/sys/vm/overcommit_memory has 0 and /proc/sys/vm/min_free_kbytes has 712, and no swap.
如果我编写这段代码,假设当前可用的嵌入式Linux物理内存为5MB(5MB的可用内存,并且没有可用的缓存或缓冲内存):
Supposing embedded Linux currently physical memory available is 5MB (5MB of free memory and there is not usable cached or buffered memory available) if i write this piece of code:
.....
#define MEGABYTE 1024*1024
.....
.....
void *ptr = NULL;
ptr = (void *) malloc(6*MEGABYTE); //Preserving 6MB
if (!prt)
exit(1);
memset(ptr, 1, MEGABYTE);
.....
我想知道何时提交memset调用时,内核将尝试在物理内存空间中分配〜6MB或〜1MB(或min_free_kbytes倍数).
I would like to know if when memset call is committed the kernel will try to allocate ~6MB or ~1MB (or min_free_kbytes multiple) in the physical memory space.
现在,我的嵌入式设备中大约有9MB的内存,其中有32MB的RAM.我通过
Right now there is about 9MB in my embedded device which has 32MB RAM. I check it by doing
# echo 3 > /proc/sys/vm/drop_caches
# free
total used free shared buffers
Mem: 23732 14184 9548 0 220
Swap: 0 0 0
Total: 23732 14184 9548
我忘记了最后的C代码,我想知道当例如空闲内存大约> 6MB时是否有可能出现oom killer. 我想知道oom出现时系统是否内存不足,所以我想我有两个选择:
Forgetting last piece of C code, i would like to know if its possible that oom killer appears when for instance free memory is about >6MB. I want to know if the system is out of memory when oom appears, so i think i have two options:
-
请参阅/proc/pid/可疑进程状态中的VmRSS条目.
See VmRSS entries in /proc/pid/status of suspicious process.
设置/proc/sys/vm/overcommit_memory = 2和/proc/sys/vm/overcommit_memory = 75,看看是否有任何需要更多物理内存的进程.
Set /proc/sys/vm/overcommit_memory = 2 and /proc/sys/vm/overcommit_memory = 75 and see if there is any process requiring more of physical memory available.
推荐答案
I think you can read this document. Is provides you three small C programs that you can use to understand what happens with the different possible values of /proc/sys/vm/overcommit_memory
.
这篇关于Linux内存过量使用详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!