Skip to contentSkip to conversation

madvice: new case for madvise(WILLNEED)

PATCH Superseded Li Wang 2 participants 4 messages Apr 1, 2016 – Apr 5, 2016

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v3 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 | 157 ++++++++++++++++++++++++++
 3 files changed, 159 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 +157 -0

157 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#1 lore raw

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

Sorry, I missed to append the notes in patch V3.

V2 --> V3
* remove the unused <sys/shm.h>
* reset TST_TOTAL = 1
* rename variable dst_num to dst_max
* take use of SAFE_MMAP(), SAFE_MUNMAP()
* no sleep() in the program
* fix the lines over 80 chars issue
* delete the kernel choise lines

Signature · 6 lines
Regards,
Li Wang
Email: [email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20160401/b91c3aa5/attachment.html>
#2 lore raw

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

In reply to Li Wang

Hi!

Quoted 1 line

+#ifdef __x86_64__

Last question, why do we limit the test to x86_64?

Since apart from hardcoded page size, there does not seem to be anything x86_64 specific at all.

Otherwise the test looks fine.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#3 lore raw

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

Hello Cyril,

Quoted 8 lines · Cyril Hrubis

Hi!

Quoted 1 line

+#ifdef __x86_64__

Last question, why do we limit the test to x86_64?

Since apart from hardcoded page size, there does not seem to be anything x86_64 specific at all.

Thanks for reminding me, limit the test program to x86_64 because the bug was detected on that platform, I did not noticed the portable issue.

If the following changes test good(bug reproduced) on other platform, I will post V4.

v3 ---> v4
------------

$ git diff
(quoted diff) +0 -0

b/testcases/kernel/syscalls/madvise/madvise06.c
index 44a40ba..41e51f9 100644

testcases/kernel/syscalls/madvise/madvise06.c +3 -13
@@ -43,10 +43,7 @@
 char *TCID = "madvise06";
 int TST_TOTAL = 1;
 
-#ifdef __x86_64__
-
 #define GB_SZ  (1024*1024*1024)
-#define PG_SZ  (4*1024)
 
 static long dst_max;
 
@@ -100,7 +97,7 @@ static int get_page_fault_num(void)
 
 static void test_advice_willneed(void)
 {
-       int i;
+       int i, pg_sz;
        char *src;
        char *dst[100];
        int page_fault_num_1;
@@ -124,8 +121,9 @@ static void test_advice_willneed(void)
 
        tst_resm(TINFO, "PageFault(no madvice): %d", get_page_fault_num());
 
+       pg_sz = getpagesize();
        /* Do madvice() to dst[0] */
-       TEST(madvise(dst[0], PG_SZ, MADV_WILLNEED));
+       TEST(madvise(dst[0], pg_sz, MADV_WILLNEED));
        if (TEST_RETURN == -1)
                tst_brkm(TBROK | TERRNO, NULL, "madvise failed");
 
@@ -147,11 +145,3 @@ static void test_advice_willneed(void)
        for (i = 0; i < dst_max; ++i)
                SAFE_MUNMAP(NULL, dst[i], 1 * GB_SZ);
 }
-
-
-#else
-int main(void)
-{
-       tst_brkm(TCONF, NULL, "Only test on x86_64.");
-}
-#endif
Quoted 7 lines

Otherwise the test looks fine.

--
Cyril Hrubis
[email protected]

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