Skip to contentSkip to conversation

madvice: new case for madvise(WILLNEED)

PATCH New Li Wang 2 participants 3 messages Mar 18, 2016 – Mar 29, 2016

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 madvice: new case for madvise(WILLNEED)

Page fault occurs in spite that madvise(WILLNEED) system call is called to prefetch the page. This issue is reproduced by running a program which sequentially accesses to a shared memory and calls madvise(WILLNEED) to the next page on a page fault.

Fixed by commit:
55231e5c898 mm: madvise: fix MADV_WILLNEED on shmem swapouts

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/.gitignore          |   1 +
 testcases/kernel/syscalls/madvise/madvise06.c | 229 ++++++++++++++++++++++++++
 3 files changed, 231 insertions(+)
 create mode 100644 testcases/kernel/syscalls/madvise/madvise06.c
runtest/syscalls +1 -0
index b41c927..732c2ca 100644
@@ -743,6 +743,7 @@ madvise02 madvise02
 madvise03 madvise03
 madvise04 madvise04
 madvise05 madvise05
+madvise06 madvise06
 
 newuname01 newuname01
 
testcases/kernel/syscalls/.gitignore +1 -0
index 0540928..ffa5db1 100644
@@ -504,6 +504,7 @@
 /madvise/madvise03
 /madvise/madvise04
 /madvise/madvise05
+/madvise/madvise06
 /mallopt/mallopt01
 /mbind/mbind01
 /memcmp/memcmp01
testcases/kernel/syscalls/madvise/madvise06.c new file +229 -0

229 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 madvice: new case for madvise(WILLNEED)

Hi!

Quoted 20 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +20 -0
+/*
+ * DESCRIPTION
+ *
+ *   Page fault occurs in spite that madvise(WILLNEED) system call is called
+ *   to prefetch the page. This issue is reproduced by running a program
+ *   which sequentially accesses to a shared memory and calls madvise(WILLNEED)
+ *   to the next page on a page fault.
+ *
+ *   This bug is present in all RHEL7 versions. It looks like this was fixed in
+ *   mainline kernel > v3.15 by the following patch:
+ *
+ *   commit 55231e5c898c5c03c14194001e349f40f59bd300
+ *   Author: Johannes Weiner <[email protected]>
+ *   Date:   Thu May 22 11:54:17 2014 -0700
+ *
+ *       mm: madvise: fix MADV_WILLNEED on shmem swapouts
+ */
+
+#include <stdio.h>
+#include <sys/shm.h>

testcases/kernel/syscalls/madvise/madvise06.c line 47

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+#include <errno.h>
+#include <sys/sysinfo.h>
+
+#include "test.h"
+#include "safe_macros.h"
+
+char *TCID = "madvise06";
+int TST_TOTAL = 1;
+
+#if __x86_64__
    ^

#ifdef

Quoted 23 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +23 -0
+#define GB_SZ  (1024*1024*1024)
+#define PG_SZ  (4*1024)
+
+#define INV_PTR ((char *)-1)
+
+static int id_src_1gb;
+static char *src_1gb;
+
+static int *id_dst;
+static char **dst;
+static long dst_num;
+
+static struct sysinfo *sys_buf;
+static long mem_total;
+
+static int page_fault_num1;
+static int page_fault_num2;
+
+static void setup(void);
+static void cleanup(void);
+static void free_shm(void);
+static int  get_page_fault_num(void);
+static void test_advice_willneed(void);

