Suppose I've disabled all the oom related features(no OOM killer). A process has occupied all the available memory and it's still trying to read some bytes from a mmapped disk file, which is not in any page caches. Will this process get a OOM signal so that it can reactively release some memory and retry later?
2 Answers
If you have disabled the oom-killer
then the process won't get a signal but malloc()
calls will fail once the memory is exhausted.

- 152,036
- 28
- 249
- 266
-
Thanks. Mainly I'm curious about what will happen if reading a page from uncached mmapped disk file? – Amos May 03 '15 at 08:51
-
Interesting question, I admit that I don't know the answer. Stupid question: Have you tried it? – hek2mgl May 03 '15 at 08:55
It depends on many conditions.
1)how you disable oom-killer?
Let's suppose you write 2 to /proc/sys/vm/overcommit_memory, which mean:
2: always check, never overcommit (see man 5 proc)
After that you called mmap.
2)What flags do you use to in "mmap"?
Let's suppose you use MAP_NORESERVE, in another case (without MAP_NORESERVE) mmap just return error, if not enough physical memory.
3)What is your overcommit_ratio value? Let's suppose it is not zero, if it is zero then mmap return error, and we cann't be in situation where "no pages for file".
If all these suppositions are true, then you come to: mm/oom_kill.c::pagefault_out_of_memory,
and again new condition:
4)May be we in cgroup with oom disable?
If yes, then we just go to sleep.
And at last oom-killer is called
About disable oom
And by "we just go to sleep", do you mean a system pause?
See linux-source/Documentation/cgroups/memory.txt:
If OOM-killer is disabled, tasks under cgroup will hang/sleep in memory cgroup's OOM-waitqueue when they request accountable memory.
So process that part cgroup with disabled oom-killer go to sleep, not all system.
Is it possible that we, the userland process handle this pagefault?
1)It is possible to do this: https://lwn.net/Articles/550555/
2)Or you can just watch oom-killer events.
See again linux-source/Documentation/cgroups/memory.txt:
memory.oom_control file is for OOM notification and other controls.
Memory cgroup implements OOM notifier using the cgroup notification API (See cgroups.txt). It allows to register multiple OOM notification delivery and gets notification when OOM happens.
To register a notifier, an application must:...

- 8,898
- 4
- 28
- 56
-
Thanks for this long if-else explaination. BTW, In mode 2 the MAP_NORESERVE flag is ignored. And by "we just go to sleep", do you mean a system pause? – Amos May 03 '15 at 10:54
-
-
>In mode 2 the MAP_NORESERVE flag is ignored There is in "man 5 proc" description how MAP_NORESERVE handled, and MAP_NORESERVE ignored in mode 0, but not mode 2. – fghj May 03 '15 at 11:04
-
that's interesting. According to this [https://www.kernel.org/doc/Documentation/vm/overcommit-accounting], mode 2 will ignore MAP_NORESERVE flag. – Amos May 03 '15 at 12:58