Commit 5c68199029e7a3f63d43e6cb0984396460113f71
1 parent
41e17e5f11
Exists in
master
Small changes to file contention
Showing 2 changed files with 28 additions and 15 deletions Side-by-side Diff
filesystem/file_contention.c
View file @
5c68199
... | ... | @@ -4,44 +4,57 @@ |
4 | 4 | #include <string.h> |
5 | 5 | #include <stdlib.h> |
6 | 6 | #include <sys/time.h> |
7 | -#define BLOCK_SIZE 1024 | |
7 | +#define BLOCK_SIZE 4096 | |
8 | + | |
8 | 9 | void main() |
9 | 10 | { |
10 | - char fname[10]="file_"; | |
11 | 11 | char buffer[BLOCK_SIZE] __attribute__ ((__aligned__ (512))); |
12 | 12 | struct timeval start, end; |
13 | 13 | int fd=0; |
14 | - char *file; | |
15 | 14 | int i = 0; |
16 | 15 | unsigned long long time; |
17 | - int status; | |
18 | - char *names[] = {"1", "2", "3", "4", "5", "6", "7"}; | |
19 | - while (i < 7) { | |
16 | + int child_status; | |
17 | + char *fnames[] = {"file_1", "file_2", "file_3", "file_4", "file_5", "file_6", | |
18 | + "file_7", "file_8", "file_9"}; | |
19 | + int numProcesses = 0; | |
20 | + | |
21 | +label: | |
22 | + numProcesses++; | |
23 | + i = 0; | |
24 | + printf("numProcesses: %d\n", numProcesses); | |
25 | + while (i < numProcesses) { | |
20 | 26 | int pid = fork(); |
21 | 27 | if (pid == 0) { |
22 | - file = strcat(fname, names[i]); | |
23 | - fd = open(fname, O_RDONLY | O_DIRECT); | |
28 | + //printf("Opening %d %s\n", i, fnames[i]); | |
29 | + fd = open(fnames[i], O_RDONLY|O_DIRECT); | |
30 | + fflush(stdout); | |
24 | 31 | if (!fd) { |
25 | 32 | printf("unable to open\n"); |
26 | - exit(0); | |
33 | + exit(1); | |
27 | 34 | } |
28 | - printf("accessing %n", file); | |
29 | - sleep(2); | |
30 | 35 | gettimeofday(&start, NULL); |
31 | - while(read(fd, buffer, BLOCK_SIZE)); | |
36 | + while(1) { | |
37 | + int rc = read(fd, buffer, BLOCK_SIZE); | |
38 | + if (rc < 0) { | |
39 | + perror("Read Error"); | |
40 | + exit(1); | |
41 | + } else if(rc == 0) | |
42 | + break; | |
43 | + } | |
32 | 44 | gettimeofday(&end, NULL); |
33 | 45 | lseek(fd, 0, SEEK_SET); |
34 | 46 | time = (end.tv_sec*1e6+end.tv_usec) - (start.tv_sec*1e6+start.tv_usec); |
35 | - // printf("timestamp %llu - %llu\n", end.tv_sec*1e6+end.tv_usec, start.tv_sec*1e6+start.tv_usec); | |
36 | 47 | printf("time taken to read file # %d - %llu\n", i, time); |
37 | 48 | sync(); |
38 | - status = system("sudo /sbin/sysctl vm.drop_caches=3"); | |
49 | + child_status = system("sudo /sbin/sysctl vm.drop_caches=3"); | |
39 | 50 | sync(); |
40 | 51 | exit(0); |
41 | 52 | } |
42 | 53 | i++; |
43 | 54 | } |
44 | 55 | sleep(10); |
45 | - wait(&status); | |
56 | + wait(&child_status); | |
57 | + if (numProcesses < 9) | |
58 | + goto label; | |
46 | 59 | } |
filesystem/file_contention.o
View file @
5c68199