blob: 22b811dc8fe49ed2dd71d0ee66801802fc75a4d5 [file] [log] [blame]
Garrett Cooperd2deda92011-01-18 01:43:39 -08001/*
2 * Out Of Memory (OOM) for NUMA
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#include "test.h"
32#include "usctest.h"
33#include "config.h"
34
35char *TCID = "oom02";
36int TST_TOTAL = 1;
37extern int Tst_count;
38
39#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
40 && HAVE_MPOL_CONSTANTS
41#include <sys/types.h>
42#include <sys/stat.h>
43#include <fcntl.h>
44#include <stdio.h>
45#include <errno.h>
46#include "lib/oom.h"
47
48static void setup(void);
49
50int main(int argc, char *argv[])
51{
52 char *msg;
53 int lc, fd;
54 unsigned long nnodes = 1;
55
56 msg = parse_opts(argc, argv, NULL, NULL);
57 if (msg != NULL)
58 tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
59
60#ifdef __i386__
61 tst_brkm(TCONF, tst_exit,
62 "this test is not designed for 32-bit system.");
63#endif /* __i386__ */
64
65 nnodes = count_numa();
66 if (count_numa() == 1)
67 tst_brkm(TCONF, tst_exit, "required a NUMA system.");
68
69 setup();
70
71 for (lc = 0; TEST_LOOPING(lc); lc++) {
72 Tst_count = 0;
73 fd = open(SYSFS_OVER, O_WRONLY);
74 if (fd == -1)
75 tst_brkm(TBROK|TERRNO, cleanup, "open");
76 if (write(fd, "1", 1) != 1)
77 tst_brkm(TBROK|TERRNO, cleanup, "write");
78 close(fd);
79
80 tst_resm(TINFO, "process mempolicy.");
81 testoom(1, 0);
82
83 tst_resm(TINFO, "process cpuset.");
84 testoom(0, 0);
85 }
86 cleanup();
87}
88
89void setup(void)
90{
91 int fd;
92
93 tst_sig(FORK, DEF_HANDLER, cleanup);
94 TEST_PAUSE;
95
96 fd = open(SYSFS_OVER, O_RDONLY);
97 if (fd == -1)
98 tst_brkm(TBROK|TERRNO, cleanup, "open");
99 if (read(fd, &overcommit, 1) != 1)
100 tst_brkm(TBROK|TERRNO, cleanup, "read");
101 close(fd);
102
103 mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW);
104}
105
106void cleanup(void)
107{
108 int fd;
109
110 fd = open(SYSFS_OVER, O_WRONLY);
111 if (fd == -1)
112 tst_brkm(TBROK|TERRNO, cleanup, "open");
113 if (write(fd, &overcommit, 1) != 1)
114 tst_brkm(TBROK|TERRNO, cleanup, "write");
115 close(fd);
116
117 umount_mem(CPATH, CPATH_NEW);
118
119 TEST_CLEANUP;
120 tst_exit();
121}
122
123#else /* no NUMA */
124int main(void)
125{
126 tst_resm(TCONF, "no NUMA development packages installed.");
127 tst_exit();
128}
129#endif