#include #include #include #include #include #include #include #include #include #define BLIND_THREADS 8 #define READDIR_THREADS 4 #define MAX_FILE_COUNT_PER_THREAD 200000 #define SYNC_INTERVAL 1 #define MAX_FILE_SIZE (8 * 1024 * 1024) void blind_thread(); void readdir_thread(); int main(int argc, char *argv[]) { int i = 0; for(i = 0;i < BLIND_THREADS;i++) { if (!fork()) { blind_thread(); } } for(i = 0;i < READDIR_THREADS;i++) { if (!fork()) { readdir_thread(); } } while(1) { sleep(SYNC_INTERVAL); sync(); } return 0; } void blind_thread() { while(1) { unsigned int seed; struct timeval tv; int i; int count; gettimeofday(&tv, NULL); seed = tv.tv_usec; count = seed % MAX_FILE_COUNT_PER_THREAD; srand(seed); printf("Creating %i files\n" , count); for(i = 0; i < count;i++) { char filename[32]; snprintf(filename, 32, "%x", rand()); close(open(filename, O_CREAT | O_RDONLY)); } printf("Performing %i random lookups\n" , count); for(i = 0; i < count;i++) { char filename[32]; struct stat useless; snprintf(filename, 32, "%x", rand()); stat(filename, &useless); } srand(seed); printf("Unlinking %i files\n" , count); for(i = 0; i < count;i++) { char filename[32]; snprintf(filename, 32, "%x", rand()); unlink(filename); } } } void readdir_thread() { while(1) { DIR *dir; struct dirent *entry; dir = opendir("."); while((entry = readdir(dir))) { struct stat st; stat(entry->d_name, &st); if (S_ISREG(st.st_mode)) { switch(rand() % 3) { case 0: unlink(entry->d_name); case 1: truncate(entry->d_name, rand() % MAX_FILE_SIZE); case 2: { char filename[32]; snprintf(filename, 32, "%x", rand()); rename(entry->d_name, filename); } } } } closedir(dir); } }