blob: 7a726c89fbf4f0034b58cb7c015440355c8aa4ba [file] [log] [blame]
Garrett Cooperd2deda92011-01-18 01:43:39 -08001/*
Zhouping Liu62d50b72013-03-19 11:40:50 +08002 * Out Of Memory (OOM) for mempolicy - need NUMA system support
Garrett Cooperd2deda92011-01-18 01:43:39 -08003 *
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 */
Caspar Zhang79667fa2012-03-12 14:41:46 +080031
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>
Zhouping Liu4849bb32013-03-19 11:40:52 +080038#include "numa_helper.h"
Garrett Cooperd2deda92011-01-18 01:43:39 -080039#include "test.h"
40#include "usctest.h"
Caspar Zhang79667fa2012-03-12 14:41:46 +080041#include "mem.h"
Garrett Cooperd2deda92011-01-18 01:43:39 -080042
43char *TCID = "oom02";
44int TST_TOTAL = 1;
Garrett Cooperd2deda92011-01-18 01:43:39 -080045
46#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
47 && HAVE_MPOL_CONSTANTS
Zhouping Liu62d50b72013-03-19 11:40:50 +080048
Garrett Cooperd2deda92011-01-18 01:43:39 -080049int main(int argc, char *argv[])
50{
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020051 const char *msg;
Caspar Zhangff74ba52012-02-27 16:13:18 +080052 int lc;
Garrett Cooperd2deda92011-01-18 01:43:39 -080053
Caspar Zhang05697c42012-02-20 19:20:57 +080054 msg = parse_opts(argc, argv, NULL, NULL);
55 if (msg != NULL)
Garrett Cooper15619ba2011-01-18 01:48:15 -080056 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooperd2deda92011-01-18 01:43:39 -080057
Garrett Cooper10e5d882011-01-20 01:29:53 -080058#if __WORDSIZE == 32
Garrett Cooper4bab3352011-01-18 01:59:16 -080059 tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
60#endif
Garrett Cooperd2deda92011-01-18 01:43:39 -080061
Garrett Cooperd2deda92011-01-18 01:43:39 -080062 setup();
63
64 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080065 tst_count = 0;
Garrett Cooperd2deda92011-01-18 01:43:39 -080066
Zhouping Liu62d50b72013-03-19 11:40:50 +080067 tst_resm(TINFO, "OOM on MPOL_BIND mempolicy...");
Jan Stancek30ac84c2014-07-25 09:58:47 +020068 testoom(MPOL_BIND, 0, ENOMEM, 1);
Garrett Cooperd2deda92011-01-18 01:43:39 -080069
Zhouping Liu62d50b72013-03-19 11:40:50 +080070 tst_resm(TINFO, "OOM on MPOL_INTERLEAVE mempolicy...");
Jan Stancek30ac84c2014-07-25 09:58:47 +020071 testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
Zhouping Liu62d50b72013-03-19 11:40:50 +080072
73 tst_resm(TINFO, "OOM on MPOL_PREFERRED mempolicy...");
Jan Stancek30ac84c2014-07-25 09:58:47 +020074 testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
Garrett Cooperd2deda92011-01-18 01:43:39 -080075 }
76 cleanup();
Garrett Coopera11ad222011-01-18 02:02:55 -080077 tst_exit();
Garrett Cooperd2deda92011-01-18 01:43:39 -080078}
79
80void setup(void)
81{
Garrett Cooperd6f4ae12011-01-18 01:48:55 -080082 tst_require_root(NULL);
Garrett Cooperd2deda92011-01-18 01:43:39 -080083 tst_sig(FORK, DEF_HANDLER, cleanup);
84 TEST_PAUSE;
85
Zhouping Liu4849bb32013-03-19 11:40:52 +080086 if (!is_numa(NULL))
87 tst_brkm(TCONF, NULL, "The case need a NUMA system.");
Zhouping Liu62d50b72013-03-19 11:40:50 +080088
Caspar Zhangff74ba52012-02-27 16:13:18 +080089 overcommit = get_sys_tune("overcommit_memory");
90 set_sys_tune("overcommit_memory", 1, 1);
Garrett Cooperd2deda92011-01-18 01:43:39 -080091}
92
93void cleanup(void)
94{
Caspar Zhangff74ba52012-02-27 16:13:18 +080095 set_sys_tune("overcommit_memory", overcommit, 0);
Garrett Cooperd2deda92011-01-18 01:43:39 -080096
97 TEST_CLEANUP;
Garrett Cooperd2deda92011-01-18 01:43:39 -080098}
99
100#else /* no NUMA */
101int main(void)
102{
Garrett Cooper15619ba2011-01-18 01:48:15 -0800103 tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
Garrett Cooperd2deda92011-01-18 01:43:39 -0800104}
105#endif