1 /* swaptest.c 0.1 (C) Jon Burgess 92jjb@eng.cam.ac.uk
3 * Tests the performance of the linux swap system
4 * Generates a block of random data, reading it a number of times.
7 * <size> memory size to try
8 * -time do automatic timing
9 * -random random pattern of data access
10 * -dirty dirty data on every access
11 * -cycles number of iterations of read to try.
16 #include <sys/types.h>
21 #define MEM_KB (MEM_MB*1024)
22 #define MEM_SIZE (MEM_KB*1024)
25 main(int argc, char *argv[])
33 buf = (char *) malloc(MEM_SIZE);
36 file = fopen ("/dev/urandom","r");
38 printf("Error reading /dev/random\n");
42 /* Get a 1kB of random data */
43 if (1 != fread( buf, 1024, 1, file)) {
44 printf("Error reading random data\n");
47 for (i=1; i<MEM_KB;i++)
48 memcpy(buf+(i*1024),buf,1024);
51 for(ptr = 0; ptr < MEM_SIZE; ptr+=4) {
52 *(unsigned long *)(ptr + buf) = ptr;
55 for(i=0;i<ITERATIONS;i++) {
56 printf("Running loop %d\n",i);
57 for(ptr=0; ptr<MEM_SIZE; ptr+=4096){
61 test = *(unsigned long *)(ptr + buf);
63 printf("AIEEE: memory corrupted at %d, reads as %08lx\n",
67 /* Do we dirty each page? */