Skip to contentSkip to conversation

mm/thp: new case thp04.c

PATCH Superseded Zhouping Liu 3 participants 7 messages Apr 8, 2013 – Apr 15, 2013 1 message not in the archive

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/3 mm/thp: new case thp04.c

The case is desinged to test THP functionality.

when one process allocate hugepage aligned anonymouse pages, kernel thread 'khugepaged' controlled by sysfs knobs /sys/kernel/mm/transparent_hugepage/* will scan them, and make them as transparent hugepage if they are suited, you can find out how many transparent hugepages are there in one process from /proc/<pid>/smaps, among the file contents, 'AnonHugePages' entry stand for transparent hugepage.

---
 runtest/mm                         |   3 +
 testcases/kernel/mem/include/mem.h |  11 +++
 testcases/kernel/mem/lib/mem.c     | 180 +++++++++++++++++++++++++++++++++++++
 testcases/kernel/mem/thp/thp04.c   | 136 ++++++++++++++++++++++++++++
 4 files changed, 330 insertions(+)
 create mode 100644 testcases/kernel/mem/thp/thp04.c
runtest/mm +3 -0
index 56b83f8..3fbb20f 100644
@@ -84,6 +84,9 @@ swapping01 swapping01 -i 5
 thp01 thp01 -I 120
 thp02 thp02
 thp03 thp03
+thp04_1 thp04
+thp04_2 thp04 -n 10 -N 20
+thp04_3 thp04 -n 1 -N 300
 
 vma01 vma01
 vma02 vma02
testcases/kernel/mem/include/mem.h +11 -0
index fdf558e..ccae47d 100644
@@ -32,6 +32,17 @@ void testoom(int mempolicy, int lite);
 
 #define PATH_KSM		"/sys/kernel/mm/ksm/"
 
+/* THP */
+
+#define PATH_THP		"/sys/kernel/mm/transparent_hugepage/"
+#define PATH_KHPD		PATH_THP "khugepaged/"
+
+int opt_nr_child, opt_nr_thps;
+char *opt_nr_child_str, *opt_nr_thps_str;
+void test_transparent_hugepage(int nr_child, int nr_thps, int hg_aligned);
+void check_thp_options(int *nr_child, int *nr_thps);
+void thp_usage(void);
+
 /* HUGETLB */
 
 #define PATH_SHMMAX		"/proc/sys/kernel/shmmax"
testcases/kernel/mem/lib/mem.c +180 -0

186 lines not on this page · raw message

testcases/kernel/mem/thp/thp04.c new file +136 -0

136 lines not on this page · raw message

Signature · 13 lines
1.7.11.7


------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#2 lore raw

PATCH 2/3 lib/mem: introduce a new function set_global_mempolicy()

Fork out a new function set_global_mempolicy() from the previous testoom() func, which will be useful for other func.

---
 testcases/kernel/mem/lib/mem.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
testcases/kernel/mem/lib/mem.c +6 -1
index 491afe8..39fa99a 100644
@@ -91,7 +91,7 @@ void oom(int testcase, int lite)
 	}
 }
 
-void testoom(int mempolicy, int lite)
+static void set_global_mempolicy(int mempolicy)
 {
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
 	&& HAVE_MPOL_CONSTANTS
@@ -133,6 +133,11 @@ void testoom(int mempolicy, int lite)
 			tst_brkm(TBROK|TERRNO, cleanup, "set_mempolicy");
 	}
 #endif
+}
+
+void testoom(int mempolicy, int lite)
+{
+	set_global_mempolicy(mempolicy);
 
 	tst_resm(TINFO, "start normal OOM testing.");
 	oom(NORMAL, lite);
Signature · 13 lines
1.7.11.7


------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#3 lore raw

PATCH 3/3 mm/thp: add new case thp05

added new case thp05, which is used to test transparent hugepage under mempolicy.

---
 runtest/mm                         |   3 +
 testcases/kernel/mem/include/mem.h |   3 +-
 testcases/kernel/mem/lib/mem.c     |   6 +-
 testcases/kernel/mem/thp/thp04.c   |   2 +-
 testcases/kernel/mem/thp/thp05.c   | 152 +++++++++++++++++++++++++++++++++++++
 5 files changed, 163 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/mem/thp/thp05.c
runtest/mm +3 -0
index 3fbb20f..7c7abf1 100644
@@ -87,6 +87,9 @@ thp03 thp03
 thp04_1 thp04
 thp04_2 thp04 -n 10 -N 20
 thp04_3 thp04 -n 1 -N 300
+thp05_1 thp05
+thp05_2 thp05 -n 10 -N 20
+thp05_3 thp05 -n 1 -N 300
 
 vma01 vma01
 vma02 vma02
testcases/kernel/mem/include/mem.h +2 -1
index ccae47d..6b020af 100644
@@ -39,7 +39,8 @@ void testoom(int mempolicy, int lite);
 
 int opt_nr_child, opt_nr_thps;
 char *opt_nr_child_str, *opt_nr_thps_str;
-void test_transparent_hugepage(int nr_child, int nr_thps, int hg_aligned);
+void test_transparent_hugepage(int nr_child, int nr_thps,
+			       int hg_aligned, int mempolicy);
 void check_thp_options(int *nr_child, int *nr_thps);
 void thp_usage(void);
 
testcases/kernel/mem/lib/mem.c +5 -1
index 39fa99a..f5a2453 100644
@@ -616,12 +616,16 @@ static void verify_thp_size(int *child, int nr_child, int nr_thps)
 	}
 }
 
