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  Red Hat, Inc.
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of version 2 of the GNU General Public
13  * License as published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it would be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * Further, this software is distributed without any warranty that it
20  * is free of the rightful claim of any third person regarding
21  * infringement or the like.  Any license provided herein, whether
22  * implied or otherwise, applies only to this software file.  Patent
23  * licenses, if any, provided herein do not apply to combinations of
24  * this program with other software, or any other product whatsoever.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write the Free Software
28  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29  * 02110-1301, USA.
30  */
31 
32 #include "config.h"
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <errno.h>
36 #include <fcntl.h>
37 #include <stdio.h>
38 #include "numa_helper.h"
39 #include "test.h"
40 #include "mem.h"
41 
42 char *TCID = "oom02";
43 int TST_TOTAL = 1;
44 
45 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
46 	&& HAVE_MPOL_CONSTANTS
47 
main(int argc,char * argv[])48 int main(int argc, char *argv[])
49 {
50 	int lc;
51 
52 	tst_parse_opts(argc, argv, NULL, NULL);
53 
54 #if __WORDSIZE == 32
55 	tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
56 #endif
57 
58 	setup();
59 
60 	for (lc = 0; TEST_LOOPING(lc); lc++) {
61 		tst_count = 0;
62 
63 		tst_resm(TINFO, "OOM on MPOL_BIND mempolicy...");
64 		testoom(MPOL_BIND, 0, ENOMEM, 1);
65 
66 		tst_resm(TINFO, "OOM on MPOL_INTERLEAVE mempolicy...");
67 		testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
68 
69 		tst_resm(TINFO, "OOM on MPOL_PREFERRED mempolicy...");
70 		testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
71 	}
72 	cleanup();
73 	tst_exit();
74 }
75 
setup(void)76 void setup(void)
77 {
78 	tst_require_root();
79 	tst_sig(FORK, DEF_HANDLER, cleanup);
80 	TEST_PAUSE;
81 
82 	if (!is_numa(NULL, NH_MEMS, 2))
83 		tst_brkm(TCONF, NULL, "The case need a NUMA system.");
84 
85 	overcommit = get_sys_tune("overcommit_memory");
86 	set_sys_tune("overcommit_memory", 1, 1);
87 }
88 
cleanup(void)89 void cleanup(void)
90 {
91 	set_sys_tune("overcommit_memory", overcommit, 0);
92 }
93 
94 #else /* no NUMA */
main(void)95 int main(void)
96 {
97 	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
98 }
99 #endif
100