aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxiao yang <yangx.jy@cn.fujitsu.com>2018-01-05 10:48:50 +0800
committerCyril Hrubis <chrubis@suse.cz>2018-02-07 17:15:50 +0100
commit254c06ba4ed842f43f0f6f733b1708c3c625244f (patch)
tree8ba5035451f94675b10b04081204a304fcc53cc5
parent158ba345aab6551277e63e5781c371a89fd8f959 (diff)
lib/mem.c: factor out wait_ksmd_full_scan()
Move common wait_ksmd_full_scan() to kernel/lib/ksm_helper.c and create accompanying kernel/include/ksm_helper.h. Signed-off-by: xiao yang <yangx.jy@cn.fujitsu.com> Acked-by: Jan Stancek <jstancek@redhat.com> Acked-by: Cyril Hrubis <chrubis@suse.cz>
-rw-r--r--testcases/kernel/include/ksm_helper.h26
-rw-r--r--testcases/kernel/lib/ksm_helper.c49
-rw-r--r--testcases/kernel/mem/include/mem.h3
-rw-r--r--testcases/kernel/mem/lib/mem.c27
4 files changed, 76 insertions, 29 deletions
diff --git a/testcases/kernel/include/ksm_helper.h b/testcases/kernel/include/ksm_helper.h
new file mode 100644
index 000000000..0b352185f
--- /dev/null
+++ b/testcases/kernel/include/ksm_helper.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author(s): Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program, if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KSM_HELPER_H
+#define KSM_HELPER_H
+
+#define PATH_KSM "/sys/kernel/mm/ksm/"
+
+void wait_ksmd_full_scan(void);
+
+#endif /* KSM_HELPER_H */
diff --git a/testcases/kernel/lib/ksm_helper.c b/testcases/kernel/lib/ksm_helper.c
new file mode 100644
index 000000000..eba28d4e3
--- /dev/null
+++ b/testcases/kernel/lib/ksm_helper.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author(s): Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program, if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define TST_NO_DEFAULT_MAIN
+
+#include <unistd.h>
+#include "tst_test.h"
+#include "ksm_helper.h"
+
+void wait_ksmd_full_scan(void)
+{
+ unsigned long full_scans, at_least_one_full_scan;
+ int count = 0;
+
+ SAFE_FILE_SCANF(PATH_KSM "full_scans", "%lu", &full_scans);
+ /*
+ * The current scan is already in progress so we can't guarantee that
+ * the get_user_pages() is called on every existing rmap_item if we
+ * only waited for the remaining part of the scan.
+ *
+ * The actual merging happens after the unstable tree has been built so
+ * we need to wait at least two full scans to guarantee merging, hence
+ * wait full_scans to increment by 3 so that at least two full scans
+ * will run.
+ */
+ at_least_one_full_scan = full_scans + 3;
+ while (full_scans < at_least_one_full_scan) {
+ sleep(1);
+ count++;
+ SAFE_FILE_SCANF(PATH_KSM "full_scans", "%lu", &full_scans);
+ }
+
+ tst_res(TINFO, "ksm daemon takes %ds to run two full scans", count);
+}
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 95d0bda72..f7682f9a9 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -2,6 +2,7 @@
#define _MEM_H
#include "config.h"
#include "tst_test.h"
+#include "ksm_helper.h"
#if defined(__powerpc__) || defined(__powerpc64__)
#define MAXNODES 256
@@ -42,8 +43,6 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
/* KSM */
-#define PATH_KSM "/sys/kernel/mm/ksm/"
-
void create_same_memory(int size, int num, int unit);
void save_max_page_sharing(void);
void restore_max_page_sharing(void);
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index 7f2099b9e..59138a0cc 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -268,33 +268,6 @@ static void check(char *path, long int value)
tst_res(TPASS, "%s is %ld.", path, actual_val);
}
-static void wait_ksmd_full_scan(void)
-{
- unsigned long full_scans, at_least_one_full_scan;
- int count = 0;
-
- SAFE_FILE_SCANF(PATH_KSM "full_scans", "%lu", &full_scans);
- /*
- * The current scan is already in progress so we can't guarantee that
- * the get_user_pages() is called on every existing rmap_item if we
- * only waited for the remaining part of the scan.
- *
- * The actual merging happens after the unstable tree has been built so
- * we need to wait at least two full scans to guarantee merging, hence
- * wait full_scans to increment by 3 so that at least two full scans
- * will run.
- */
- at_least_one_full_scan = full_scans + 3;
- while (full_scans < at_least_one_full_scan) {
- sleep(1);
- count++;
- SAFE_FILE_SCANF(PATH_KSM "full_scans", "%lu", &full_scans);
- }
-
- tst_res(TINFO, "ksm daemon takes %ds to run two full scans",
- count);
-}
-
static void final_group_check(int run, int pages_shared, int pages_sharing,
int pages_volatile, int pages_unshared,
int sleep_millisecs, int pages_to_scan)