-void test_transparent_hugepage(int nr_child, int nr_thps, int hg_aligned)
+void test_transparent_hugepage(int nr_child, int nr_thps,
+			       int hg_aligned, int mempolicy)
 {
 	unsigned long hugepagesize;
 	int i, *pid, ret, status;
 	char path[BUFSIZ];
 
+	if (mempolicy)
+		set_global_mempolicy(mempolicy);
+
 	hugepagesize = read_meminfo("Hugepagesize:");
 
 	pid = (int *)malloc(nr_child * sizeof(int));
testcases/kernel/mem/thp/thp04.c +1 -1
index 2855eb5..a628be3 100644
@@ -83,7 +83,7 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		test_transparent_hugepage(nr_child, nr_thps, 1);
+		test_transparent_hugepage(nr_child, nr_thps, 1, 0);
 	}
 
 	cleanup();
testcases/kernel/mem/thp/thp05.c new file +152 -0

152 lines not on this page · raw message

Signature · 13 lines
1.7.11.7


------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#4 lore raw

Re: [LTP] [PATCH 3/3] mm/thp: add new case thp05

Quoted 141 lines · Zhouping Liu

added new case thp05, which is used to test transparent hugepage under mempolicy.

---
 runtest/mm                         |   3 +
 testcases/kernel/mem/include/mem.h |   3 +-
 testcases/kernel/mem/lib/mem.c     |   6 +-
 testcases/kernel/mem/thp/thp04.c   |   2 +-
 testcases/kernel/mem/thp/thp05.c   | 152 +++++++++++++++++++++++++++++++++++++
 5 files changed, 163 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/mem/thp/thp05.c
runtest/mm +3 -0
index 3fbb20f..7c7abf1 100644
@@ -87,6 +87,9 @@ thp03 thp03
 thp04_1 thp04
 thp04_2 thp04 -n 10 -N 20
 thp04_3 thp04 -n 1 -N 300
+thp05_1 thp05
+thp05_2 thp05 -n 10 -N 20
+thp05_3 thp05 -n 1 -N 300
 
 vma01 vma01
 vma02 vma02
testcases/kernel/mem/include/mem.h +2 -1
index ccae47d..6b020af 100644
@@ -39,7 +39,8 @@ void testoom(int mempolicy, int lite);
 
 int opt_nr_child, opt_nr_thps;
 char *opt_nr_child_str, *opt_nr_thps_str;
-void test_transparent_hugepage(int nr_child, int nr_thps, int hg_aligned);
+void test_transparent_hugepage(int nr_child, int nr_thps,
+			       int hg_aligned, int mempolicy);
 void check_thp_options(int *nr_child, int *nr_thps);
 void thp_usage(void);
 
testcases/kernel/mem/lib/mem.c +5 -1
index 39fa99a..f5a2453 100644
@@ -616,12 +616,16 @@ static void verify_thp_size(int *child, int nr_child, int nr_thps)
 	}
 }
 
-void test_transparent_hugepage(int nr_child, int nr_thps, int hg_aligned)
+void test_transparent_hugepage(int nr_child, int nr_thps,
+			       int hg_aligned, int mempolicy)
 {
 	unsigned long hugepagesize;
 	int i, *pid, ret, status;
 	char path[BUFSIZ];
 
+	if (mempolicy)
+		set_global_mempolicy(mempolicy);
+
 	hugepagesize = read_meminfo("Hugepagesize:");
 
 	pid = (int *)malloc(nr_child * sizeof(int));
testcases/kernel/mem/thp/thp04.c +1 -1
index 2855eb5..a628be3 100644
@@ -83,7 +83,7 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		test_transparent_hugepage(nr_child, nr_thps, 1);
+		test_transparent_hugepage(nr_child, nr_thps, 1, 0);
 	}
 
 	cleanup();
testcases/kernel/mem/thp/thp05.c new file +59 -0
new file mode 100644
index 0000000..7d339cb
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2013 Linux Test Project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * The case is designed to test the functionality of transparent
+ * hugepage - THP under mempolicy (NUMA)
+ *
+ * when one process allocate hugepage aligned anonymouse pages,
+ * kernel thread 'khugepaged' controlled by sysfs knobs
+ * /sys/kernel/mm/transparent_hugepage/ will scan them, and make
+ * them as transparent hugepage if they are suited, you can find out
+ * how many transparent hugepages are there in one process from
+ * /proc/<pid>/smaps, among the file contents, 'AnonHugePages' entry
+ * stand for transparent hugepage.
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "numa_helper.h"
+#include "test.h"
+#include "usctest.h"
+#include "mem.h"
+
+char *TCID = "thp05";
+int TST_TOTAL = 1;
+
+#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
+		&& HAVE_MPOL_CONSTANTS
+

testcases/kernel/mem/thp/thp05.c line 69

Quoted 10 lines
testcases/kernel/mem/thp/thp05.c new file +10 -0
+option_t thp_options[] = {
+	{"n:", &opt_nr_child, &opt_nr_child_str},
+	{"N:", &opt_nr_thps, &opt_nr_thps_str},
+	{NULL, NULL, NULL}
+};
+
+int pre_thp_scan_sleep_millisecs;
+int pre_thp_alloc_sleep_millisecs;
+char pre_thp_enabled[BUFSIZ];
+

static?

