Advertisement
Guest User

Untitled

a guest
Oct 16th, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. p4f# cat page_fault4.c
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <sys/mman.h>
  5. #include <assert.h>
  6.  
  7. //#define MEMSIZE (128 * 1024 * 1024)
  8. #define MEMSIZE (8 * 1024)
  9.  
  10. char *testcase_description = "Anonymous memory page fault";
  11.  
  12. void testcase(unsigned long long *iterations, unsigned long nr)
  13. {
  14. unsigned long pgsize = getpagesize();
  15.  
  16. int clines = atoi(getenv("CLINES"));
  17.  
  18. while (1) {
  19. unsigned long i, l;
  20.  
  21. char *c = mmap(NULL, MEMSIZE, PROT_READ|PROT_WRITE,
  22. MAP_PRIVATE|MAP_ANON, -1, 0);
  23. assert(c != MAP_FAILED);
  24.  
  25. for (i = 0; i < MEMSIZE; i += pgsize) {
  26. for (l = 0; l < clines; l++)
  27. c[i + l * 64] = 0;
  28. (*iterations)++;
  29. }
  30.  
  31. munmap(c, MEMSIZE);
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement