From 1f7e92aa4ac17b3235718a0950807a78c58d9082 Mon Sep 17 00:00:00 2001 From: flavono123 Date: Sat, 19 Nov 2016 22:22:00 +0900 Subject: [PATCH 1/3] madv_free: dirts pages and use 'madvise()' rather than 'sys_madvise()' Before this commit, two test scripts has no differences. To do page faults, write all page contents as soon as memory allocated by memset. Do NOT use glibc malloc since that does not support MADV_FREE, thus use mmap. Actually, nothing to do on source file for that since it can be done by command line option. So it would be committed on test script commit. Use madvise NOT sys_madvise directly by syscall. Those are done only the size to allocate memory over 4096. --- feature-evals/madv_free/ebizzy_madv.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/feature-evals/madv_free/ebizzy_madv.c b/feature-evals/madv_free/ebizzy_madv.c index 8fe4861..392fadd 100644 --- a/feature-evals/madv_free/ebizzy_madv.c +++ b/feature-evals/madv_free/ebizzy_madv.c @@ -263,10 +263,14 @@ alloc_mem(size_t size) err = 1; } - if (madv_flag) - syscall(__NR_madvise, p, size, MADV_FREE); - else - syscall(__NR_madvise, p, size, MADV_DONTNEED); + memset(p, 1, size); + + if (size > 4096) { + if (madv_flag) + madvise(p, size, MADV_FREE); + else + madvise(p, size, MADV_DONTNEED); + } if (err) { fprintf(stderr, "Couldn't allocate %zu bytes, try smaller " From e7b073830dcc5c142b781999e143d9d76a0e7b89 Mon Sep 17 00:00:00 2001 From: flavono123 Date: Sat, 19 Nov 2016 22:30:05 +0900 Subject: [PATCH 2/3] madv_free: use '-m' option for ebizzy_madv To allocate memory by mmap NOT malloc, use the '-m' option for binary ebizzy_madv. Followed command will be run in test_dontneed.py; $ ./ebizzy_madv -S 10 -n 512 -m --- feature-evals/madv_free/test_dontneed.py | 2 +- feature-evals/madv_free/test_free.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/feature-evals/madv_free/test_dontneed.py b/feature-evals/madv_free/test_dontneed.py index 3fcfe83..9c417bb 100755 --- a/feature-evals/madv_free/test_dontneed.py +++ b/feature-evals/madv_free/test_dontneed.py @@ -14,7 +14,7 @@ def exec_cmd(cmd): stderr=subprocess.PIPE) def set_cmd(flag): - cmd = "./ebizzy_madv -S 10 -n 512" + cmd = "./ebizzy_madv -S 10 -n 512 -m" if flag == "MADV_FREE": cmd += " -f" return cmd diff --git a/feature-evals/madv_free/test_free.py b/feature-evals/madv_free/test_free.py index 23b05e2..d25e182 100755 --- a/feature-evals/madv_free/test_free.py +++ b/feature-evals/madv_free/test_free.py @@ -14,7 +14,7 @@ def exec_cmd(cmd): stderr=subprocess.PIPE) def set_cmd(flag): - cmd = "./ebizzy_madv -S 10 -n 512" + cmd = "./ebizzy_madv -S 10 -n 512 -m" if flag == "MADV_FREE": cmd += " -f" return cmd From 430fcfc77431ae2ee46f42beb02ce27585be3db2 Mon Sep 17 00:00:00 2001 From: flavono123 Date: Sat, 19 Nov 2016 22:36:41 +0900 Subject: [PATCH 3/3] madv_free: do NOT dirt page for memory pointer The page for pointer of memory, to write patterns and searched, is NOT dirted by memset. That page is used for just array of memories to real thread works, binary search. So, do memeset that size is over 4096 since that page size is 4096. --- feature-evals/madv_free/ebizzy_madv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feature-evals/madv_free/ebizzy_madv.c b/feature-evals/madv_free/ebizzy_madv.c index 392fadd..8a3c35b 100644 --- a/feature-evals/madv_free/ebizzy_madv.c +++ b/feature-evals/madv_free/ebizzy_madv.c @@ -263,9 +263,9 @@ alloc_mem(size_t size) err = 1; } - memset(p, 1, size); - if (size > 4096) { + memset(p, 1, size); + if (madv_flag) madvise(p, size, MADV_FREE); else