Quoted 25 lines
testcases/kernel/mem/thp/thp05.c new file +25 -0
+int main(int argc, char *argv[])
+{
+	int lc;
+	char *msg;
+	int nr_child = 2, nr_thps = 64;
+
+	msg = parse_opts(argc, argv, thp_options, thp_usage);
+	if (msg != NULL)
+		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+	check_thp_options(&nr_child, &nr_thps);
+
+	setup();
+
+	tst_resm(TINFO, "Start to test transparent hugepage...");
+	tst_resm(TINFO, "There are %d children allocating %d "
+			"transparent hugepages", nr_child, nr_thps);
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		tst_resm(TINFO, "THP on MPOL_BIND mempolicy...");
+		test_transparent_hugepage(nr_child, nr_thps, 1, MPOL_BIND);
+
+		tst_resm(TINFO, "THP on MPOL_INTERLEAVE mempolicy...");
+		test_transparent_hugepage(nr_child, nr_thps, 1,
+					  MPOL_INTERLEAVE);

testcases/kernel/mem/thp/thp05.c line 104

Quoted 10 lines
testcases/kernel/mem/thp/thp05.c new file +10 -0
+
+		tst_resm(TINFO, "THP on MPOL_PREFERRED mempolicy...");
+		test_transparent_hugepage(nr_child, nr_thps, 1, MPOL_PREFERRED);
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+void setup(void)

ditto?

Quoted 17 lines
testcases/kernel/mem/thp/thp05.c new file +17 -0
+{
+	char path[BUFSIZ];
+
+	tst_require_root(NULL);
+
+	if (access(PATH_THP, F_OK) == -1)
+		tst_brkm(TCONF, NULL, "THP is not enabled");
+
+	if (!is_numa(NULL))
+		tst_brkm(TCONF, NULL, "The case need a NUMA system.");
+
+	snprintf(path, BUFSIZ, PATH_KHPD "scan_sleep_millisecs");
+	SAFE_FILE_SCANF(NULL, path, "%d", &pre_thp_scan_sleep_millisecs);
+	SAFE_FILE_PRINTF(cleanup, path, "%d", 0);
+
+	snprintf(path, BUFSIZ, PATH_KHPD "alloc_sleep_millisecs");
+	SAFE_FILE_SCANF(NULL, path, "%d", &pre_thp_alloc_sleep_millisecs);

testcases/kernel/mem/thp/thp05.c line 131

Quoted 10 lines
testcases/kernel/mem/thp/thp05.c new file +10 -0
+	SAFE_FILE_PRINTF(NULL, path, "%d", 0);
+
+	snprintf(path, BUFSIZ, PATH_THP "enabled");
+	write_file(path, "always");
+
+	tst_sig(FORK, DEF_HANDLER, NULL);
+	TEST_PAUSE;
+}
+
+void cleanup(void)

ditto?

Thanks,
Wanlong Gao

Quoted 12 lines
testcases/kernel/mem/thp/thp05.c new file +11 -0
+{
+	char path[BUFSIZ];
+
+	snprintf(path, BUFSIZ, PATH_KHPD "scan_sleep_millisecs");
+	SAFE_FILE_PRINTF(NULL, path, "%d", pre_thp_scan_sleep_millisecs);
+
+	snprintf(path, BUFSIZ, PATH_KHPD "alloc_sleep_millisecs");
+	SAFE_FILE_PRINTF(NULL, path, "%d", pre_thp_alloc_sleep_millisecs);
+
+	snprintf(path, BUFSIZ, PATH_THP "enabled");
+	write_file(path, pre_thp_enabled);

testcases/kernel/mem/thp/thp05.c line 152

Quoted 10 lines
testcases/kernel/mem/thp/thp05.c new file +10 -0
+
+	TEST_CLEANUP;
+}
+
+#else /* no NUMA */
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
+}
+#endif

------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness. Reduce network management and security costs.Learn how to hire the most talented Cisco Certified professionals. Visit the Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#5 lore raw
In reply to Zhouping Liu
Quoted 104 lines · Zhouping Liu

The case is desinged to test THP functionality.

when one process allocate hugepage aligned anonymouse pages, kernel thread 'khugepaged' controlled by sysfs knobs /sys/kernel/mm/transparent_hugepage/* will scan them, and make them as transparent hugepage if they are suited, you can find out how many transparent hugepages are there in one process from /proc/<pid>/smaps, among the file contents, 'AnonHugePages' entry stand for transparent hugepage.

---
 runtest/mm                         |   3 +
 testcases/kernel/mem/include/mem.h |  11 +++
 testcases/kernel/mem/lib/mem.c     | 180 +++++++++++++++++++++++++++++++++++++
 testcases/kernel/mem/thp/thp04.c   | 136 ++++++++++++++++++++++++++++
 4 files changed, 330 insertions(+)
 create mode 100644 testcases/kernel/mem/thp/thp04.c
runtest/mm +3 -0
index 56b83f8..3fbb20f 100644
@@ -84,6 +84,9 @@ swapping01 swapping01 -i 5
 thp01 thp01 -I 120
 thp02 thp02
 thp03 thp03
+thp04_1 thp04
+thp04_2 thp04 -n 10 -N 20
+thp04_3 thp04 -n 1 -N 300
 
 vma01 vma01
 vma02 vma02
testcases/kernel/mem/include/mem.h +11 -0
index fdf558e..ccae47d 100644
@@ -32,6 +32,17 @@ void testoom(int mempolicy, int lite);
 
 #define PATH_KSM		"/sys/kernel/mm/ksm/"
 
+/* THP */
+
+#define PATH_THP		"/sys/kernel/mm/transparent_hugepage/"
+#define PATH_KHPD		PATH_THP "khugepaged/"
+
+int opt_nr_child, opt_nr_thps;
+char *opt_nr_child_str, *opt_nr_thps_str;
+void test_transparent_hugepage(int nr_child, int nr_thps, int hg_aligned);
+void check_thp_options(int *nr_child, int *nr_thps);
+void thp_usage(void);
+
 /* HUGETLB */
 
 #define PATH_SHMMAX		"/proc/sys/kernel/shmmax"
