vm-data2.c 806 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define PAGE_SIZE (4096)
  4. #define PAGES (2048) /* 8 MB worth of data : won't all fit */
  5. #define SIZE (PAGE_SIZE * PAGES / sizeof(int))
  6. #define NUM_REFS (2)
  7. #define PAGES_TO_TOUCH (1536) /* Touching 6 MB of data */
  8. /* Create a very large array */
  9. unsigned int array[SIZE];
  10. int
  11. main()
  12. {
  13. unsigned int i = 0;
  14. unsigned int index = 0;
  15. unsigned int refs = 0;
  16. for (refs = 0; refs < NUM_REFS; refs++) {
  17. for (i=0; i<PAGES_TO_TOUCH; i++) {
  18. index = i * PAGE_SIZE / sizeof(int);
  19. array[index] = i;
  20. }
  21. }
  22. for (i=0; i<PAGES_TO_TOUCH; i++) {
  23. index = i * PAGE_SIZE / sizeof(int);
  24. if (array[index] != i) {
  25. printf("FAILED array[%d] = %u != %d\n", i, array[index], i);
  26. exit(1);
  27. }
  28. }
  29. printf("SUCCEEDED\n");
  30. exit(0);
  31. }