blob: 8ea8203d62475af1201214c9511180db40b0a150 [file] [log] [blame]
Zhouping Liu65ca1bd2013-05-13 16:43:28 +08001/*
2 * Copyright (C) 2013 Linux Test Project
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it
13 * is free of the rightful claim of any third person regarding
14 * infringement or the like. Any license provided herein, whether
15 * implied or otherwise, applies only to this software file. Patent
16 * licenses, if any, provided herein do not apply to combinations of
17 * this program with other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
23 */
24
25/*
26 * The case is designed to test new sysfs boolean knob
27 * /sys/kernel/mm/ksm/merge_across_nodes, which was introduced by
28 * commit 90bd6fd31c8097ee (ksm: allow trees per NUMA node).
29 * when merge_across_nodes is set to zero only pages from the same
30 * node are merged, otherwise pages from all nodes can be merged
31 * together.
32 */
33
34#include "config.h"
35#include <sys/types.h>
36#include <sys/stat.h>
37#include <sys/mman.h>
38#include <errno.h>
39#include <fcntl.h>
40#if HAVE_NUMAIF_H
41#include <numaif.h>
42#endif
43#include <signal.h>
44#include <stdio.h>
45#include <unistd.h>
46#include "numa_helper.h"
47#include "test.h"
48#include "safe_macros.h"
Zhouping Liu65ca1bd2013-05-13 16:43:28 +080049#include "mem.h"
50
51char *TCID = "ksm06";
52int TST_TOTAL = 1;
53
54#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
55 && HAVE_MPOL_CONSTANTS
56
57static int run;
58static int sleep_millisecs;
59static int merge_across_nodes;
60static int n_flag;
61static unsigned long nr_pages;
62
63static char *n_opt;
64option_t options[] = {
65 { "n:", &n_flag, &n_opt },
66 { NULL, NULL, NULL }
67};
68static void usage(void);
69
70int main(int argc, char *argv[])
71{
72 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020073 const char *msg;
Zhouping Liu65ca1bd2013-05-13 16:43:28 +080074
75 msg = parse_opts(argc, argv, options, &usage);
76 if (msg != NULL)
77 tst_brkm(TBROK, NULL, "OPTION PASING ERROR - %s", msg);
78 if (n_flag)
79 nr_pages = SAFE_STRTOUL(NULL, n_opt, 0, ULONG_MAX);
80 else
81 nr_pages = 100;
82
83 setup();
84
85 for (lc = 0; TEST_LOOPING(lc); lc++) {
86 tst_count = 0;
87
88 test_ksm_merge_across_nodes(nr_pages);
89 }
90
91 cleanup();
92 tst_exit();
93}
94
95void setup(void)
96{
97 if (access(PATH_KSM "merge_across_nodes", F_OK) == -1)
98 tst_brkm(TCONF, NULL, "no merge_across_nodes sysfs knob");
99
100 if (!is_numa(NULL))
101 tst_brkm(TCONF, NULL, "The case need a NUMA system.");
102
103 /* save the current value */
104 SAFE_FILE_SCANF(NULL, PATH_KSM "run", "%d", &run);
105 SAFE_FILE_SCANF(NULL, PATH_KSM "merge_across_nodes",
106 "%d", &merge_across_nodes);
107 SAFE_FILE_SCANF(NULL, PATH_KSM "sleep_millisecs",
108 "%d", &sleep_millisecs);
109
110 tst_sig(FORK, DEF_HANDLER, cleanup);
111 TEST_PAUSE;
112}
113
114void cleanup(void)
115{
Li Wang8bfd7c12014-12-03 08:11:36 -0500116 FILE_PRINTF(PATH_KSM "merge_across_nodes",
Zhouping Liu65ca1bd2013-05-13 16:43:28 +0800117 "%d", merge_across_nodes);
Li Wang8bfd7c12014-12-03 08:11:36 -0500118 FILE_PRINTF(PATH_KSM "sleep_millisecs",
Zhouping Liu65ca1bd2013-05-13 16:43:28 +0800119 "%d", sleep_millisecs);
Li Wang8bfd7c12014-12-03 08:11:36 -0500120 FILE_PRINTF(PATH_KSM "run", "%d", run);
Zhouping Liu65ca1bd2013-05-13 16:43:28 +0800121}
122
123static void usage(void)
124{
125 printf(" -n x Allocate x pages memory per node\n");
126}
127
128#else /* no NUMA */
129int main(void)
130{
131 tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
132}
133#endif