testcases/kernel/mem/lib/mem.c +41 -0
index c9525e5..491afe8 100644
@@ -501,6 +501,186 @@ void ksm_usage(void)
 	printf("  -u      Memory allocation unit in MB\n");
 }
 
+/* THP */
+
+static int alloc_transparent_hugepages(int nr_thps, int hg_aligned)
+{
+	unsigned long hugepagesize, size;
+	void *addr;
+	int ret;
+
+	hugepagesize = read_meminfo("Hugepagesize:") * KB;
+	size = nr_thps * hugepagesize;
+
+	if (hg_aligned) {
+		ret = posix_memalign(&addr, hugepagesize, size);
+		if (ret != 0) {
+			printf("posix_memalign failed\n");
+			return -1;
+		}
+	} else {
+		addr = mmap(NULL, size, PROT_READ|PROT_WRITE,
+			    MAP_PRIVATE|MAP_ANON, -1, 0);
+		if (addr == MAP_FAILED) {
+			perror("mmap");
+			return -1;
+		}
+	}
+
+	memset(addr, 10, size);
+
+	tst_resm(TINFO, "child[%d] stop here", getpid());
+	/*
+	 * stop here, until the father finish to calculate
+	 * all the transparent hugepages.
+	 */
+	if (raise(SIGSTOP) == -1) {
+		perror("kill");
+		return -1;
+	}
+
+	return 0;
+}
+

testcases/kernel/mem/lib/mem.c void ksm_usage(void) · line 554

Quoted 10 lines
testcases/kernel/mem/lib/mem.c +10 -0
+static void khugepaged_scan_done(void)
+{
+	int changing = 1, count = 0;
+	long old_pages_collapsed, old_defrag;
+	long old_max_ptes_none, old_pages_to_scan;
+	long pages_collapsed = 0, pages_to_scan = 0;
+	long defrag = 0, max_ptes_none = 0;
+
+	while (changing) {
+		sleep(10);

You should comment this sleep line. Why should it be 10?

Quoted 58 lines
testcases/kernel/mem/lib/mem.c +58 -0
+		count++;
+
+		SAFE_FILE_SCANF(cleanup, PATH_KHPD "pages_collapsed",
+			       "%ld", &pages_collapsed);
+		SAFE_FILE_SCANF(cleanup, PATH_KHPD "defrag", "%ld", &defrag);
+		SAFE_FILE_SCANF(cleanup, PATH_KHPD "max_ptes_none",
+			       "%ld", &max_ptes_none);
+		SAFE_FILE_SCANF(cleanup, PATH_KHPD "pages_to_scan",
+			       "%ld", &pages_to_scan);
+
+		if (pages_collapsed != old_pages_collapsed ||
+		    pages_to_scan != old_pages_to_scan ||
+		    max_ptes_none != old_max_ptes_none ||
+		    defrag != old_defrag) {
+			old_pages_collapsed = pages_collapsed;
+			old_pages_to_scan = pages_to_scan;
+			old_max_ptes_none = max_ptes_none;
+			old_defrag = defrag;
+		} else {
+			changing = 0;
+		}
+	}
+
+	tst_resm(TINFO, "khugepaged daemon takes %ds to scan all thp pages",
+		 count * 10);
+}
+
+static void verify_thp_size(int *child, int nr_child, int nr_thps)
+{
+	FILE *fp;
+	char path[BUFSIZ], buf[BUFSIZ], line[BUFSIZ];
+	int i, ret;
+	long expect_thps; /* the amount of per child's transparent hugepages */
+	long val, actual_thps;
+	long hugepagesize;
+
+	hugepagesize = read_meminfo("Hugepagesize:");
+	expect_thps = nr_thps * hugepagesize;
+
+	for (i = 0; i < nr_child; i++) {
+		actual_thps = 0;
+
+		snprintf(path, BUFSIZ, "/proc/%d/smaps", child[i]);
+		fp = fopen(path, "r");
+		while (fgets(line, BUFSIZ, fp) != NULL) {
+			ret = sscanf(line, "%64s %ld", buf, &val);
+			if (ret == 2 && val != 0) {
+				if (strcmp(buf, "AnonHugePages:") == 0)
+					actual_thps += val;
+			}
+		}
+
+		if (actual_thps != expect_thps)
+			tst_resm(TFAIL, "child[%d] got %ldKB thps - expect %ld"
+				"KB thps", getpid(), actual_thps, expect_thps);
+		fclose(fp);
+	}
+}

testcases/kernel/mem/lib/mem.c void ksm_usage(void) · line 622

