4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
38 * --------------------------------------------------------------------
40 * The bug time sequence:
41 * 1. context #1, zfs_write assign a txg "n".
42 * 2. In the same process, context #2, mmap page fault (which means the mm_sem
43 * is hold) occurred, zfs_dirty_inode open a txg failed, and wait previous
45 * 3. context #1 call zfs_uiomove to write, however page fault is occurred in
46 * zfs_uiomove, which means it needs mm_sem, but mm_sem is hold by
47 * context #2, so it stuck and can't complete, then txg "n" will not
50 * So context #1 and context #2 trap into the "dead lock".
51 * --------------------------------------------------------------------
54 #define NORMAL_WRITE_TH_NUM 2
55 #define MAX_WRITE_BYTES 262144000
58 normal_writer(void *filename
)
60 char *file_path
= filename
;
62 ssize_t write_num
= 0;
63 int page_size
= getpagesize();
65 fd
= open(file_path
, O_RDWR
| O_CREAT
, 0777);
67 err(1, "failed to open %s", file_path
);
71 off_t bytes_written
= 0;
73 while (bytes_written
< MAX_WRITE_BYTES
) {
74 write_num
= write(fd
, &buf
, 1);
76 err(1, "write failed!");
79 if ((bytes_written
= lseek(fd
, page_size
, SEEK_CUR
)) == -1) {
80 err(1, "lseek failed on %s: %s", file_path
,
87 err(1, "failed to close file");
93 map_writer(void *filename
)
98 int page_size
= getpagesize();
99 char *file_path
= filename
;
102 fd
= open(file_path
, O_RDWR
);
104 if (errno
== ENOENT
) {
105 fd
= open(file_path
, O_RDWR
| O_CREAT
, 0777);
107 err(1, "open file failed");
109 ret
= ftruncate(fd
, page_size
);
111 err(1, "truncate file failed");
114 err(1, "open file failed");
118 if ((buf
= mmap(NULL
, page_size
, PROT_READ
| PROT_WRITE
,
119 MAP_SHARED
, fd
, 0)) == MAP_FAILED
) {
120 err(1, "map file failed");
128 ret
= munmap(buf
, page_size
);
130 err(1, "unmap file failed");
136 main(int argc
, char **argv
)
138 pthread_t map_write_tid
;
139 pthread_t normal_write_tid
[NORMAL_WRITE_TH_NUM
];
143 (void) printf("usage: %s <normal write file name> "
144 "<map write file name>\n", argv
[0]);
148 for (i
= 0; i
< NORMAL_WRITE_TH_NUM
; i
++) {
149 if (pthread_create(&normal_write_tid
[i
], NULL
, normal_writer
,
151 err(1, "pthread_create normal_writer failed.");
155 if (pthread_create(&map_write_tid
, NULL
, map_writer
, argv
[2])) {
156 err(1, "pthread_create map_writer failed.");
159 pthread_join(map_write_tid
, NULL
);