The decision system appears oom When , What to do . The three accepted values are as follows ：
0 - The default value is , When there is a oom When , Trigger oom killer
1 - The program has cpuset、memory policy、memcg Under the constraint of OOM, Consider not panic, But start OOM killer. Other conditions trigger kernel panic, That is, the system will restart directly
2 - When there is a oom, Direct trigger kernel panic, That is, the system will restart directly
Linux User memory is allocated during read and write , So the system found that the need for memory basically occurs in handle_mm_fault() When （ Other special processes are similar , Here to ignore ）,handle_mm_fault() To allocate memory for missing pages , It's easy to tune alloc_pages() Series of functions , So as to adjust prepare_alloc_pages(), And then enter the __alloc_pages_direct_reclaim(), The buffer that can be cleared to the disk has been cleared once . After that, the memory can't be allocated , I have to enter OMM Killer 了 （pagefault_out_of_memory()）.
In this state , The memory in the system can only be occupied by the running process and kernel , Everybody won't let me , The system is dead
In order to prevent the system from crashing when the physical memory of the system is not enough , And choose the program that takes the most memory , Take it Kill fall ！
swap： stay linux Inside , When physical memory is out of use , And a new program requests to allocate memory , that linux You will choose to exchange data not used by other programs to physical disk (swap out), Wait until the program is ready to use (swap in). The disadvantages of doing so are obvious ,swap in/swap out The price here is higher , Compared to keeping data in memory all the time , More disk reading operations
OOM：out of memory, Referring to linux Inside , Due to system memory pressure , The system will choose to protect some system processes , And some other processes kill fall , Free memory .
How to avoid the process because OOM The mechanism is kill fall ？
- And OOM The related documents are /proc//oom_adj 、 /proc//oom_score. The former is a weight -16 to 15, The default is 0, Set to -17 It means never to be kill, In other cases, the higher the value, the easier it is to be kill. The latter is a value it calculates , It is based on this value to select which processes are kill Dropped .
- Put it on the top for use swap The third method in overcommit Parameters , Because it can't allocate memory, it will return an error , So it's never possible to run out of memory .OOM It won't have an impact .
Reference documents ：https://blog.csdn.net/hu_jing...`