Created
August 19, 2015 13:12
-
-
Save niedbalski/abaeb047d4dbeef0b7c9 to your computer and use it in GitHub Desktop.
madvise tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
niedbalski@theos-mobile:~$ cat test-madvise.c | |
#include <sys/mman.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <string.h> | |
int main(void) { | |
size_t size = sysconf(_SC_PAGE_SIZE) * 6; //24K | |
void *two_pages = mmap(NULL, size, | |
PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, | |
-1, 0); | |
memset(two_pages, 0, size); | |
//madvise(two_pages, size, MADV_MERGEABLE); | |
for(;;) {} | |
munmap(two_pages, size); | |
return 0; | |
} | |
niedbalski@theos-mobile:~$ cat /sys/kernel/mm/ksm/pages_shared | |
0 | |
niedbalski@theos-mobile:~$ pmap $(pgrep madvise) | grep rwx | |
00007fe681a76000 24K rwx-- [ anon ] | |
niedbalski@theos-mobile:~$ cat /proc/$(pgrep madvise)/status | grep VmPTE | |
VmPTE: 24 kB | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
niedbalski@theos-mobile:~$ cat test-madvise.c | |
#include <sys/mman.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <string.h> | |
int main(void) { | |
size_t size = sysconf(_SC_PAGE_SIZE) * 6; //24K | |
void *two_pages = mmap(NULL, size, | |
PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, | |
-1, 0); | |
memset(two_pages, 0, size); | |
madvise(two_pages, size, MADV_MERGEABLE); | |
for(;;) {} | |
munmap(two_pages, size); | |
return 0; | |
} | |
niedbalski@theos-mobile:~$ cat /sys/kernel/mm/ksm/pages_shared | |
1 | |
niedbalski@theos-mobile:~$ pmap $(pgrep madvise) | grep rwx | |
00007fa7fea9a000 24K rwx-- [ anon ] | |
niedbalski@theos-mobile:~$ cat /proc/$(pgrep madvise)/status | grep VmPTE | |
VmPTE: 28 kB | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment