Skip to content

Instantly share code, notes, and snippets.

@73696e65
Forked from niedbalski/no-madvise.c
Created June 19, 2017 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 73696e65/afa703a26ac28230bcb8a1de8d14da59 to your computer and use it in GitHub Desktop.
Save 73696e65/afa703a26ac28230bcb8a1de8d14da59 to your computer and use it in GitHub Desktop.
madvise tests
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
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