Trigger OOM Killer with a minimal example?

Behrooz Nobakht nobeh5 at gmail.com
Sat Sep 5 12:07:47 UTC 2015


Hi,

I have been trying to create a minimal example/setting to be able to
trigger
the Unix OOM Killer.

Here is the general scenario that I follow:

1. Setup up a machine with `X` MB of memory
2. Configure the machine to have `Y` MB of swap space
3. Run the Java example
4. Observe in `dmesg` the killing happens

For (1), I use a small virtual machine on VB using Ubuntu 14.04.03-server
with X ~= 1000MB memory

```3.19.0-26-generic #28~14.04.1-Ubuntu SMP Wed Aug 12 14:09:17 UTC 2015
x86_64 x86_64 x86_64 GNU/Linux```

For (2), I use a small script to make the necessary swap space with Y = 64MB
https://gist.github.com/nobeh/8924c2f5292d54b3fba9#file-create-swap-sh

For (3), I use a small Java example at:
https://gist.github.com/nobeh/8924c2f5292d54b3fba9#file-killer-java

and this is how I run the program (to preserve our live environment
settings):
https://gist.github.com/nobeh/8924c2f5292d54b3fba9#file-run-sh

I have three "types" of observations:

Type1: OOM Killer triggered
Sometimes, the example indeed leads to triggering OOM Killer with the
following messages
in `dmesg`:

```
[ 8072.902446] Out of memory: Kill process 2619 (java) score 865 or
sacrifice child
[ 8072.904516] Killed process 2619 (java) total-vm:2214952kB,
anon-rss:885596kB, file-rss:0kB
```

Type2: VM failure with an hs_ error log
Other times the run leads to the following error message:

```
Java HotSpot(TM) 64-Bit Server VM warning: INFO:
os::commit_memory(0x00000000f4400000, 111149056, 0) failed; error='Cannot
allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 111149056 bytes for
committing reserved memory.
# An error report file with more information is saved as:
# /home/behrooz/hs_err_pid3030.log
```

I can provide the logs if necessary.

Type3: OutOfMemoryError: Java heap space
And, sometimes, the program actually exits with an OutOfMemoryError

```
[    1825] *** ERROR ***
java.lang.OutOfMemoryError: Java heap space
at Killer$KillerArrays.<init>(Killer.java:21)
at Killer.main(Killer.java:51)
```

Having said the above, I understand that "consistently" triggering OOM
Killer can be hard considering OS configurations and runtime state.
If it is possible to do this, what am I missing? How can I "consistently"
make the program killed by OOM Killer?

Thanks,
Behrooz


More information about the jdk9-dev mailing list