Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 1 | /* |
Zhouping Liu | 62d50b7 | 2013-03-19 11:40:50 +0800 | [diff] [blame] | 2 | * Out Of Memory (OOM) for mempolicy - need NUMA system support |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 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 | */ |
Caspar Zhang | 79667fa | 2012-03-12 14:41:46 +0800 | [diff] [blame] | 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> |
Zhouping Liu | 4849bb3 | 2013-03-19 11:40:52 +0800 | [diff] [blame^] | 38 | #include "numa_helper.h" |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 39 | #include "test.h" |
| 40 | #include "usctest.h" |
Caspar Zhang | 79667fa | 2012-03-12 14:41:46 +0800 | [diff] [blame] | 41 | #include "mem.h" |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 42 | |
| 43 | char *TCID = "oom02"; |
| 44 | int TST_TOTAL = 1; |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 45 | |
| 46 | #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \ |
| 47 | && HAVE_MPOL_CONSTANTS |
Zhouping Liu | 62d50b7 | 2013-03-19 11:40:50 +0800 | [diff] [blame] | 48 | |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 49 | int main(int argc, char *argv[]) |
| 50 | { |
| 51 | char *msg; |
Caspar Zhang | ff74ba5 | 2012-02-27 16:13:18 +0800 | [diff] [blame] | 52 | int lc; |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 53 | |
Caspar Zhang | 05697c4 | 2012-02-20 19:20:57 +0800 | [diff] [blame] | 54 | msg = parse_opts(argc, argv, NULL, NULL); |
| 55 | if (msg != NULL) |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame] | 56 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 57 | |
Garrett Cooper | 10e5d88 | 2011-01-20 01:29:53 -0800 | [diff] [blame] | 58 | #if __WORDSIZE == 32 |
Garrett Cooper | 4bab335 | 2011-01-18 01:59:16 -0800 | [diff] [blame] | 59 | tst_brkm(TCONF, NULL, "test is not designed for 32-bit system."); |
| 60 | #endif |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 61 | |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 62 | setup(); |
| 63 | |
| 64 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 65 | tst_count = 0; |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 66 | |
Zhouping Liu | 62d50b7 | 2013-03-19 11:40:50 +0800 | [diff] [blame] | 67 | tst_resm(TINFO, "OOM on MPOL_BIND mempolicy..."); |
| 68 | testoom(MPOL_BIND, 0, 1); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 69 | |
Zhouping Liu | 62d50b7 | 2013-03-19 11:40:50 +0800 | [diff] [blame] | 70 | tst_resm(TINFO, "OOM on MPOL_INTERLEAVE mempolicy..."); |
| 71 | testoom(MPOL_INTERLEAVE, 0, 1); |
| 72 | |
| 73 | tst_resm(TINFO, "OOM on MPOL_PREFERRED mempolicy..."); |
| 74 | testoom(MPOL_PREFERRED, 0, 1); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 75 | } |
| 76 | cleanup(); |
Garrett Cooper | a11ad22 | 2011-01-18 02:02:55 -0800 | [diff] [blame] | 77 | tst_exit(); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void setup(void) |
| 81 | { |
Garrett Cooper | d6f4ae1 | 2011-01-18 01:48:55 -0800 | [diff] [blame] | 82 | tst_require_root(NULL); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 83 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 84 | TEST_PAUSE; |
| 85 | |
Zhouping Liu | 4849bb3 | 2013-03-19 11:40:52 +0800 | [diff] [blame^] | 86 | if (!is_numa(NULL)) |
| 87 | tst_brkm(TCONF, NULL, "The case need a NUMA system."); |
Zhouping Liu | 62d50b7 | 2013-03-19 11:40:50 +0800 | [diff] [blame] | 88 | |
Caspar Zhang | ff74ba5 | 2012-02-27 16:13:18 +0800 | [diff] [blame] | 89 | overcommit = get_sys_tune("overcommit_memory"); |
| 90 | set_sys_tune("overcommit_memory", 1, 1); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void cleanup(void) |
| 94 | { |
Caspar Zhang | ff74ba5 | 2012-02-27 16:13:18 +0800 | [diff] [blame] | 95 | set_sys_tune("overcommit_memory", overcommit, 0); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 96 | |
| 97 | TEST_CLEANUP; |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | #else /* no NUMA */ |
| 101 | int main(void) |
| 102 | { |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame] | 103 | tst_brkm(TCONF, NULL, "no NUMA development packages installed."); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 104 | } |
| 105 | #endif |