[Dovecot] test program #2: mmaping

Greg Troxel gdt at ir.bbn.com
Thu Jun 21 15:06:22 EEST 2007


I'm not sure what you expect to happen, but:

fnord gdt 18 ~ > ./concurrency 
0: reading, page size = 4096
writing, page size = 4096
4: reading, page size = 4096
3: reading, page size = 4096
2: reading, page size = 4096
1: reading, page size = 4096
open(): No such file or directory
open(): No such file or directory
open(): No such file or directory
open(): No such file or directory
open(): No such file or directory
fnord gdt 19 ~ > ps uaxw|egrep con
gdt     19239  0.0  0.1   104   548 ttyp1  S     7:55AM 0:00.00 ./concurrency 
[other false hits redacted]
fnord gdt 20 ~ > uname -a
NetBSD fnord.ir.bbn.com 4.0_BETA2 NetBSD 4.0_BETA2 (GENERIC) #11: Mon Apr 30 10:46:41 EDT 2007  gdt at fnord.ir.bbn.com:/n0/obj/gdt-4/i386/sys/arch/i386/compile/GENERIC i386

My system has 2 cpus.


Reading the code, I don't understand why this shouldn't happen - the
bottom branch in the children gets to the open before the top has done
rename, and there's no synchronization to prevent this.

With the following, it prints the 'reading' lines and then sits running:

fnord gdt 68 ~ > ./concurrency 
writing, page size = 4096
0: reading, page size = 4096
4: reading, page size = 4096
3: reading, page size = 4096
2: reading, page size = 4096
1: reading, page size = 4096
...........................................................................................................................................................................................................................................^C


--- concurrency.c.~1~	2007-06-21 07:54:51.000000000 -0400
+++ concurrency.c	2007-06-21 08:05:33.000000000 -0400
@@ -43,16 +43,19 @@
 				perror("rename()");
 			usleep(rand() % 1000);
 
-			pwrite(fd, buf, pagesize + 16, 0);
+			if (pwrite(fd, buf, pagesize + 16, 0) < 0)
+				perror("pwrite1()");
 			//usleep(rand() % 1000);
 			//fdatasync(fd);
-			pwrite(fd, ones, 4, pagesize-4);
+			if (pwrite(fd, ones, 4, pagesize-4) < 0)
+				perror("pwrite1()");
 			if (flock(fd, LOCK_UN) < 0)
 				perror("flock()");
 			close(fd);
 			usleep(rand() % 1000);
 		}
 	} else {
+		sleep(1);
 		while (process_count-- > 1) {
 			if (fork() == 0)
 				break;
@@ -61,7 +64,7 @@
 		for (;; close(fd), usleep(rand() % 1000)) {
 			fd = open("foo", O_RDWR, 0600);
 			if (fd == -1) {
-				perror("open()");
+				perror("open_lower()");
 				return 1;
 			}
 
@@ -93,6 +96,7 @@
 				} else if (((char *)mmap_base)[pagesize] != 'h')
 					printf("broken data\n");
 			}
+			putchar('.'); fflush(stdout);			
 		}
 	}
 	return 0;


More information about the dovecot mailing list