Quoted 10 lines
testcases/kernel/mem/lib/mem.c +10 -0
+
+void test_transparent_hugepage(int nr_child, int nr_thps, int hg_aligned)
+{
+	unsigned long hugepagesize;
+	int i, *pid, ret, status;
+	char path[BUFSIZ];
+
+	hugepagesize = read_meminfo("Hugepagesize:");
+
+	pid = (int *)malloc(nr_child * sizeof(int));

type is unnecessary?

Quoted 124 lines
testcases/kernel/mem/lib/mem.c +61 -0
+	if (pid == NULL)
+		tst_brkm(TBROK | TERRNO, cleanup, "malloc");
+
+	for (i = 0; i < nr_child; i++) {
+		switch (pid[i] = fork()) {
+		case -1:
+			tst_brkm(TBROK | TERRNO, cleanup, "fork");
+
+		case 0:
+			ret = alloc_transparent_hugepages(nr_thps, hg_aligned);
+			exit(ret);
+		}
+	}
+
+	tst_resm(TINFO, "Stop all children...");
+	for (i = 0; i < nr_child; i++) {
+		if (waitpid(pid[i], &status, WUNTRACED) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+		if (!WIFSTOPPED(status))
+			tst_brkm(TBROK, cleanup,
+				 "child[%d] was not stoppted", pid[i]);
+	}
+
+	tst_resm(TINFO, "Start to scan all transparent hugepages...");
+	khugepaged_scan_done();
+
+	tst_resm(TINFO, "Start to verify transparent hugepage size...");
+	verify_thp_size(pid, nr_child, nr_thps);
+
+	tst_resm(TINFO, "Wake up all children...");
+	for (i = 0; i < nr_child; i++) {
+		if (kill(pid[i], SIGCONT) == -1)
+			tst_brkm(TBROK | TERRNO, cleanup,
+				 "signal continue child[%d]", pid[i]);
+	}
+
+	/* wait all children finish himself task */
+	for (i = 0; i < nr_child; i++) {
+		if (waitpid(pid[i], &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid %d", pid[i]);
+
+		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+			tst_resm(TFAIL, "the child[%d] unexpectedly failed:"
+				 " %d", pid[i], status);
+	}
+}
+
+void check_thp_options(int *nr_child, int *nr_thps)
+{
+	if (opt_nr_child)
+		*nr_child = SAFE_STRTOL(NULL, opt_nr_child_str, 0, LONG_MAX);
+	if (opt_nr_thps)
+		*nr_thps = SAFE_STRTOL(NULL, opt_nr_thps_str, 0, LONG_MAX);
+}
+
+void thp_usage(void)
+{
+	printf("  -n      Number of processes\n");
+	printf("  -N      Number of transparent hugepages\n");
+}
+
 /* cpuset/memcg */
 
 static void gather_node_cpus(char *cpus, long nd)
testcases/kernel/mem/thp/thp04.c new file +54 -0
new file mode 100644
index 0000000..2855eb5
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2013 Linux Test Project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * The case is designed to test the functionality of transparent
+ * hugepage - THP
+ *
+ * when one process allocate hugepage aligned anonymouse pages,
+ * kernel thread 'khugepaged' controlled by sysfs knobs
+ * /sys/kernel/mm/transparent_hugepage/ will scan them, and make
+ * them as transparent hugepage if they are suited, you can find out
+ * how many transparent hugepages are there in one process from
+ * /proc/<pid>/smaps, among the file contents, 'AnonHugePages' entry
+ * stand for transparent hugepage.
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "test.h"
+#include "usctest.h"
+#include "mem.h"
+
+char *TCID = "thp04";
+int TST_TOTAL = 1;

testcases/kernel/mem/thp/thp04.c line 64

Quoted 10 lines
testcases/kernel/mem/thp/thp04.c new file +10 -0
+
+option_t thp_options[] = {
+	{"n:", &opt_nr_child, &opt_nr_child_str},
+	{"N:", &opt_nr_thps, &opt_nr_thps_str},
+	{NULL, NULL, NULL}
+};
+
+int pre_thp_scan_sleep_millisecs;
+int pre_thp_alloc_sleep_millisecs;
+char pre_thp_enabled[BUFSIZ];

These can be made to static?

Quoted 19 lines
testcases/kernel/mem/thp/thp04.c new file +19 -0
+
+int main(int argc, char *argv[])
+{
+	int lc;
+	char *msg;
+	int nr_child = 2, nr_thps = 64;
+
+	msg = parse_opts(argc, argv, thp_options, thp_usage);
+	if (msg != NULL)
+		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+	check_thp_options(&nr_child, &nr_thps);
+
+	setup();
+
+	tst_resm(TINFO, "Start to test transparent hugepage...");
+	tst_resm(TINFO, "There are %d children allocating %d "
+			"transparent hugepages", nr_child, nr_thps);
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {

testcases/kernel/mem/thp/thp04.c line 93

Quoted 10 lines
testcases/kernel/mem/thp/thp04.c new file +10 -0
+		tst_count = 0;
+
+		test_transparent_hugepage(nr_child, nr_thps, 1);
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+void setup(void)

static ?

Quoted 19 lines
testcases/kernel/mem/thp/thp04.c new file +19 -0
+{
+	char path[BUFSIZ];
+
+	tst_require_root(NULL);
+
+	if (access(PATH_THP, F_OK) == -1)
+		tst_brkm(TCONF, NULL, "THP is not enabled");
+
+	snprintf(path, BUFSIZ, PATH_KHPD "scan_sleep_millisecs");
+	SAFE_FILE_SCANF(NULL, path, "%d", &pre_thp_scan_sleep_millisecs);
+	/* set 0 to khugepaged/scan_sleep_millisecs to run khugepaged 100% */
+	SAFE_FILE_PRINTF(cleanup, path, "%d", 0);
+
+	snprintf(path, BUFSIZ, PATH_KHPD "alloc_sleep_millisecs");
+	SAFE_FILE_SCANF(NULL, path, "%d", &pre_thp_alloc_sleep_millisecs);
+	/*
+	 * set 0 to khugepaged/alloc_sleep_millisecs to make sure khugepaged
+	 * don't stop if there's a hugepage allcation failure.
+	 */

testcases/kernel/mem/thp/thp04.c line 122

Quoted 10 lines
testcases/kernel/mem/thp/thp04.c new file +10 -0
+	SAFE_FILE_PRINTF(NULL, path, "%d", 0);
+
+	snprintf(path, BUFSIZ, PATH_THP "enabled");
+	write_file(path, "always");
+
+	tst_sig(FORK, DEF_HANDLER, NULL);
+	TEST_PAUSE;
+}
+
+void cleanup(void)

static?

Thanks,
Wanlong Gao

Quoted 5 lines
testcases/kernel/mem/thp/thp04.c new file +4 -0
+{
+	char path[BUFSIZ];
+
+	snprintf(path, BUFSIZ, PATH_KHPD "scan_sleep_millisecs");

testcases/kernel/mem/thp/thp04.c line 136

Quoted 10 lines
testcases/kernel/mem/thp/thp04.c new file +10 -0
+	SAFE_FILE_PRINTF(NULL, path, "%d", pre_thp_scan_sleep_millisecs);
+
+	snprintf(path, BUFSIZ, PATH_KHPD "alloc_sleep_millisecs");
+	SAFE_FILE_PRINTF(NULL, path, "%d", pre_thp_alloc_sleep_millisecs);
+
+	snprintf(path, BUFSIZ, PATH_THP "enabled");
+	write_file(path, pre_thp_enabled);
+
+	TEST_CLEANUP;
+}

------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness. Reduce network management and security costs.Learn how to hire the most talented Cisco Certified professionals. Visit the Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#6 lore raw

Hi Wanlong,

Quoted 108 lines · Wanlong Gao
Quoted 107 lines · Zhouping Liu

The case is desinged to test THP functionality.

when one process allocate hugepage aligned anonymouse pages, kernel thread 'khugepaged' controlled by sysfs knobs /sys/kernel/mm/transparent_hugepage/* will scan them, and make them as transparent hugepage if they are suited, you can find out how many transparent hugepages are there in one process from /proc/<pid>/smaps, among the file contents, 'AnonHugePages' entry stand for transparent hugepage.

---
  runtest/mm                         |   3 +
  testcases/kernel/mem/include/mem.h |  11 +++
  testcases/kernel/mem/lib/mem.c     | 180 +++++++++++++++++++++++++++++++++++++
  testcases/kernel/mem/thp/thp04.c   | 136 ++++++++++++++++++++++++++++
  4 files changed, 330 insertions(+)

create mode 100644 testcases/kernel/mem/thp/thp04.c

runtest/mm +3 -0
index 56b83f8..3fbb20f 100644
@@ -84,6 +84,9 @@ swapping01 swapping01 -i 5
  thp01 thp01 -I 120
  thp02 thp02
  thp03 thp03
+thp04_1 thp04
+thp04_2 thp04 -n 10 -N 20
+thp04_3 thp04 -n 1 -N 300
 
  vma01 vma01
  vma02 vma02
testcases/kernel/mem/include/mem.h +11 -0
index fdf558e..ccae47d 100644
@@ -32,6 +32,17 @@ void testoom(int mempolicy, int lite);
 
  #define PATH_KSM		"/sys/kernel/mm/ksm/"
 
+/* THP */
+
+#define PATH_THP		"/sys/kernel/mm/transparent_hugepage/"
+#define PATH_KHPD		PATH_THP "khugepaged/"
+
+int opt_nr_child, opt_nr_thps;
+char *opt_nr_child_str, *opt_nr_thps_str;
+void test_transparent_hugepage(int nr_child, int nr_thps, int hg_aligned);
+void check_thp_options(int *nr_child, int *nr_thps);
+void thp_usage(void);
+
  /* HUGETLB */
 
  #define PATH_SHMMAX		"/proc/sys/kernel/shmmax"
testcases/kernel/mem/lib/mem.c +44 -0
index c9525e5..491afe8 100644
@@ -501,6 +501,186 @@ void ksm_usage(void)
  	printf("  -u      Memory allocation unit in MB\n");
  }
 
+/* THP */
+
+static int alloc_transparent_hugepages(int nr_thps, int hg_aligned)
+{
+	unsigned long hugepagesize, size;
+	void *addr;
+	int ret;
+
+	hugepagesize = read_meminfo("Hugepagesize:") * KB;
+	size = nr_thps * hugepagesize;
+
+	if (hg_aligned) {
+		ret = posix_memalign(&addr, hugepagesize, size);
+		if (ret != 0) {
+			printf("posix_memalign failed\n");
+			return -1;
+		}
+	} else {
+		addr = mmap(NULL, size, PROT_READ|PROT_WRITE,
+			    MAP_PRIVATE|MAP_ANON, -1, 0);
+		if (addr == MAP_FAILED) {
+			perror("mmap");
+			return -1;
+		}
+	}
+
+	memset(addr, 10, size);
+
+	tst_resm(TINFO, "child[%d] stop here", getpid());
+	/*
+	 * stop here, until the father finish to calculate
+	 * all the transparent hugepages.
+	 */
+	if (raise(SIGSTOP) == -1) {
+		perror("kill");
+		return -1;
+	}
+
+	return 0;
+}
+
+static void khugepaged_scan_done(void)
+{
+	int changing = 1, count = 0;
Quoted 8 lines

testcases/kernel/mem/lib/mem.c void ksm_usage(void) · line 554

Quoted 7 lines
testcases/kernel/mem/lib/mem.c +7 -0
+	long old_pages_collapsed, old_defrag;
+	long old_max_ptes_none, old_pages_to_scan;
+	long pages_collapsed = 0, pages_to_scan = 0;
+	long defrag = 0, max_ptes_none = 0;
+
+	while (changing) {
+		sleep(10);

You should comment this sleep line. Why should it be 10?

Wanlong, Thanks for reviewing.

here 10s is similar with one inside wait_ksmd_done() (see lib/mem.c)

10s is an interval for khugepaged to finish scan process's transparent hugepages, and at the beginning, khugepaged/[scan_sleep_millisecs|alloc_sleep_millisecs]
are all be set 0, so 'khugepaged' always run 100% during the testing, depending on
this, I choose an optional value 10s to khugepaged, and I think the interval is enough
to recognise whether khugepaged finished scanning process's anonymous hugepage or not.

I will do some comment on V2.

Quoted 63 lines
Quoted 63 lines
testcases/kernel/mem/lib/mem.c +61 -0
+		count++;
+
+		SAFE_FILE_SCANF(cleanup, PATH_KHPD "pages_collapsed",
+			       "%ld", &pages_collapsed);
+		SAFE_FILE_SCANF(cleanup, PATH_KHPD "defrag", "%ld", &defrag);
+		SAFE_FILE_SCANF(cleanup, PATH_KHPD "max_ptes_none",
+			       "%ld", &max_ptes_none);
+		SAFE_FILE_SCANF(cleanup, PATH_KHPD "pages_to_scan",
+			       "%ld", &pages_to_scan);
+
+		if (pages_collapsed != old_pages_collapsed ||
+		    pages_to_scan != old_pages_to_scan ||
+		    max_ptes_none != old_max_ptes_none ||
+		    defrag != old_defrag) {
+			old_pages_collapsed = pages_collapsed;
+			old_pages_to_scan = pages_to_scan;
+			old_max_ptes_none = max_ptes_none;
+			old_defrag = defrag;
+		} else {
+			changing = 0;
+		}
+	}
+
+	tst_resm(TINFO, "khugepaged daemon takes %ds to scan all thp pages",
+		 count * 10);
+}
+
+static void verify_thp_size(int *child, int nr_child, int nr_thps)
+{
+	FILE *fp;
+	char path[BUFSIZ], buf[BUFSIZ], line[BUFSIZ];
+	int i, ret;
+	long expect_thps; /* the amount of per child's transparent hugepages */
+	long val, actual_thps;
+	long hugepagesize;
+
+	hugepagesize = read_meminfo("Hugepagesize:");
+	expect_thps = nr_thps * hugepagesize;
+
+	for (i = 0; i < nr_child; i++) {
+		actual_thps = 0;
+
+		snprintf(path, BUFSIZ, "/proc/%d/smaps", child[i]);
+		fp = fopen(path, "r");
+		while (fgets(line, BUFSIZ, fp) != NULL) {
+			ret = sscanf(line, "%64s %ld", buf, &val);
+			if (ret == 2 && val != 0) {
+				if (strcmp(buf, "AnonHugePages:") == 0)
+					actual_thps += val;
+			}
+		}
+
+		if (actual_thps != expect_thps)
+			tst_resm(TFAIL, "child[%d] got %ldKB thps - expect %ld"
+				"KB thps", getpid(), actual_thps, expect_thps);
+		fclose(fp);
+	}
+}
+
+void test_transparent_hugepage(int nr_child, int nr_thps, int hg_aligned)
+{
Quoted 8 lines

testcases/kernel/mem/lib/mem.c void ksm_usage(void) · line 622

Quoted 7 lines
testcases/kernel/mem/lib/mem.c +7 -0
+	unsigned long hugepagesize;
+	int i, *pid, ret, status;
+	char path[BUFSIZ];
+
+	hugepagesize = read_meminfo("Hugepagesize:");
+
+	pid = (int *)malloc(nr_child * sizeof(int));

type is unnecessary?

doesn't it need? (I'm not sure)

Quoted 128 lines
Quoted 128 lines
testcases/kernel/mem/lib/mem.c +61 -0
+	if (pid == NULL)
+		tst_brkm(TBROK | TERRNO, cleanup, "malloc");
+
+	for (i = 0; i < nr_child; i++) {
+		switch (pid[i] = fork()) {
+		case -1:
+			tst_brkm(TBROK | TERRNO, cleanup, "fork");
+
+		case 0:
+			ret = alloc_transparent_hugepages(nr_thps, hg_aligned);
+			exit(ret);
+		}
+	}
+
+	tst_resm(TINFO, "Stop all children...");
+	for (i = 0; i < nr_child; i++) {
+		if (waitpid(pid[i], &status, WUNTRACED) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+		if (!WIFSTOPPED(status))
+			tst_brkm(TBROK, cleanup,
+				 "child[%d] was not stoppted", pid[i]);
+	}
+
+	tst_resm(TINFO, "Start to scan all transparent hugepages...");
+	khugepaged_scan_done();
+
+	tst_resm(TINFO, "Start to verify transparent hugepage size...");
+	verify_thp_size(pid, nr_child, nr_thps);
+
+	tst_resm(TINFO, "Wake up all children...");
+	for (i = 0; i < nr_child; i++) {
+		if (kill(pid[i], SIGCONT) == -1)
+			tst_brkm(TBROK | TERRNO, cleanup,
+				 "signal continue child[%d]", pid[i]);
+	}
+
+	/* wait all children finish himself task */
+	for (i = 0; i < nr_child; i++) {
+		if (waitpid(pid[i], &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid %d", pid[i]);
+
+		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+			tst_resm(TFAIL, "the child[%d] unexpectedly failed:"
+				 " %d", pid[i], status);
+	}
+}
+
+void check_thp_options(int *nr_child, int *nr_thps)
+{
+	if (opt_nr_child)
+		*nr_child = SAFE_STRTOL(NULL, opt_nr_child_str, 0, LONG_MAX);
+	if (opt_nr_thps)
+		*nr_thps = SAFE_STRTOL(NULL, opt_nr_thps_str, 0, LONG_MAX);
+}
+
+void thp_usage(void)
+{
+	printf("  -n      Number of processes\n");
+	printf("  -N      Number of transparent hugepages\n");
+}
+
  /* cpuset/memcg */
 
  static void gather_node_cpus(char *cpus, long nd)
testcases/kernel/mem/thp/thp04.c new file +57 -0
new file mode 100644
index 0000000..2855eb5
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2013 Linux Test Project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * The case is designed to test the functionality of transparent
+ * hugepage - THP
+ *
+ * when one process allocate hugepage aligned anonymouse pages,
+ * kernel thread 'khugepaged' controlled by sysfs knobs
+ * /sys/kernel/mm/transparent_hugepage/ will scan them, and make
+ * them as transparent hugepage if they are suited, you can find out
+ * how many transparent hugepages are there in one process from
+ * /proc/<pid>/smaps, among the file contents, 'AnonHugePages' entry
+ * stand for transparent hugepage.
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "test.h"
+#include "usctest.h"
+#include "mem.h"
+
+char *TCID = "thp04";
+int TST_TOTAL = 1;
+
+option_t thp_options[] = {
+	{"n:", &opt_nr_child, &opt_nr_child_str},
Quoted 8 lines

testcases/kernel/mem/thp/thp04.c line 64

Quoted 7 lines
testcases/kernel/mem/thp/thp04.c new file +7 -0
+	{"N:", &opt_nr_thps, &opt_nr_thps_str},
+	{NULL, NULL, NULL}
+};
+
+int pre_thp_scan_sleep_millisecs;
+int pre_thp_alloc_sleep_millisecs;
+char pre_thp_enabled[BUFSIZ];

These can be made to static?

yes, they can be static, I will update these on V2.

Quoted 23 lines
Quoted 23 lines
testcases/kernel/mem/thp/thp04.c new file +22 -0
+
+int main(int argc, char *argv[])
+{
+	int lc;
+	char *msg;
+	int nr_child = 2, nr_thps = 64;
+
+	msg = parse_opts(argc, argv, thp_options, thp_usage);
+	if (msg != NULL)
+		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+	check_thp_options(&nr_child, &nr_thps);
+
+	setup();
+
+	tst_resm(TINFO, "Start to test transparent hugepage...");
+	tst_resm(TINFO, "There are %d children allocating %d "
+			"transparent hugepages", nr_child, nr_thps);
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		test_transparent_hugepage(nr_child, nr_thps, 1);
Quoted 8 lines

testcases/kernel/mem/thp/thp04.c line 93

Quoted 7 lines
testcases/kernel/mem/thp/thp04.c new file +7 -0
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+void setup(void)

static ?

no, it declared on include/mem.h.

Quoted 23 lines
Quoted 23 lines
testcases/kernel/mem/thp/thp04.c new file +22 -0
+{
+	char path[BUFSIZ];
+
+	tst_require_root(NULL);
+
+	if (access(PATH_THP, F_OK) == -1)
+		tst_brkm(TCONF, NULL, "THP is not enabled");
+
+	snprintf(path, BUFSIZ, PATH_KHPD "scan_sleep_millisecs");
+	SAFE_FILE_SCANF(NULL, path, "%d", &pre_thp_scan_sleep_millisecs);
+	/* set 0 to khugepaged/scan_sleep_millisecs to run khugepaged 100% */
+	SAFE_FILE_PRINTF(cleanup, path, "%d", 0);
+
+	snprintf(path, BUFSIZ, PATH_KHPD "alloc_sleep_millisecs");
+	SAFE_FILE_SCANF(NULL, path, "%d", &pre_thp_alloc_sleep_millisecs);
+	/*
+	 * set 0 to khugepaged/alloc_sleep_millisecs to make sure khugepaged
+	 * don't stop if there's a hugepage allcation failure.
+	 */
+	SAFE_FILE_PRINTF(NULL, path, "%d", 0);
+
+	snprintf(path, BUFSIZ, PATH_THP "enabled");
Quoted 8 lines

testcases/kernel/mem/thp/thp04.c line 122

Quoted 7 lines
testcases/kernel/mem/thp/thp04.c new file +7 -0
+	write_file(path, "always");
+
+	tst_sig(FORK, DEF_HANDLER, NULL);
+	TEST_PAUSE;
+}
+
+void cleanup(void)

static?

ditto, it's also used by some functions in lib/mem.c.

Quoted 5 lines

Thanks,
Wanlong Gao

Quoted 15 lines
Quoted 5 lines
testcases/kernel/mem/thp/thp04.c new file +4 -0
+{
+	char path[BUFSIZ];
+
+	snprintf(path, BUFSIZ, PATH_KHPD "scan_sleep_millisecs");

testcases/kernel/mem/thp/thp04.c line 136

Quoted 10 lines
testcases/kernel/mem/thp/thp04.c new file +10 -0
+	SAFE_FILE_PRINTF(NULL, path, "%d", pre_thp_scan_sleep_millisecs);
+
+	snprintf(path, BUFSIZ, PATH_KHPD "alloc_sleep_millisecs");
+	SAFE_FILE_PRINTF(NULL, path, "%d", pre_thp_alloc_sleep_millisecs);
+
+	snprintf(path, BUFSIZ, PATH_THP "enabled");
+	write_file(path, pre_thp_enabled);
+
+	TEST_CLEANUP;
+}

------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness. Reduce network management and security costs.Learn how to hire the most talented Cisco Certified professionals. Visit the Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#7 lore raw

Hi!

Quoted 11 lines

here 10s is similar with one inside wait_ksmd_done() (see lib/mem.c)

10s is an interval for khugepaged to finish scan process's transparent hugepages, and at the beginning, khugepaged/[scan_sleep_millisecs|alloc_sleep_millisecs]
are all be set 0, so 'khugepaged' always run 100% during the testing, depending on
this, I choose an optional value 10s to khugepaged, and I think the interval is enough
to recognise whether khugepaged finished scanning process's anonymous hugepage or not.

Hardcoded constants tend to break from time to time. Is there any interface that could give you information about the state of the scan?

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list