testcases/kernel/syscalls/madvise/madvise06.c line 81

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+
+int main(int argc, char *argv[])
+{
+	int lc;
+
+	tst_parse_opts(argc, argv, NULL, NULL);
+
+	sys_buf = malloc(sizeof(struct sysinfo));
+	sysinfo(sys_buf);
+	mem_total = sys_buf->totalram;

Just why do you use malloc to allocate small structure? Why can't you just create it on the stack instead?

Also why do you have global pointer to it when it's not used outside of the main() function?

And also getting the amount of system memory is something that should be done in the setup() function instead.

testcases/kernel/syscalls/madvise/madvise06.c line 91

Quoted 9 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +9 -0
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		test_advice_willneed();
+
+		if (page_fault_num1 != page_fault_num2)
+			tst_resm(TFAIL, "Bug has been reproduced!");
+		else
+			tst_resm(TPASS, "Regression test pass!");

The TPASS/TFAIL should be printed in the test_advice_willneed() function and the page_fault* variables shouldn't be global.

Quoted 7 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +7 -0
+		free_shm();
+	}
+
+	free(sys_buf);
+	tst_exit();
+}
+

testcases/kernel/syscalls/madvise/madvise06.c line 109

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+static void setup(void)
+{
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	if (tst_kvercmp(3, 9, 0) < 0)
+		tst_brkm(TCONF, NULL, "madvise(MADV_WILLNEED) swap file"
+			"prefetch available only since 3.9");
+
+	if (mem_total < 2L * GB_SZ) {
+		tst_resm(TCONF, "Test requires more than 2GB of RAM");
+		tst_exit();

tst_brkm(TCONF, NULL, "...");

testcases/kernel/syscalls/madvise/madvise06.c line 110

Quoted 1 line
testcases/kernel/syscalls/madvise/madvise06.c new file +1 -0
+	} else if (mem_total > 100L * GB_SZ) {

Why is the else branch here if you call tst_exit() in the body of the if above?

testcases/kernel/syscalls/madvise/madvise06.c line 112

Quoted 2 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +2 -0
+		tst_resm(TCONF, "System RAM is too large, skip this test.");
+		tst_exit();

tst_brkm(TCONF, NULL, ...);

Also why do we skip the test on systems with large RAM?

Does it take too long?

Quoted 15 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +15 -0
+	}
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	free_shm();
+}
+
+static void free_shm(void)
+{
+	int i;
+
+	if (id_src_1gb != -1) {

testcases/kernel/syscalls/madvise/madvise06.c line 137

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+		if (shmctl(id_src_1gb, IPC_RMID, NULL) == -1)
+			tst_brkm(TBROK | TERRNO, NULL, "shmctl(id_src_1gb)");
+	}
+
+	for (i = 0; i < dst_num; ++i) {
+		if (id_dst[i] != -1) {
+			if (shmctl(id_dst[i], IPC_RMID, NULL) == -1)
+				tst_brkm(TBROK | TERRNO, NULL, "shmctl(id_dst[i])");
+		}
+	}

You can shmctl(..., IPC_RMID) the memory right after you did shmat() and you don't have to remember the ids that way, the memory will be accesible till you detach it with shmdt(). In other words this will not free the memory at all. Does the test runs with -i 100?

Quoted 4 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +4 -0
+}
+
+static int get_page_fault_num(void)
+{

testcases/kernel/syscalls/madvise/madvise06.c line 151

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+	FILE *fp;
+	char s[11][256];
+	int pg, ret;
+
+	fp = fopen("/proc/self/stat", "r");
+	if (fp == NULL)
+		tst_brkm(TBROK | TERRNO, cleanup, "Failed to open /proc/self/stat.");
+
+	ret = fscanf(fp, "%s %s %s %s %s %s %s %s %s %s %s %d",
+			s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], &pg);

fscanf has assigment-supression operator '*' so you can just do:

SAFE_FILE_SCANF("/proc/self/stat",

                "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %d",
		&pg);
