@@ -66,30 +66,7 @@ static void verify_ksm(void)
static void setup(void)
{
- if (access(PATH_KSM, F_OK) == -1)
- tst_brk(TCONF, "KSM configuration is not enabled");
-
parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
-
- /*
- * kernel commit 90bd6fd introduced a new KSM sysfs knob
- * /sys/kernel/mm/ksm/merge_across_nodes, setting it to '0'
- * will prevent KSM pages being merged across numa nodes,
- * which will cause the case fail, so we need to make sure
- * it is enabled before testing.
- */
- if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
- SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
- "%d", &merge_across_nodes);
- SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
- }
-}
-
-static void cleanup(void)
-{
- if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
- FILE_PRINTF(PATH_KSM "merge_across_nodes",
- "%d", merge_across_nodes);
}
static struct tst_test test = {
@@ -102,11 +79,17 @@ static struct tst_test test = {
{}
},
.setup = setup,
- .cleanup = cleanup,
.save_restore = (const struct tst_path_val const[]) {
+ {"!/sys/kernel/mm/ksm/run", NULL},
+ {"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+ {"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
NULL,
},
+ .needs_kconfigs = (const char *const[]){
+ "CONFIG_KSM=y",
+ NULL
+ },
.test_all = verify_ksm,
.min_kver = "2.6.32",
};
@@ -82,26 +82,9 @@ static void verify_ksm(void)
SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid());
}
-static void cleanup(void)
-{
- if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
- FILE_PRINTF(PATH_KSM "merge_across_nodes",
- "%d", merge_across_nodes);
- }
-}
-
static void setup(void)
{
- if (access(PATH_KSM, F_OK) == -1)
- tst_brk(TCONF, "KSM configuration is not enabled");
-
parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
-
- if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
- SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
- "%d", &merge_across_nodes);
- SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
- }
}
static struct tst_test test = {
@@ -114,11 +97,17 @@ static struct tst_test test = {
{}
},
.setup = setup,
- .cleanup = cleanup,
.save_restore = (const struct tst_path_val const[]) {
+ {"!/sys/kernel/mm/ksm/run", NULL},
+ {"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+ {"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
NULL,
},
+ .needs_kconfigs = (const char *const[]){
+ "CONFIG_KSM=y",
+ NULL
+ },
.test_all = verify_ksm,
.min_kver = "2.6.32",
.needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
@@ -66,29 +66,12 @@ static void verify_ksm(void)
static void setup(void)
{
- if (access(PATH_KSM, F_OK) == -1)
- tst_brk(TCONF, "KSM configuration is not enabled");
-
- if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
- SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
- "%d", &merge_across_nodes);
- SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
- }
-
parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
}
-static void cleanup(void)
-{
- if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
- FILE_PRINTF(PATH_KSM "merge_across_nodes",
- "%d", merge_across_nodes);
- }
-}
-
static struct tst_test test = {
.needs_root = 1,
.forks_child = 1,
@@ -99,11 +82,17 @@ static struct tst_test test = {
{}
},
.setup = setup,
- .cleanup = cleanup,
.save_restore = (const struct tst_path_val const[]) {
+ {"!/sys/kernel/mm/ksm/run", NULL},
+ {"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+ {"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
NULL,
},
+ .needs_kconfigs = (const char *const[]){
+ "CONFIG_KSM=y",
+ NULL
+ },
.test_all = verify_ksm,
.min_kver = "2.6.32",
.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
@@ -82,24 +82,8 @@ static void verify_ksm(void)
create_same_memory(size, num, unit);
}
-static void cleanup(void)
-{
- if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
- FILE_PRINTF(PATH_KSM "merge_across_nodes",
- "%d", merge_across_nodes);
-}
-
static void setup(void)
{
- if (access(PATH_KSM, F_OK) == -1)
- tst_brk(TCONF, "KSM configuration is not enabled");
-
- if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
- SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
- "%d", &merge_across_nodes);
- SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
- }
-
parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
@@ -115,11 +99,17 @@ static struct tst_test test = {
{}
},
.setup = setup,
- .cleanup = cleanup,
.save_restore = (const struct tst_path_val const[]) {
+ {"!/sys/kernel/mm/ksm/run", NULL},
+ {"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+ {"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
NULL,
},
+ .needs_kconfigs = (const char *const[]){
+ "CONFIG_KSM=y",
+ NULL
+ },
.test_all = verify_ksm,
.min_kver = "2.6.32",
.needs_cgroup_ctrls = (const char *const []){
@@ -83,32 +83,19 @@ static void sighandler(int sig)
_exit((sig == SIGSEGV) ? 0 : sig);
}
-static void setup(void)
-{
- if (access(PATH_KSM, F_OK) == -1)
- tst_brk(TCONF, "KSM configuration is not enabled");
-
- /* save original /sys/kernel/mm/ksm/run value */
- SAFE_FILE_SCANF(PATH_KSM "run", "%d", &ksm_run_orig);
-
- /* echo 1 > /sys/kernel/mm/ksm/run */
- SAFE_FILE_PRINTF(PATH_KSM "run", "1");
-}
-
-static void cleanup(void)
-{
- /* restore /sys/kernel/mm/ksm/run value */
- if (ksm_run_orig > 0)
- FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig);
-}
-
static struct tst_test test = {
.needs_root = 1,
.forks_child = 1,
- .setup = setup,
- .cleanup = cleanup,
.test_all = test_ksm,
.min_kver = "2.6.32",
+ .save_restore = (const struct tst_path_val const[]) {
+ {"!/sys/kernel/mm/ksm/run", "1"},
+ NULL,
+ },
+ .needs_kconfigs = (const char *const[]){
+ "CONFIG_KSM=y",
+ NULL
+ },
};
#else
@@ -9,8 +9,6 @@
#include "tst_test.h"
-int merge_across_nodes;
-
int size = 128, num = 3, unit = 1;
char *opt_sizestr, *opt_numstr, *opt_unitstr;