os161-1.99
 All Data Structures
vm-data2.c
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 
00004 #define PAGE_SIZE       (4096)
00005 #define PAGES           (2048)  /* 8 MB worth of data : won't all fit */
00006 #define SIZE            (PAGE_SIZE * PAGES / sizeof(int))
00007 #define NUM_REFS        (2)
00008 #define PAGES_TO_TOUCH  (1536) /* Touching 6 MB of data */
00009 
00010 /* Create a very large array */
00011 unsigned int array[SIZE];
00012 
00013 int
00014 main()
00015 {
00016         unsigned int i = 0;
00017         unsigned int index = 0;
00018         unsigned int refs = 0;
00019 
00020         for (refs = 0; refs < NUM_REFS; refs++) {
00021                 for (i=0; i<PAGES_TO_TOUCH; i++) {
00022                         index = i * PAGE_SIZE  / sizeof(int);
00023                         array[index] = i;
00024                 }
00025         }
00026 
00027         for (i=0; i<PAGES_TO_TOUCH; i++) {
00028                 index = i * PAGE_SIZE  / sizeof(int);
00029                 if (array[index] != i) {
00030                         printf("FAILED array[%d] = %u != %d\n", i, array[index], i);
00031                         exit(1);
00032                 }
00033         }
00034 
00035         printf("SUCCEEDED\n");
00036         exit(0);
00037 }
 All Data Structures