Quoted 11 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +11 -0
+	if (ret != 12) {
+		tst_resm(TFAIL, "Failed to get page fault num.");
+		pg = -1;
+	}
+
+	fclose(fp);
+	return pg;
+}
+
+static void test_advice_willneed(void)
+{

testcases/kernel/syscalls/madvise/madvise06.c line 172

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+	int i;
+
+	dst_num = mem_total / GB_SZ;
+	tst_resm(TINFO, "dst_num =  %ld", dst_num);
+
+	if ((id_dst = malloc(dst_num * sizeof(int))) == NULL)
+		tst_brkm(TBROK | TERRNO, NULL, "malloc failed.");
+
+	if ((dst = malloc(dst_num * sizeof(char *))) == NULL)
+		tst_brkm(TBROK | TERRNO, NULL, "malloc failed.");

Make use of SAFE_MALLOC().

Quoted 14 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +14 -0
+	id_src_1gb = -1;
+	src_1gb = INV_PTR;
+	for (i = 0; i < dst_num; ++i) {
+		id_dst[i] = -1;
+		dst[i] = INV_PTR;
+	}
+
+	/* allocate source memory (1GB only) */
+	id_src_1gb = shmget(IPC_PRIVATE, 1 * GB_SZ, IPC_CREAT);
+	if (id_src_1gb == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "shmget failed");
+	src_1gb = shmat(id_src_1gb, 0, 0);
+	if (src_1gb == INV_PTR)
+		tst_brkm(TBROK | TERRNO, cleanup, "shmat failed");

testcases/kernel/syscalls/madvise/madvise06.c line 197

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+
+	/* allocate destination memory (array) */
+	for (i = 0; i < dst_num; ++i) {
+		id_dst[i] = shmget(IPC_PRIVATE, 1 * GB_SZ, IPC_CREAT);
+		if (id_dst[i] == -1)
+			tst_brkm(TBROK | TERRNO, cleanup, "shmget failed");
+
+		dst[i] = shmat(id_dst[i], 0, 0);
+		if (dst[i] == INV_PTR)
+			tst_brkm(TBROK | TERRNO, cleanup, "shmat failed");

Why can't we just use mmap() with MAP_ANONYMOUS instead? Do we really need to use the System V shm?

testcases/kernel/syscalls/madvise/madvise06.c line 203

Quoted 6 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +6 -0
+	}
+
+	/* memmove  source to each destination memories (for SWAP-OUT) */
+	for (i = 0; i < dst_num; ++i) {
+		memmove(dst[i], src_1gb, 1 * GB_SZ);
+		fflush(stdout);

Why do we fflush(stdout) here? We do not write to it at all.

testcases/kernel/syscalls/madvise/madvise06.c line 212

Quoted 9 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +9 -0
+	}
+
+	/* Do madvice() to dst[0] */
+	tst_resm(TINFO, "PageFault(before madvice): %d", get_page_fault_num());
+
+	TEST(madvise(dst[0], PG_SZ, MADV_WILLNEED));
+	if (TEST_RETURN == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "madvise failed");
+	sleep(3);  /* wait for read from SWAP */

Can't we just loop here with a usleep(1000) waiting for the page_fault count to increase?

Doing blind sleep(3) does not guarantee that the event we are wating for really happened and will slown down the testing.

testcases/kernel/syscalls/madvise/madvise06.c line 214

Quoted 1 line
testcases/kernel/syscalls/madvise/madvise06.c new file +1 -0
+	/* Read dst[0] data */

Eh? You are writing to dst[0] here.

testcases/kernel/syscalls/madvise/madvise06.c line 220

Quoted 6 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +6 -0
+	page_fault_num1 = get_page_fault_num();
+	tst_resm(TINFO, "PageFault(after madvice / before Mem Access): %d", page_fault_num1);
+
+	*dst[0] = 10;
+	page_fault_num2 = get_page_fault_num();
+	tst_resm(TINFO, "PageFault(after madvice / after Mem Access): %d", page_fault_num2);

You are allocating the dst arrays on each test iteration but they are not freed. You should rather allocate them once in the setup and free then in the cleanup.

Also the test would not run if you have more than 100GB so we can easily setup static global array for 100 pointers and be done with it.

Quoted 15 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +9 -0
+}
+
+
+#else
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "Only test on x86_64.");
+}
+#endif
Signature · 5 lines
1.8.3.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH 1/1 madvice: new case for madvise(WILLNEED)

Hi Cyril,

Quoted 74 lines · Cyril Hrubis

Hi!

Quoted 4 lines

+/*
+ * DESCRIPTION
+ *
+ * Page fault occurs in spite that madvise(WILLNEED) system call is

called

Quoted 2 lines

+ * to prefetch the page. This issue is reproduced by running a program
+ * which sequentially accesses to a shared memory and calls

madvise(WILLNEED)

Quoted 3 lines

+ * to the next page on a page fault.
+ *
+ * This bug is present in all RHEL7 versions. It looks like this was

fixed in

Quoted 11 lines

+ * mainline kernel > v3.15 by the following patch:
+ *

+ *   commit 55231e5c898c5c03c14194001e349f40f59bd300
+ *   Author: Johannes Weiner <[email protected]>
+ *   Date:   Thu May 22 11:54:17 2014 -0700

+ *
+ * mm: madvise: fix MADV_WILLNEED on shmem swapouts
+ */

testcases/kernel/syscalls/madvise/madvise06.c new file +3 -0
+
+#include <stdio.h>
+#include <sys/shm.h>

testcases/kernel/syscalls/madvise/madvise06.c line 47

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+#include <errno.h>
+#include <sys/sysinfo.h>
+
+#include "test.h"
+#include "safe_macros.h"
+
+char *TCID = "madvise06";
+int TST_TOTAL = 1;
+
+#if __x86_64__
    ^

#ifdef

Quoted 23 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +23 -0
+#define GB_SZ  (1024*1024*1024)
+#define PG_SZ  (4*1024)
+
+#define INV_PTR ((char *)-1)
+
+static int id_src_1gb;
+static char *src_1gb;
+
+static int *id_dst;
+static char **dst;
+static long dst_num;
+
+static struct sysinfo *sys_buf;
+static long mem_total;
+
+static int page_fault_num1;
+static int page_fault_num2;
+
+static void setup(void);
+static void cleanup(void);
+static void free_shm(void);
+static int  get_page_fault_num(void);
+static void test_advice_willneed(void);

testcases/kernel/syscalls/madvise/madvise06.c line 81

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+
+int main(int argc, char *argv[])
+{
+     int lc;
+
+     tst_parse_opts(argc, argv, NULL, NULL);
+
+     sys_buf = malloc(sizeof(struct sysinfo));
+     sysinfo(sys_buf);
+     mem_total = sys_buf->totalram;

Just why do you use malloc to allocate small structure? Why can't you just create it on the stack instead?

Quoted 6 lines

Also why do you have global pointer to it when it's not used outside of the main() function?

And also getting the amount of system memory is something that should be done in the setup() function instead.

ok, I will make them be created on the stack in setup().

Quoted 41 lines

testcases/kernel/syscalls/madvise/madvise06.c line 91

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +9 -0
+     setup();
+
+     for (lc = 0; TEST_LOOPING(lc); lc++) {
+             test_advice_willneed();
+
+             if (page_fault_num1 != page_fault_num2)
+                     tst_resm(TFAIL, "Bug has been reproduced!");
+             else
+                     tst_resm(TPASS, "Regression test pass!");

The TPASS/TFAIL should be printed in the test_advice_willneed() function and the page_fault* variables shouldn't be global.

Quoted 7 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +7 -0
+             free_shm();
+     }
+
+     free(sys_buf);
+     tst_exit();
+}
+

