Swapping performance tester

J.J. Burgess (92jjb@eng.cam.ac.uk)
Thu, 25 Apr 1996 21:33:38 +0100 (BST)


Below is a quick crude program to measure swap performance,
if the swap size is set to 8meg, the program takes about 2 seconds to
complete, if it is set to 12meg it takes over 2 minutes (with only about
2 seconds of user+system) this is with 16meg. of ram. Surely we can
better this factor of 60 slowdown?
(This is on a 16meg machine, 1.3.95)

- obviously something isn't doing any large predictive read-ahead swap in
or page outs!.

/* swaptest.c 0.1 (C) Jon Burgess 92jjb@eng.cam.ac.uk
*
* Tests the performance of the linux swap system
* Generates a block of random data, reading it a number of times.
*/
/* TODO: options
* <size> memory size to try
* -time do automatic timing
* -random random pattern of data access
* -dirty dirty data on every access
* -cycles number of iterations of read to try.
*/

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define MEM_MB 12
#define MEM_KB (MEM_MB*1024)
#define MEM_SIZE (MEM_KB*1024)
#define ITERATIONS 2

main(int argc, char *argv[])
{
char *buf;
int i,ptr;
char junk;
FILE *file;

buf = (char *) malloc(MEM_SIZE);

file = fopen ("/dev/urandom","r");
if (!file) {
printf("Error reading /dev/random\n");
exit(1);
}

/* Get a 1kB of random data */
if (1 != fread( buf, 1024, 1, file)) {
printf("Error reading random data\n");
exit(1);
}
for (i=1; i<MEM_KB;i++)
memcpy(buf+(i*1024),buf,1024);

for(i=0;i<ITERATIONS;i++) {
printf("Running loop %d\n",i);
for(ptr=0; ptr<MEM_SIZE; ptr+=4096){
junk = *(ptr+buf);

/* Do we dirty each page? */
#if 0
*(ptr+buf) = 0;
#endif
}
}
exit(0);
}

Thanks.

.. . . . . . . . . . . . . . ..
:: : : Jon Burgess 01223-461907 : : ::
:: : jjb1003@cam.ac.uk : : ::
:: : : : : : : : : : : : : : ::