1 /*
2 * Out Of Memory (OOM) for mempolicy - need NUMA system support
3 *
4 * The program is designed to cope with unpredictable like amount and
5 * system physical memory, swap size and other VMM technology like KSM,
6 * memcg, memory hotplug and so on which may affect the OOM
7 * behaviours. It simply increase the memory consumption 3G each time
8 * until all the available memory is consumed and OOM is triggered.
9 *
10 * Copyright (C) 2010-2017 Red Hat, Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
20 * the GNU General Public License for more details.
21 */
22
23 #include "config.h"
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <stdio.h>
29 #if HAVE_NUMA_H
30 #include <numa.h>
31 #endif
32
33 #include "lapi/abisize.h"
34 #include "numa_helper.h"
35 #include "mem.h"
36
37 #ifdef HAVE_NUMA_V2
38
verify_oom(void)39 static void verify_oom(void)
40 {
41 #ifdef TST_ABI32
42 tst_brk(TCONF, "test is not designed for 32-bit system.");
43 #endif
44
45 tst_res(TINFO, "OOM on MPOL_BIND mempolicy...");
46 testoom(MPOL_BIND, 0, ENOMEM, 1);
47
48 tst_res(TINFO, "OOM on MPOL_INTERLEAVE mempolicy...");
49 testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
50
51 tst_res(TINFO, "OOM on MPOL_PREFERRED mempolicy...");
52 testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
53 }
54
setup(void)55 static void setup(void)
56 {
57 if (!is_numa(NULL, NH_MEMS, 2))
58 tst_brk(TCONF, "The case need a NUMA system.");
59
60 overcommit = get_sys_tune("overcommit_memory");
61 set_sys_tune("overcommit_memory", 1, 1);
62 }
63
cleanup(void)64 static void cleanup(void)
65 {
66 if (overcommit != -1)
67 set_sys_tune("overcommit_memory", overcommit, 0);
68 }
69
70 static struct tst_test test = {
71 .needs_root = 1,
72 .forks_child = 1,
73 .timeout = -1,
74 .setup = setup,
75 .cleanup = cleanup,
76 .test_all = verify_oom,
77 };
78
79 #else
80 TST_TEST_TCONF(NUMA_ERROR_MSG);
81 #endif
82