Created
February 9, 2016 18:48
-
-
Save buchgr/ab49c171ba0a3390ae48 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <unistd.h> | |
#include <sys/syscall.h> | |
#include <sys/mman.h> | |
#include <cstring> | |
#include <cstdio> | |
int main(int argc, char** argv) { | |
constexpr size_t SIZE = 512 << 20; | |
unsigned i = 10; | |
void *p = mmap(NULL, SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0); | |
while(i--) { | |
memset(p, 1, SIZE); | |
// 4 = MADV_DONTNEED, 8 = MADV_FREE | |
long err = syscall(SYS_madvise, p, SIZE, 4); | |
if (err) | |
printf("err: %ld\n", err); | |
} | |
return 0; | |
} |
Author
buchgr
commented
Feb 9, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment