Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 35 | char *TCID = "oom02"; |
| 36 | int TST_TOTAL = 1; |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 37 | |
| 38 | #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \ |
| 39 | && HAVE_MPOL_CONSTANTS |
| 40 | #include <sys/types.h> |
| 41 | #include <sys/stat.h> |
| 42 | #include <fcntl.h> |
| 43 | #include <stdio.h> |
| 44 | #include <errno.h> |
| 45 | #include "lib/oom.h" |
| 46 | |
| 47 | static void setup(void); |
| 48 | |
| 49 | int main(int argc, char *argv[]) |
| 50 | { |
| 51 | char *msg; |
| 52 | int lc, fd; |
| 53 | unsigned long nnodes = 1; |
| 54 | |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame] | 55 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) |
| 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 | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame] | 58 | #ifdef __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 | |
| 62 | nnodes = count_numa(); |
| 63 | if (count_numa() == 1) |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame] | 64 | tst_brkm(TCONF, NULL, "required a NUMA system."); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 65 | |
| 66 | setup(); |
| 67 | |
| 68 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 69 | Tst_count = 0; |
| 70 | fd = open(SYSFS_OVER, O_WRONLY); |
| 71 | if (fd == -1) |
| 72 | tst_brkm(TBROK|TERRNO, cleanup, "open"); |
| 73 | if (write(fd, "1", 1) != 1) |
| 74 | tst_brkm(TBROK|TERRNO, cleanup, "write"); |
| 75 | close(fd); |
| 76 | |
| 77 | tst_resm(TINFO, "process mempolicy."); |
Garrett Cooper | 4bab335 | 2011-01-18 01:59:16 -0800 | [diff] [blame] | 78 | testoom(1, 0, 1); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 79 | |
| 80 | tst_resm(TINFO, "process cpuset."); |
Garrett Cooper | 4bab335 | 2011-01-18 01:59:16 -0800 | [diff] [blame] | 81 | testoom(0, 0, 1); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 82 | } |
| 83 | cleanup(); |
Garrett Cooper | a11ad22 | 2011-01-18 02:02:55 -0800 | [diff] [blame^] | 84 | tst_exit(); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void setup(void) |
| 88 | { |
| 89 | int fd; |
| 90 | |
Garrett Cooper | d6f4ae1 | 2011-01-18 01:48:55 -0800 | [diff] [blame] | 91 | tst_require_root(NULL); |
| 92 | |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 93 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 94 | TEST_PAUSE; |
| 95 | |
| 96 | fd = open(SYSFS_OVER, O_RDONLY); |
| 97 | if (fd == -1) |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame] | 98 | tst_brkm(TBROK|TERRNO, NULL, "open"); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 99 | if (read(fd, &overcommit, 1) != 1) |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame] | 100 | tst_brkm(TBROK|TERRNO, NULL, "read"); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 101 | close(fd); |
| 102 | |
| 103 | mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); |
| 104 | } |
| 105 | |
| 106 | void 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; |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | #else /* no NUMA */ |
| 123 | int main(void) |
| 124 | { |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame] | 125 | tst_brkm(TCONF, NULL, "no NUMA development packages installed."); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 126 | } |
| 127 | #endif |