testcases/kernel/syscalls/madvise/madvise06.c line 109

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+static void setup(void)
+{
+     tst_sig(NOFORK, DEF_HANDLER, cleanup);
+     if (tst_kvercmp(3, 9, 0) < 0)
+             tst_brkm(TCONF, NULL, "madvise(MADV_WILLNEED) swap file"
+                     "prefetch available only since 3.9");
+
+     if (mem_total < 2L * GB_SZ) {
+             tst_resm(TCONF, "Test requires more than 2GB of RAM");
+             tst_exit();

tst_brkm(TCONF, NULL, "...");

Quoted 1 line

+ } else if (mem_total > 100L * GB_SZ) {

Why is the else branch here if you call tst_exit() in the body of the if above?

Quoted 1 line

+ tst_resm(TCONF, "System RAM is too large, skip this

Quoted 9 lines

test.");

Quoted 1 line

+ tst_exit();

tst_brkm(TCONF, NULL, ...);

Also why do we skip the test on systems with large RAM?

Does it take too long?

Yes, the memmove() takes too long on larger RAM, so I limit the test on less than 100G system.

Quoted 25 lines
Quoted 8 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +7 -0
+     }
+
+     TEST_PAUSE;
+}
+
+static void cleanup(void)
+{

testcases/kernel/syscalls/madvise/madvise06.c

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+     free_shm();
+}
+
+static void free_shm(void)
+{
+     int i;
+
+     if (id_src_1gb != -1) {
+             if (shmctl(id_src_1gb, IPC_RMID, NULL) == -1)
+                     tst_brkm(TBROK | TERRNO, NULL,

"shmctl(id_src_1gb)");

testcases/kernel/syscalls/madvise/madvise06.c

Quoted 6 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +6 -0
+     }
+
+     for (i = 0; i < dst_num; ++i) {
+             if (id_dst[i] != -1) {
+                     if (shmctl(id_dst[i], IPC_RMID, NULL) == -1)
+                             tst_brkm(TBROK | TERRNO, NULL,
Quoted 9 lines

"shmctl(id_dst[i])");

Review

Quoted 2 lines
(quoted diff) +2 -0
+             }
+     }

You can shmctl(..., IPC_RMID) the memory right after you did shmat() and you don't have to remember the ids that way, the memory will be accesible till you detach it with shmdt(). In other words this will not free the memory at all. Does the test runs with -i 100?

run with -i 100, it triggers the oom-killer.

Quoted 16 lines

testcases/kernel/syscalls/madvise/madvise06.c

Quoted 12 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +11 -0
+}
+
+static int get_page_fault_num(void)
+{
+     FILE *fp;
+     char s[11][256];
+     int pg, ret;
+
+     fp = fopen("/proc/self/stat", "r");
+     if (fp == NULL)
+             tst_brkm(TBROK | TERRNO, cleanup, "Failed to open

/proc/self/stat.");

testcases/kernel/syscalls/madvise/madvise06.c

Quoted 3 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +3 -0
+
+     ret = fscanf(fp, "%s %s %s %s %s %s %s %s %s %s %s %d",
+                     s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7],
Quoted 8 lines

s[8], s[9], s[10], &pg);

fscanf has assigment-supression operator '*' so you can just do:

SAFE_FILE_SCANF("/proc/self/stat",

                "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %d",
                &pg);

pretty good! it makes the code much less but clearer.

Quoted 44 lines
Quoted 12 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +11 -0
+     if (ret != 12) {
+             tst_resm(TFAIL, "Failed to get page fault num.");
+             pg = -1;
+     }
+
+     fclose(fp);
+     return pg;
+}
+
+static void test_advice_willneed(void)
+{

testcases/kernel/syscalls/madvise/madvise06.c line 172

Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +10 -0
+     int i;
+
+     dst_num = mem_total / GB_SZ;
+     tst_resm(TINFO, "dst_num =  %ld", dst_num);
+
+     if ((id_dst = malloc(dst_num * sizeof(int))) == NULL)
+             tst_brkm(TBROK | TERRNO, NULL, "malloc failed.");
+
+     if ((dst = malloc(dst_num * sizeof(char *))) == NULL)
+             tst_brkm(TBROK | TERRNO, NULL, "malloc failed.");

Make use of SAFE_MALLOC().

Quoted 19 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +19 -0
+     id_src_1gb = -1;
+     src_1gb = INV_PTR;
+     for (i = 0; i < dst_num; ++i) {
+             id_dst[i] = -1;
+             dst[i] = INV_PTR;
+     }
+
+     /* allocate source memory (1GB only) */
+     id_src_1gb = shmget(IPC_PRIVATE, 1 * GB_SZ, IPC_CREAT);
+     if (id_src_1gb == -1)
+             tst_brkm(TBROK | TERRNO, cleanup, "shmget failed");
+     src_1gb = shmat(id_src_1gb, 0, 0);
+     if (src_1gb == INV_PTR)
+             tst_brkm(TBROK | TERRNO, cleanup, "shmat failed");
+
+     /* allocate destination memory (array) */
+     for (i = 0; i < dst_num; ++i) {
+             id_dst[i] = shmget(IPC_PRIVATE, 1 * GB_SZ, IPC_CREAT);
+             if (id_dst[i] == -1)
Quoted 9 lines

testcases/kernel/syscalls/madvise/madvise06.c line 197

Quoted 5 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +5 -0
+                     tst_brkm(TBROK | TERRNO, cleanup, "shmget failed");
+
+             dst[i] = shmat(id_dst[i], 0, 0);
+             if (dst[i] == INV_PTR)
+                     tst_brkm(TBROK | TERRNO, cleanup, "shmat failed");

Why can't we just use mmap() with MAP_ANONYMOUS instead? Do we really need to use the System V shm?

Just tried mmap() with flag 'MAP_SHARED | MAP_ANONYMOUS', it reproduced the bug as we expected. Now, I decide to use mmap(). thanks!

Quoted 38 lines

testcases/kernel/syscalls/madvise/madvise06.c line 203

Quoted 7 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +6 -0
+     }
+
+     /* memmove  source to each destination memories (for SWAP-OUT) */
+     for (i = 0; i < dst_num; ++i) {
+             memmove(dst[i], src_1gb, 1 * GB_SZ);
+             fflush(stdout);

Why do we fflush(stdout) here? We do not write to it at all.

testcases/kernel/syscalls/madvise/madvise06.c

Quoted 4 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +4 -0
+     }
+
+     /* Do madvice() to dst[0] */
+     tst_resm(TINFO, "PageFault(before madvice): %d",

get_page_fault_num());

testcases/kernel/syscalls/madvise/madvise06.c line 212

Quoted 5 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +5 -0
+
+     TEST(madvise(dst[0], PG_SZ, MADV_WILLNEED));
+     if (TEST_RETURN == -1)
+             tst_brkm(TBROK | TERRNO, cleanup, "madvise failed");
+     sleep(3);  /* wait for read from SWAP */

Can't we just loop here with a usleep(1000) waiting for the page_fault count to increase?

Doing blind sleep(3) does not guarantee that the event we are wating for really happened and will slown down the testing.

Quoted 1 line

+ /* Read dst[0] data */

Eh? You are writing to dst[0] here.

Review

Quoted 2 lines
(quoted diff) +2 -0
+     page_fault_num1 = get_page_fault_num();
+     tst_resm(TINFO, "PageFault(after madvice / before Mem Access):

%d", page_fault_num1);

testcases/kernel/syscalls/madvise/madvise06.c

Quoted 4 lines
testcases/kernel/syscalls/madvise/madvise06.c new file +4 -0
+
+     *dst[0] = 10;
+     page_fault_num2 = get_page_fault_num();
+     tst_resm(TINFO, "PageFault(after madvice / after Mem Access): %d",
Quoted 9 lines

page_fault_num2);

You are allocating the dst arrays on each test iteration but they are not freed. You should rather allocate them once in the setup and free then in the cleanup.

Also the test would not run if you have more than 100GB so we can easily setup static global array for 100 pointers and be done with it.

sure, I tend to declare the global arrays as id_des[100], dst[100].

And, I accepted all the other comments in above. Thanks for reviewing, PATCH V2 will be sent out soon.

Signature · 6 lines
Regards,
Li Wang
Email: [email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20160329/c0b3a0f6/attachment-0001.html>