ebruakagunduz

thp_test half read, half write pages

Jan 16th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5. int *memory_area1 = malloc(819200000);
  6. int *p;
  7.  
  8. int i, j = 0;
  9. for (i = 0; i < 200000; i++) {
  10. /* write per 4kB, 1024*4byte */
  11. memory_area1[j] = 1;
  12. j += 1024;
  13. }
  14.  
  15. printf("First 800MB allocated\n");
  16. sleep(10);
  17. printf("After 600 seconds start to read first area\n");
  18. sleep(600);
  19. printf("Ten seconds ..\n");
  20. sleep(10);
  21. printf("Starting..\n");
  22. /* read or write every 4kb page to make swapped in */
  23.  
  24. for (i = 0; i < 100000; i++) {
  25. /* 1024*4bytes = 4kB read */
  26. *p = *memory_area1;
  27. memory_area1 += 1024;
  28. /* 1024*4bytes = 4kB write */
  29. *memory_area1 = 1;
  30. memory_area1 += 1024;
  31. }
  32. printf("Read is completed\n");
  33. getchar();
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment