$ cat /etc/systemd/system/user-cg.slice [Unit] Description=Demo cgroup Before=slices.target [Slice] MemoryAccounting=true MemoryLimit=10M $ uname -a Linux p50-laptop 4.19.14-200.fc28.x86_64 #1 SMP Wed Jan 9 21:30:31 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux $ sudo systemctl daemon-reload && sudo systemctl restart user-cg.slice && sudo systemd-run --slice user-cg.slice --scope bash [root]# /usr/lib/jvm/java-11-openjdk/bin/java -version openjdk version "11.0.1" 2018-10-16 OpenJDK Runtime Environment 18.9 (build 11.0.1+13) OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode, sharing) [root]# /usr/lib/jvm/java-11-openjdk/bin/java -Xlog:os+container=trace -version 2> foo.txt | grep 'Memory Limit is:' | cut -d']' -f4 | sort | uniq Memory Limit is: 9223372036854771712 Memory Limit is: Unlimited [root]# \time -v /usr/lib/jvm/java-11-openjdk/bin/java MemoryLeak Command terminated by signal 9 Command being timed: "/usr/lib/jvm/java-11-openjdk/bin/java MemoryLeak" User time (seconds): 20.41 System time (seconds): 203.58 Percent of CPU this job got: 76% Elapsed (wall clock) time (h:mm:ss or m:ss): 4:53.17 Average shared text size (kbytes): 0 Average unshared data size (kbytes): 0 Average stack size (kbytes): 0 Average total size (kbytes): 0 Maximum resident set size (kbytes): 7344 Average resident set size (kbytes): 0 Major (requiring I/O) page faults: 6653434 Minor (reclaiming a frame) page faults: 8438178 Voluntary context switches: 9575148 Involuntary context switches: 2073213 Swaps: 0 File system inputs: 368049024 File system outputs: 0 Socket messages sent: 0 Socket messages received: 0 Signals delivered: 0 Page size (bytes): 4096 Exit status: 0 $ dmesg | grep -B20 'Killed process.*(java)' [20037.478560] RIP: 0033:0x7fae7fface1c [20037.478562] Code: 24 f2 0f 11 45 e0 f2 0f 11 65 d8 48 89 df e8 8b 5a 45 00 44 8b 63 08 66 0f 28 d0 41 83 fc 04 0f 8e b1 00 00 00 f2 0f 10 45 d8 0f 10 0d 0c 33 81 00 f2 0f 59 c2 f2 0f 58 45 e0 f2 0f 59 45 e8 [20037.478562] RSP: 002b:00007fae7c16bcc0 EFLAGS: 00010206 [20037.478564] RAX: 0000000000000000 RBX: 00007fae78024260 RCX: 0000000000000000 [20037.478564] RDX: 0000000000000001 RSI: 0000000000000bcc RDI: 00007fae78024260 [20037.478565] RBP: 00007fae7c16bcf0 R08: 0000000000000000 R09: 0000000000000695 [20037.478565] R10: 00007fae7c16bc70 R11: 0000000000000206 R12: 000000000000000a [20037.478566] R13: 00007fae348cb980 R14: 0000000000000001 R15: 0000000000000bcc [20037.478567] Task in /user.slice/user-cg.slice/run-r47a38b861d1b413bbbef0f3c23433c46.scope killed as a result of limit of /user.slice/user-cg.slice [20037.478570] memory: usage 10240kB, limit 10240kB, failcnt 20752030 [20037.478570] memory+swap: usage 1764220kB, limit 9007199254740988kB, failcnt 0 [20037.478571] kmem: usage 9112kB, limit 9007199254740988kB, failcnt 0 [20037.478571] Memory cgroup stats for /user.slice/user-cg.slice: cache:0KB rss:0KB rss_huge:0KB shmem:0KB mapped_file:0KB dirty:0KB writeback:0KB swap:0KB inactive_anon:0KB active_anon:0KB inactive_file:0KB active_file:0KB unevictable:0KB [20037.478577] Memory cgroup stats for /user.slice/user-cg.slice/run-r47a38b861d1b413bbbef0f3c23433c46.scope: cache:616KB rss:536KB rss_huge:0KB shmem:0KB mapped_file:264KB dirty:0KB writeback:264KB swap:1753884KB inactive_anon:0KB active_anon:0KB inactive_file:348KB active_file:248KB unevictable:0KB [20037.478583] Tasks state (memory values in pages): [20037.478583] [ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name [20037.478754] [ 270133] 0 270133 59905 964 118784 3288 0 bash [20037.478758] [ 270658] 0 270658 1081 168 57344 20 0 time [20037.478759] [ 270659] 0 270659 3073102 0 4141056 435406 0 java [20037.478761] Memory cgroup out of memory: Kill process 270659 (java) score 111 or sacrifice child [20037.478816] Killed process 270659 (java) total-vm:12292408kB, anon-rss:0kB, file-rss:0kB, shmem-rss:0kB [root]# cat MemoryLeak.java import java.util.Map; import java.util.HashMap; public class MemoryLeak { private static final Map leak = new HashMap(); private static final int MB = 1024 * 1024; public static void main(String[] args) { int bound = 10 * MB; for (int i = 0; i < bound; i++) { Byte[] payload = new Byte[10]; for (int j = 1; j <= 10; j++) { payload[j-1] = new Byte((byte)j); } String key = "key_" + i; leak.put(key, payload); } } }