author | perrin |
Thu, 24 Jul 2008 11:23:47 -0700 | |
changeset 7181 | 8d299641aa23 |
parent 7046 | 361307ae060d |
child 7294 | c9c31ef4c960 |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1472 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
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] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
/* |
|
5809
084c69fe7d0a
6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents:
5712
diff
changeset
|
22 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
#pragma ident "%Z%%M% %I% %E% SMI" |
|
27 |
||
28 |
#include <sys/zfs_context.h> |
|
29 |
#include <sys/spa.h> |
|
30 |
#include <sys/dmu.h> |
|
31 |
#include <sys/zap.h> |
|
32 |
#include <sys/arc.h> |
|
33 |
#include <sys/stat.h> |
|
34 |
#include <sys/resource.h> |
|
35 |
#include <sys/zil.h> |
|
36 |
#include <sys/zil_impl.h> |
|
37 |
#include <sys/dsl_dataset.h> |
|
38 |
#include <sys/vdev.h> |
|
3668 | 39 |
#include <sys/dmu_tx.h> |
789 | 40 |
|
41 |
/* |
|
42 |
* The zfs intent log (ZIL) saves transaction records of system calls |
|
43 |
* that change the file system in memory with enough information |
|
44 |
* to be able to replay them. These are stored in memory until |
|
45 |
* either the DMU transaction group (txg) commits them to the stable pool |
|
46 |
* and they can be discarded, or they are flushed to the stable log |
|
47 |
* (also in the pool) due to a fsync, O_DSYNC or other synchronous |
|
48 |
* requirement. In the event of a panic or power fail then those log |
|
49 |
* records (transactions) are replayed. |
|
50 |
* |
|
51 |
* There is one ZIL per file system. Its on-disk (pool) format consists |
|
52 |
* of 3 parts: |
|
53 |
* |
|
54 |
* - ZIL header |
|
55 |
* - ZIL blocks |
|
56 |
* - ZIL records |
|
57 |
* |
|
58 |
* A log record holds a system call transaction. Log blocks can |
|
59 |
* hold many log records and the blocks are chained together. |
|
60 |
* Each ZIL block contains a block pointer (blkptr_t) to the next |
|
61 |
* ZIL block in the chain. The ZIL header points to the first |
|
62 |
* block in the chain. Note there is not a fixed place in the pool |
|
63 |
* to hold blocks. They are dynamically allocated and freed as |
|
64 |
* needed from the blocks available. Figure X shows the ZIL structure: |
|
65 |
*/ |
|
66 |
||
67 |
/* |
|
2986 | 68 |
* This global ZIL switch affects all pools |
789 | 69 |
*/ |
70 |
int zil_disable = 0; /* disable intent logging */ |
|
2986 | 71 |
|
72 |
/* |
|
73 |
* Tunable parameter for debugging or performance analysis. Setting |
|
74 |
* zfs_nocacheflush will cause corruption on power loss if a volatile |
|
75 |
* out-of-order write cache is enabled. |
|
76 |
*/ |
|
77 |
boolean_t zfs_nocacheflush = B_FALSE; |
|
789 | 78 |
|
79 |
static kmem_cache_t *zil_lwb_cache; |
|
80 |
||
81 |
static int |
|
82 |
zil_dva_compare(const void *x1, const void *x2) |
|
83 |
{ |
|
84 |
const dva_t *dva1 = x1; |
|
85 |
const dva_t *dva2 = x2; |
|
86 |
||
87 |
if (DVA_GET_VDEV(dva1) < DVA_GET_VDEV(dva2)) |
|
88 |
return (-1); |
|
89 |
if (DVA_GET_VDEV(dva1) > DVA_GET_VDEV(dva2)) |
|
90 |
return (1); |
|
91 |
||
92 |
if (DVA_GET_OFFSET(dva1) < DVA_GET_OFFSET(dva2)) |
|
93 |
return (-1); |
|
94 |
if (DVA_GET_OFFSET(dva1) > DVA_GET_OFFSET(dva2)) |
|
95 |
return (1); |
|
96 |
||
97 |
return (0); |
|
98 |
} |
|
99 |
||
100 |
static void |
|
101 |
zil_dva_tree_init(avl_tree_t *t) |
|
102 |
{ |
|
103 |
avl_create(t, zil_dva_compare, sizeof (zil_dva_node_t), |
|
104 |
offsetof(zil_dva_node_t, zn_node)); |
|
105 |
} |
|
106 |
||
107 |
static void |
|
108 |
zil_dva_tree_fini(avl_tree_t *t) |
|
109 |
{ |
|
110 |
zil_dva_node_t *zn; |
|
111 |
void *cookie = NULL; |
|
112 |
||
113 |
while ((zn = avl_destroy_nodes(t, &cookie)) != NULL) |
|
114 |
kmem_free(zn, sizeof (zil_dva_node_t)); |
|
115 |
||
116 |
avl_destroy(t); |
|
117 |
} |
|
118 |
||
119 |
static int |
|
120 |
zil_dva_tree_add(avl_tree_t *t, dva_t *dva) |
|
121 |
{ |
|
122 |
zil_dva_node_t *zn; |
|
123 |
avl_index_t where; |
|
124 |
||
125 |
if (avl_find(t, dva, &where) != NULL) |
|
126 |
return (EEXIST); |
|
127 |
||
128 |
zn = kmem_alloc(sizeof (zil_dva_node_t), KM_SLEEP); |
|
129 |
zn->zn_dva = *dva; |
|
130 |
avl_insert(t, zn, where); |
|
131 |
||
132 |
return (0); |
|
133 |
} |
|
134 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
135 |
static zil_header_t * |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
136 |
zil_header_in_syncing_context(zilog_t *zilog) |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
137 |
{ |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
138 |
return ((zil_header_t *)zilog->zl_header); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
139 |
} |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
140 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
141 |
static void |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
142 |
zil_init_log_chain(zilog_t *zilog, blkptr_t *bp) |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
143 |
{ |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
144 |
zio_cksum_t *zc = &bp->blk_cksum; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
145 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
146 |
zc->zc_word[ZIL_ZC_GUID_0] = spa_get_random(-1ULL); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
147 |
zc->zc_word[ZIL_ZC_GUID_1] = spa_get_random(-1ULL); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
148 |
zc->zc_word[ZIL_ZC_OBJSET] = dmu_objset_id(zilog->zl_os); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
149 |
zc->zc_word[ZIL_ZC_SEQ] = 1ULL; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
150 |
} |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
151 |
|
789 | 152 |
/* |
153 |
* Read a log block, make sure it's valid, and byteswap it if necessary. |
|
154 |
*/ |
|
155 |
static int |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
156 |
zil_read_log_block(zilog_t *zilog, const blkptr_t *bp, arc_buf_t **abufpp) |
789 | 157 |
{ |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
158 |
blkptr_t blk = *bp; |
1544 | 159 |
zbookmark_t zb; |
2391 | 160 |
uint32_t aflags = ARC_WAIT; |
789 | 161 |
int error; |
162 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
163 |
zb.zb_objset = bp->blk_cksum.zc_word[ZIL_ZC_OBJSET]; |
1544 | 164 |
zb.zb_object = 0; |
165 |
zb.zb_level = -1; |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
166 |
zb.zb_blkid = bp->blk_cksum.zc_word[ZIL_ZC_SEQ]; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
167 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
168 |
*abufpp = NULL; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
169 |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7030
diff
changeset
|
170 |
/* |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7030
diff
changeset
|
171 |
* We shouldn't be doing any scrubbing while we're doing log |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7030
diff
changeset
|
172 |
* replay, it's OK to not lock. |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7030
diff
changeset
|
173 |
*/ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7030
diff
changeset
|
174 |
error = arc_read_nolock(NULL, zilog->zl_spa, &blk, |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
175 |
arc_getbuf_func, abufpp, ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL | |
2391 | 176 |
ZIO_FLAG_SPECULATIVE | ZIO_FLAG_SCRUB, &aflags, &zb); |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
177 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
178 |
if (error == 0) { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
179 |
char *data = (*abufpp)->b_data; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
180 |
uint64_t blksz = BP_GET_LSIZE(bp); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
181 |
zil_trailer_t *ztp = (zil_trailer_t *)(data + blksz) - 1; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
182 |
zio_cksum_t cksum = bp->blk_cksum; |
1544 | 183 |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
184 |
/* |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
185 |
* Sequence numbers should be... sequential. The checksum |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
186 |
* verifier for the next block should be bp's checksum plus 1. |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
187 |
*/ |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
188 |
cksum.zc_word[ZIL_ZC_SEQ]++; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
189 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
190 |
if (bcmp(&cksum, &ztp->zit_next_blk.blk_cksum, sizeof (cksum))) |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
191 |
error = ESTALE; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
192 |
else if (BP_IS_HOLE(&ztp->zit_next_blk)) |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
193 |
error = ENOENT; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
194 |
else if (ztp->zit_nused > (blksz - sizeof (zil_trailer_t))) |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
195 |
error = EOVERFLOW; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
196 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
197 |
if (error) { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
198 |
VERIFY(arc_buf_remove_ref(*abufpp, abufpp) == 1); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
199 |
*abufpp = NULL; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
200 |
} |
789 | 201 |
} |
202 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
203 |
dprintf("error %d on %llu:%llu\n", error, zb.zb_objset, zb.zb_blkid); |
789 | 204 |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
205 |
return (error); |
789 | 206 |
} |
207 |
||
208 |
/* |
|
209 |
* Parse the intent log, and call parse_func for each valid record within. |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
210 |
* Return the highest sequence number. |
789 | 211 |
*/ |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
212 |
uint64_t |
789 | 213 |
zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func, |
214 |
zil_parse_lr_func_t *parse_lr_func, void *arg, uint64_t txg) |
|
215 |
{ |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
216 |
const zil_header_t *zh = zilog->zl_header; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
217 |
uint64_t claim_seq = zh->zh_claim_seq; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
218 |
uint64_t seq = 0; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
219 |
uint64_t max_seq = 0; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
220 |
blkptr_t blk = zh->zh_log; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
221 |
arc_buf_t *abuf; |
789 | 222 |
char *lrbuf, *lrp; |
223 |
zil_trailer_t *ztp; |
|
224 |
int reclen, error; |
|
225 |
||
226 |
if (BP_IS_HOLE(&blk)) |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
227 |
return (max_seq); |
789 | 228 |
|
229 |
/* |
|
230 |
* Starting at the block pointed to by zh_log we read the log chain. |
|
231 |
* For each block in the chain we strongly check that block to |
|
232 |
* ensure its validity. We stop when an invalid block is found. |
|
233 |
* For each block pointer in the chain we call parse_blk_func(). |
|
234 |
* For each record in each valid block we call parse_lr_func(). |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
235 |
* If the log has been claimed, stop if we encounter a sequence |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
236 |
* number greater than the highest claimed sequence number. |
789 | 237 |
*/ |
238 |
zil_dva_tree_init(&zilog->zl_dva_tree); |
|
239 |
for (;;) { |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
240 |
seq = blk.blk_cksum.zc_word[ZIL_ZC_SEQ]; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
241 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
242 |
if (claim_seq != 0 && seq > claim_seq) |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
243 |
break; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
244 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
245 |
ASSERT(max_seq < seq); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
246 |
max_seq = seq; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
247 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
248 |
error = zil_read_log_block(zilog, &blk, &abuf); |
789 | 249 |
|
250 |
if (parse_blk_func != NULL) |
|
251 |
parse_blk_func(zilog, &blk, arg, txg); |
|
252 |
||
253 |
if (error) |
|
254 |
break; |
|
255 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
256 |
lrbuf = abuf->b_data; |
789 | 257 |
ztp = (zil_trailer_t *)(lrbuf + BP_GET_LSIZE(&blk)) - 1; |
258 |
blk = ztp->zit_next_blk; |
|
259 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
260 |
if (parse_lr_func == NULL) { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
261 |
VERIFY(arc_buf_remove_ref(abuf, &abuf) == 1); |
789 | 262 |
continue; |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
263 |
} |
789 | 264 |
|
265 |
for (lrp = lrbuf; lrp < lrbuf + ztp->zit_nused; lrp += reclen) { |
|
266 |
lr_t *lr = (lr_t *)lrp; |
|
267 |
reclen = lr->lrc_reclen; |
|
268 |
ASSERT3U(reclen, >=, sizeof (lr_t)); |
|
269 |
parse_lr_func(zilog, lr, arg, txg); |
|
270 |
} |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
271 |
VERIFY(arc_buf_remove_ref(abuf, &abuf) == 1); |
789 | 272 |
} |
273 |
zil_dva_tree_fini(&zilog->zl_dva_tree); |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
274 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
275 |
return (max_seq); |
789 | 276 |
} |
277 |
||
278 |
/* ARGSUSED */ |
|
279 |
static void |
|
280 |
zil_claim_log_block(zilog_t *zilog, blkptr_t *bp, void *tx, uint64_t first_txg) |
|
281 |
{ |
|
282 |
spa_t *spa = zilog->zl_spa; |
|
283 |
int err; |
|
284 |
||
285 |
/* |
|
286 |
* Claim log block if not already committed and not already claimed. |
|
287 |
*/ |
|
288 |
if (bp->blk_birth >= first_txg && |
|
289 |
zil_dva_tree_add(&zilog->zl_dva_tree, BP_IDENTITY(bp)) == 0) { |
|
290 |
err = zio_wait(zio_claim(NULL, spa, first_txg, bp, NULL, NULL)); |
|
291 |
ASSERT(err == 0); |
|
292 |
} |
|
293 |
} |
|
294 |
||
295 |
static void |
|
296 |
zil_claim_log_record(zilog_t *zilog, lr_t *lrc, void *tx, uint64_t first_txg) |
|
297 |
{ |
|
298 |
if (lrc->lrc_txtype == TX_WRITE) { |
|
299 |
lr_write_t *lr = (lr_write_t *)lrc; |
|
300 |
zil_claim_log_block(zilog, &lr->lr_blkptr, tx, first_txg); |
|
301 |
} |
|
302 |
} |
|
303 |
||
304 |
/* ARGSUSED */ |
|
305 |
static void |
|
306 |
zil_free_log_block(zilog_t *zilog, blkptr_t *bp, void *tx, uint64_t claim_txg) |
|
307 |
{ |
|
308 |
zio_free_blk(zilog->zl_spa, bp, dmu_tx_get_txg(tx)); |
|
309 |
} |
|
310 |
||
311 |
static void |
|
312 |
zil_free_log_record(zilog_t *zilog, lr_t *lrc, void *tx, uint64_t claim_txg) |
|
313 |
{ |
|
314 |
/* |
|
315 |
* If we previously claimed it, we need to free it. |
|
316 |
*/ |
|
317 |
if (claim_txg != 0 && lrc->lrc_txtype == TX_WRITE) { |
|
318 |
lr_write_t *lr = (lr_write_t *)lrc; |
|
319 |
blkptr_t *bp = &lr->lr_blkptr; |
|
320 |
if (bp->blk_birth >= claim_txg && |
|
321 |
!zil_dva_tree_add(&zilog->zl_dva_tree, BP_IDENTITY(bp))) { |
|
322 |
(void) arc_free(NULL, zilog->zl_spa, |
|
323 |
dmu_tx_get_txg(tx), bp, NULL, NULL, ARC_WAIT); |
|
324 |
} |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
/* |
|
329 |
* Create an on-disk intent log. |
|
330 |
*/ |
|
331 |
static void |
|
332 |
zil_create(zilog_t *zilog) |
|
333 |
{ |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
334 |
const zil_header_t *zh = zilog->zl_header; |
789 | 335 |
lwb_t *lwb; |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
336 |
uint64_t txg = 0; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
337 |
dmu_tx_t *tx = NULL; |
789 | 338 |
blkptr_t blk; |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
339 |
int error = 0; |
789 | 340 |
|
341 |
/* |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
342 |
* Wait for any previous destroy to complete. |
789 | 343 |
*/ |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
344 |
txg_wait_synced(zilog->zl_dmu_pool, zilog->zl_destroy_txg); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
345 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
346 |
ASSERT(zh->zh_claim_txg == 0); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
347 |
ASSERT(zh->zh_replay_seq == 0); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
348 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
349 |
blk = zh->zh_log; |
789 | 350 |
|
351 |
/* |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
352 |
* If we don't already have an initial log block, allocate one now. |
789 | 353 |
*/ |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
354 |
if (BP_IS_HOLE(&blk)) { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
355 |
tx = dmu_tx_create(zilog->zl_os); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
356 |
(void) dmu_tx_assign(tx, TXG_WAIT); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
357 |
dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
358 |
txg = dmu_tx_get_txg(tx); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
359 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
360 |
error = zio_alloc_blk(zilog->zl_spa, ZIL_MIN_BLKSZ, &blk, |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
361 |
NULL, txg); |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
362 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
363 |
if (error == 0) |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
364 |
zil_init_log_chain(zilog, &blk); |
1362
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
365 |
} |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
366 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
367 |
/* |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
368 |
* Allocate a log write buffer (lwb) for the first log block. |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
369 |
*/ |
789 | 370 |
if (error == 0) { |
371 |
lwb = kmem_cache_alloc(zil_lwb_cache, KM_SLEEP); |
|
372 |
lwb->lwb_zilog = zilog; |
|
373 |
lwb->lwb_blk = blk; |
|
374 |
lwb->lwb_nused = 0; |
|
375 |
lwb->lwb_sz = BP_GET_LSIZE(&lwb->lwb_blk); |
|
376 |
lwb->lwb_buf = zio_buf_alloc(lwb->lwb_sz); |
|
377 |
lwb->lwb_max_txg = txg; |
|
2237 | 378 |
lwb->lwb_zio = NULL; |
379 |
||
789 | 380 |
mutex_enter(&zilog->zl_lock); |
381 |
list_insert_tail(&zilog->zl_lwb_list, lwb); |
|
382 |
mutex_exit(&zilog->zl_lock); |
|
383 |
} |
|
384 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
385 |
/* |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
386 |
* If we just allocated the first log block, commit our transaction |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
387 |
* and wait for zil_sync() to stuff the block poiner into zh_log. |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
388 |
* (zh is part of the MOS, so we cannot modify it in open context.) |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
389 |
*/ |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
390 |
if (tx != NULL) { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
391 |
dmu_tx_commit(tx); |
1362
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
392 |
txg_wait_synced(zilog->zl_dmu_pool, txg); |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
393 |
} |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
394 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
395 |
ASSERT(bcmp(&blk, &zh->zh_log, sizeof (blk)) == 0); |
789 | 396 |
} |
397 |
||
398 |
/* |
|
399 |
* In one tx, free all log blocks and clear the log header. |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
400 |
* If keep_first is set, then we're replaying a log with no content. |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
401 |
* We want to keep the first block, however, so that the first |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
402 |
* synchronous transaction doesn't require a txg_wait_synced() |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
403 |
* in zil_create(). We don't need to txg_wait_synced() here either |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
404 |
* when keep_first is set, because both zil_create() and zil_destroy() |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
405 |
* will wait for any in-progress destroys to complete. |
789 | 406 |
*/ |
407 |
void |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
408 |
zil_destroy(zilog_t *zilog, boolean_t keep_first) |
789 | 409 |
{ |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
410 |
const zil_header_t *zh = zilog->zl_header; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
411 |
lwb_t *lwb; |
789 | 412 |
dmu_tx_t *tx; |
413 |
uint64_t txg; |
|
414 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
415 |
/* |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
416 |
* Wait for any previous destroy to complete. |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
417 |
*/ |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
418 |
txg_wait_synced(zilog->zl_dmu_pool, zilog->zl_destroy_txg); |
789 | 419 |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
420 |
if (BP_IS_HOLE(&zh->zh_log)) |
789 | 421 |
return; |
422 |
||
423 |
tx = dmu_tx_create(zilog->zl_os); |
|
424 |
(void) dmu_tx_assign(tx, TXG_WAIT); |
|
425 |
dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx); |
|
426 |
txg = dmu_tx_get_txg(tx); |
|
427 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
428 |
mutex_enter(&zilog->zl_lock); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
429 |
|
5223
ca2e1fd5ee29
6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents:
4935
diff
changeset
|
430 |
/* |
ca2e1fd5ee29
6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents:
4935
diff
changeset
|
431 |
* It is possible for the ZIL to get the previously mounted zilog |
ca2e1fd5ee29
6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents:
4935
diff
changeset
|
432 |
* structure of the same dataset if quickly remounted and the dbuf |
ca2e1fd5ee29
6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents:
4935
diff
changeset
|
433 |
* eviction has not completed. In this case we can see a non |
ca2e1fd5ee29
6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents:
4935
diff
changeset
|
434 |
* empty lwb list and keep_first will be set. We fix this by |
ca2e1fd5ee29
6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents:
4935
diff
changeset
|
435 |
* clearing the keep_first. This will be slower but it's very rare. |
ca2e1fd5ee29
6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents:
4935
diff
changeset
|
436 |
*/ |
ca2e1fd5ee29
6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents:
4935
diff
changeset
|
437 |
if (!list_is_empty(&zilog->zl_lwb_list) && keep_first) |
ca2e1fd5ee29
6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents:
4935
diff
changeset
|
438 |
keep_first = B_FALSE; |
ca2e1fd5ee29
6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents:
4935
diff
changeset
|
439 |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
440 |
ASSERT3U(zilog->zl_destroy_txg, <, txg); |
789 | 441 |
zilog->zl_destroy_txg = txg; |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
442 |
zilog->zl_keep_first = keep_first; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
443 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
444 |
if (!list_is_empty(&zilog->zl_lwb_list)) { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
445 |
ASSERT(zh->zh_claim_txg == 0); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
446 |
ASSERT(!keep_first); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
447 |
while ((lwb = list_head(&zilog->zl_lwb_list)) != NULL) { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
448 |
list_remove(&zilog->zl_lwb_list, lwb); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
449 |
if (lwb->lwb_buf != NULL) |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
450 |
zio_buf_free(lwb->lwb_buf, lwb->lwb_sz); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
451 |
zio_free_blk(zilog->zl_spa, &lwb->lwb_blk, txg); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
452 |
kmem_cache_free(zil_lwb_cache, lwb); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
453 |
} |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
454 |
} else { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
455 |
if (!keep_first) { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
456 |
(void) zil_parse(zilog, zil_free_log_block, |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
457 |
zil_free_log_record, tx, zh->zh_claim_txg); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
458 |
} |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
459 |
} |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
460 |
mutex_exit(&zilog->zl_lock); |
789 | 461 |
|
462 |
dmu_tx_commit(tx); |
|
463 |
} |
|
464 |
||
4935
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
465 |
/* |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
466 |
* zil_rollback_destroy() is only called by the rollback code. |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
467 |
* We already have a syncing tx. Rollback has exclusive access to the |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
468 |
* dataset, so we don't have to worry about concurrent zil access. |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
469 |
* The actual freeing of any log blocks occurs in zil_sync() later in |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
470 |
* this txg syncing phase. |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
471 |
*/ |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
472 |
void |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
473 |
zil_rollback_destroy(zilog_t *zilog, dmu_tx_t *tx) |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
474 |
{ |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
475 |
const zil_header_t *zh = zilog->zl_header; |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
476 |
uint64_t txg; |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
477 |
|
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
478 |
if (BP_IS_HOLE(&zh->zh_log)) |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
479 |
return; |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
480 |
|
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
481 |
txg = dmu_tx_get_txg(tx); |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
482 |
ASSERT3U(zilog->zl_destroy_txg, <, txg); |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
483 |
zilog->zl_destroy_txg = txg; |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
484 |
zilog->zl_keep_first = B_FALSE; |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
485 |
|
5809
084c69fe7d0a
6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents:
5712
diff
changeset
|
486 |
/* |
084c69fe7d0a
6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents:
5712
diff
changeset
|
487 |
* Ensure there's no outstanding ZIL IO. No lwbs or just the |
084c69fe7d0a
6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents:
5712
diff
changeset
|
488 |
* unused one that allocated in advance is ok. |
084c69fe7d0a
6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents:
5712
diff
changeset
|
489 |
*/ |
084c69fe7d0a
6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents:
5712
diff
changeset
|
490 |
ASSERT(zilog->zl_lwb_list.list_head.list_next == |
084c69fe7d0a
6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents:
5712
diff
changeset
|
491 |
zilog->zl_lwb_list.list_head.list_prev); |
4935
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
492 |
(void) zil_parse(zilog, zil_free_log_block, zil_free_log_record, |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
493 |
tx, zh->zh_claim_txg); |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
494 |
} |
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4527
diff
changeset
|
495 |
|
2199 | 496 |
int |
789 | 497 |
zil_claim(char *osname, void *txarg) |
498 |
{ |
|
499 |
dmu_tx_t *tx = txarg; |
|
500 |
uint64_t first_txg = dmu_tx_get_txg(tx); |
|
501 |
zilog_t *zilog; |
|
502 |
zil_header_t *zh; |
|
503 |
objset_t *os; |
|
504 |
int error; |
|
505 |
||
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6101
diff
changeset
|
506 |
error = dmu_objset_open(osname, DMU_OST_ANY, DS_MODE_USER, &os); |
789 | 507 |
if (error) { |
508 |
cmn_err(CE_WARN, "can't process intent log for %s", osname); |
|
2199 | 509 |
return (0); |
789 | 510 |
} |
511 |
||
512 |
zilog = dmu_objset_zil(os); |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
513 |
zh = zil_header_in_syncing_context(zilog); |
789 | 514 |
|
515 |
/* |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
516 |
* Claim all log blocks if we haven't already done so, and remember |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
517 |
* the highest claimed sequence number. This ensures that if we can |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
518 |
* read only part of the log now (e.g. due to a missing device), |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
519 |
* but we can read the entire log later, we will not try to replay |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
520 |
* or destroy beyond the last block we successfully claimed. |
789 | 521 |
*/ |
522 |
ASSERT3U(zh->zh_claim_txg, <=, first_txg); |
|
523 |
if (zh->zh_claim_txg == 0 && !BP_IS_HOLE(&zh->zh_log)) { |
|
524 |
zh->zh_claim_txg = first_txg; |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
525 |
zh->zh_claim_seq = zil_parse(zilog, zil_claim_log_block, |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
526 |
zil_claim_log_record, tx, first_txg); |
789 | 527 |
dsl_dataset_dirty(dmu_objset_ds(os), tx); |
528 |
} |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
529 |
|
789 | 530 |
ASSERT3U(first_txg, ==, (spa_last_synced_txg(zilog->zl_spa) + 1)); |
531 |
dmu_objset_close(os); |
|
2199 | 532 |
return (0); |
789 | 533 |
} |
534 |
||
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
535 |
static int |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
536 |
zil_vdev_compare(const void *x1, const void *x2) |
789 | 537 |
{ |
5875
599b7007a9cd
6653210 zil_vdev_compare() compares pointers instead of vdev ids
perrin
parents:
5809
diff
changeset
|
538 |
uint64_t v1 = ((zil_vdev_node_t *)x1)->zv_vdev; |
599b7007a9cd
6653210 zil_vdev_compare() compares pointers instead of vdev ids
perrin
parents:
5809
diff
changeset
|
539 |
uint64_t v2 = ((zil_vdev_node_t *)x2)->zv_vdev; |
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
540 |
|
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
541 |
if (v1 < v2) |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
542 |
return (-1); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
543 |
if (v1 > v2) |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
544 |
return (1); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
545 |
|
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
546 |
return (0); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
547 |
} |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
548 |
|
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
549 |
void |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
550 |
zil_add_block(zilog_t *zilog, blkptr_t *bp) |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
551 |
{ |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
552 |
avl_tree_t *t = &zilog->zl_vdev_tree; |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
553 |
avl_index_t where; |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
554 |
zil_vdev_node_t *zv, zvsearch; |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
555 |
int ndvas = BP_GET_NDVAS(bp); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
556 |
int i; |
789 | 557 |
|
2986 | 558 |
if (zfs_nocacheflush) |
789 | 559 |
return; |
560 |
||
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
561 |
ASSERT(zilog->zl_writer); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
562 |
|
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
563 |
/* |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
564 |
* Even though we're zl_writer, we still need a lock because the |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
565 |
* zl_get_data() callbacks may have dmu_sync() done callbacks |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
566 |
* that will run concurrently. |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
567 |
*/ |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
568 |
mutex_enter(&zilog->zl_vdev_lock); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
569 |
for (i = 0; i < ndvas; i++) { |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
570 |
zvsearch.zv_vdev = DVA_GET_VDEV(&bp->blk_dva[i]); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
571 |
if (avl_find(t, &zvsearch, &where) == NULL) { |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
572 |
zv = kmem_alloc(sizeof (*zv), KM_SLEEP); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
573 |
zv->zv_vdev = zvsearch.zv_vdev; |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
574 |
avl_insert(t, zv, where); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
575 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
576 |
} |
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
577 |
mutex_exit(&zilog->zl_vdev_lock); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
578 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
579 |
|
789 | 580 |
void |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
581 |
zil_flush_vdevs(zilog_t *zilog) |
789 | 582 |
{ |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
583 |
spa_t *spa = zilog->zl_spa; |
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
584 |
avl_tree_t *t = &zilog->zl_vdev_tree; |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
585 |
void *cookie = NULL; |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
586 |
zil_vdev_node_t *zv; |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
587 |
zio_t *zio; |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
588 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
589 |
ASSERT(zilog->zl_writer); |
789 | 590 |
|
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
591 |
/* |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
592 |
* We don't need zl_vdev_lock here because we're the zl_writer, |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
593 |
* and all zl_get_data() callbacks are done. |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
594 |
*/ |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
595 |
if (avl_numnodes(t) == 0) |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
596 |
return; |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
597 |
|
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
598 |
spa_config_enter(spa, RW_READER, FTAG); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
599 |
|
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
600 |
zio = zio_root(spa, NULL, NULL, |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
601 |
ZIO_FLAG_CONFIG_HELD | ZIO_FLAG_CANFAIL); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
602 |
|
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
603 |
while ((zv = avl_destroy_nodes(t, &cookie)) != NULL) { |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
604 |
vdev_t *vd = vdev_lookup_top(spa, zv->zv_vdev); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
605 |
if (vd != NULL) |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
606 |
zio_flush(zio, vd); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
607 |
kmem_free(zv, sizeof (*zv)); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
608 |
} |
789 | 609 |
|
610 |
/* |
|
611 |
* Wait for all the flushes to complete. Not all devices actually |
|
612 |
* support the DKIOCFLUSHWRITECACHE ioctl, so it's OK if it fails. |
|
613 |
*/ |
|
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
614 |
(void) zio_wait(zio); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
615 |
|
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
616 |
spa_config_exit(spa, FTAG); |
789 | 617 |
} |
618 |
||
619 |
/* |
|
620 |
* Function called when a log block write completes |
|
621 |
*/ |
|
622 |
static void |
|
623 |
zil_lwb_write_done(zio_t *zio) |
|
624 |
{ |
|
625 |
lwb_t *lwb = zio->io_private; |
|
626 |
zilog_t *zilog = lwb->lwb_zilog; |
|
627 |
||
628 |
/* |
|
629 |
* Now that we've written this log block, we have a stable pointer |
|
630 |
* to the next block in the chain, so it's OK to let the txg in |
|
631 |
* which we allocated the next block sync. |
|
632 |
*/ |
|
633 |
txg_rele_to_sync(&lwb->lwb_txgh); |
|
634 |
||
635 |
zio_buf_free(lwb->lwb_buf, lwb->lwb_sz); |
|
636 |
mutex_enter(&zilog->zl_lock); |
|
637 |
lwb->lwb_buf = NULL; |
|
4527 | 638 |
if (zio->io_error) |
789 | 639 |
zilog->zl_log_error = B_TRUE; |
640 |
mutex_exit(&zilog->zl_lock); |
|
641 |
} |
|
642 |
||
643 |
/* |
|
2237 | 644 |
* Initialize the io for a log block. |
645 |
* |
|
646 |
* Note, we should not initialize the IO until we are about |
|
647 |
* to use it, since zio_rewrite() does a spa_config_enter(). |
|
648 |
*/ |
|
649 |
static void |
|
650 |
zil_lwb_write_init(zilog_t *zilog, lwb_t *lwb) |
|
651 |
{ |
|
652 |
zbookmark_t zb; |
|
653 |
||
654 |
zb.zb_objset = lwb->lwb_blk.blk_cksum.zc_word[ZIL_ZC_OBJSET]; |
|
655 |
zb.zb_object = 0; |
|
656 |
zb.zb_level = -1; |
|
657 |
zb.zb_blkid = lwb->lwb_blk.blk_cksum.zc_word[ZIL_ZC_SEQ]; |
|
658 |
||
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
659 |
if (zilog->zl_root_zio == NULL) { |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
660 |
zilog->zl_root_zio = zio_root(zilog->zl_spa, NULL, NULL, |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
661 |
ZIO_FLAG_CANFAIL); |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
662 |
} |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
663 |
if (lwb->lwb_zio == NULL) { |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
664 |
lwb->lwb_zio = zio_rewrite(zilog->zl_root_zio, zilog->zl_spa, |
7181
8d299641aa23
6719934 assertion failed: ((&zh->zh_log)->blk_birth == 0), file: ../../common/fs/zfs/zil.c, line: 1336
perrin
parents:
7046
diff
changeset
|
665 |
ZIO_CHECKSUM_ZILOG, 0, &lwb->lwb_blk, lwb->lwb_buf, |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
666 |
lwb->lwb_sz, zil_lwb_write_done, lwb, |
4527 | 667 |
ZIO_PRIORITY_LOG_WRITE, ZIO_FLAG_CANFAIL, &zb); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
668 |
} |
2237 | 669 |
} |
670 |
||
671 |
/* |
|
789 | 672 |
* Start a log block write and advance to the next log block. |
673 |
* Calls are serialized. |
|
674 |
*/ |
|
675 |
static lwb_t * |
|
676 |
zil_lwb_write_start(zilog_t *zilog, lwb_t *lwb) |
|
677 |
{ |
|
678 |
lwb_t *nlwb; |
|
679 |
zil_trailer_t *ztp = (zil_trailer_t *)(lwb->lwb_buf + lwb->lwb_sz) - 1; |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
680 |
spa_t *spa = zilog->zl_spa; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
681 |
blkptr_t *bp = &ztp->zit_next_blk; |
789 | 682 |
uint64_t txg; |
683 |
uint64_t zil_blksz; |
|
684 |
int error; |
|
685 |
||
686 |
ASSERT(lwb->lwb_nused <= ZIL_BLK_DATA_SZ(lwb)); |
|
687 |
||
688 |
/* |
|
689 |
* Allocate the next block and save its address in this block |
|
690 |
* before writing it in order to establish the log chain. |
|
691 |
* Note that if the allocation of nlwb synced before we wrote |
|
692 |
* the block that points at it (lwb), we'd leak it if we crashed. |
|
693 |
* Therefore, we don't do txg_rele_to_sync() until zil_lwb_write_done(). |
|
694 |
*/ |
|
695 |
txg = txg_hold_open(zilog->zl_dmu_pool, &lwb->lwb_txgh); |
|
696 |
txg_rele_to_quiesce(&lwb->lwb_txgh); |
|
697 |
||
698 |
/* |
|
1141 | 699 |
* Pick a ZIL blocksize. We request a size that is the |
700 |
* maximum of the previous used size, the current used size and |
|
701 |
* the amount waiting in the queue. |
|
789 | 702 |
*/ |
2237 | 703 |
zil_blksz = MAX(zilog->zl_prev_used, |
704 |
zilog->zl_cur_used + sizeof (*ztp)); |
|
1141 | 705 |
zil_blksz = MAX(zil_blksz, zilog->zl_itx_list_sz + sizeof (*ztp)); |
1842
1712a484fc9d
6413731 pathologically slower fsync on 32 bit systems
perrin
parents:
1807
diff
changeset
|
706 |
zil_blksz = P2ROUNDUP_TYPED(zil_blksz, ZIL_MIN_BLKSZ, uint64_t); |
1141 | 707 |
if (zil_blksz > ZIL_MAX_BLKSZ) |
708 |
zil_blksz = ZIL_MAX_BLKSZ; |
|
789 | 709 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
710 |
BP_ZERO(bp); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
711 |
/* pass the old blkptr in order to spread log blocks across devs */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
712 |
error = zio_alloc_blk(spa, zil_blksz, bp, &lwb->lwb_blk, txg); |
789 | 713 |
if (error) { |
3668 | 714 |
dmu_tx_t *tx = dmu_tx_create_assigned(zilog->zl_dmu_pool, txg); |
715 |
||
1544 | 716 |
/* |
3668 | 717 |
* We dirty the dataset to ensure that zil_sync() will |
718 |
* be called to remove this lwb from our zl_lwb_list. |
|
719 |
* Failing to do so, may leave an lwb with a NULL lwb_buf |
|
720 |
* hanging around on the zl_lwb_list. |
|
721 |
*/ |
|
722 |
dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx); |
|
3848
abf146257cf9
6495013 Loops and recursion in metaslab_ff_alloc can kill performance, even on a pool with lots of free data
gw25295
parents:
3778
diff
changeset
|
723 |
dmu_tx_commit(tx); |
3668 | 724 |
|
725 |
/* |
|
726 |
* Since we've just experienced an allocation failure so we |
|
727 |
* terminate the current lwb and send it on its way. |
|
728 |
*/ |
|
729 |
ztp->zit_pad = 0; |
|
730 |
ztp->zit_nused = lwb->lwb_nused; |
|
731 |
ztp->zit_bt.zbt_cksum = lwb->lwb_blk.blk_cksum; |
|
732 |
zio_nowait(lwb->lwb_zio); |
|
733 |
||
734 |
/* |
|
1544 | 735 |
* By returning NULL the caller will call tx_wait_synced() |
736 |
*/ |
|
789 | 737 |
return (NULL); |
738 |
} |
|
739 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
740 |
ASSERT3U(bp->blk_birth, ==, txg); |
1544 | 741 |
ztp->zit_pad = 0; |
789 | 742 |
ztp->zit_nused = lwb->lwb_nused; |
743 |
ztp->zit_bt.zbt_cksum = lwb->lwb_blk.blk_cksum; |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
744 |
bp->blk_cksum = lwb->lwb_blk.blk_cksum; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
745 |
bp->blk_cksum.zc_word[ZIL_ZC_SEQ]++; |
789 | 746 |
|
747 |
/* |
|
748 |
* Allocate a new log write buffer (lwb). |
|
749 |
*/ |
|
750 |
nlwb = kmem_cache_alloc(zil_lwb_cache, KM_SLEEP); |
|
751 |
||
752 |
nlwb->lwb_zilog = zilog; |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
753 |
nlwb->lwb_blk = *bp; |
789 | 754 |
nlwb->lwb_nused = 0; |
755 |
nlwb->lwb_sz = BP_GET_LSIZE(&nlwb->lwb_blk); |
|
756 |
nlwb->lwb_buf = zio_buf_alloc(nlwb->lwb_sz); |
|
757 |
nlwb->lwb_max_txg = txg; |
|
2237 | 758 |
nlwb->lwb_zio = NULL; |
789 | 759 |
|
760 |
/* |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
761 |
* Put new lwb at the end of the log chain |
789 | 762 |
*/ |
763 |
mutex_enter(&zilog->zl_lock); |
|
764 |
list_insert_tail(&zilog->zl_lwb_list, nlwb); |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
765 |
mutex_exit(&zilog->zl_lock); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
766 |
|
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
767 |
/* Record the block for later vdev flushing */ |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
768 |
zil_add_block(zilog, &lwb->lwb_blk); |
789 | 769 |
|
770 |
/* |
|
2237 | 771 |
* kick off the write for the old log block |
789 | 772 |
*/ |
2237 | 773 |
dprintf_bp(&lwb->lwb_blk, "lwb %p txg %llu: ", lwb, txg); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
774 |
ASSERT(lwb->lwb_zio); |
2237 | 775 |
zio_nowait(lwb->lwb_zio); |
789 | 776 |
|
777 |
return (nlwb); |
|
778 |
} |
|
779 |
||
780 |
static lwb_t * |
|
781 |
zil_lwb_commit(zilog_t *zilog, itx_t *itx, lwb_t *lwb) |
|
782 |
{ |
|
783 |
lr_t *lrc = &itx->itx_lr; /* common log record */ |
|
2237 | 784 |
lr_write_t *lr = (lr_write_t *)lrc; |
789 | 785 |
uint64_t txg = lrc->lrc_txg; |
786 |
uint64_t reclen = lrc->lrc_reclen; |
|
2237 | 787 |
uint64_t dlen; |
789 | 788 |
|
789 |
if (lwb == NULL) |
|
790 |
return (NULL); |
|
791 |
ASSERT(lwb->lwb_buf != NULL); |
|
792 |
||
2237 | 793 |
if (lrc->lrc_txtype == TX_WRITE && itx->itx_wr_state == WR_NEED_COPY) |
794 |
dlen = P2ROUNDUP_TYPED( |
|
795 |
lr->lr_length, sizeof (uint64_t), uint64_t); |
|
796 |
else |
|
797 |
dlen = 0; |
|
1669 | 798 |
|
799 |
zilog->zl_cur_used += (reclen + dlen); |
|
800 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
801 |
zil_lwb_write_init(zilog, lwb); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
802 |
|
1669 | 803 |
/* |
804 |
* If this record won't fit in the current log block, start a new one. |
|
805 |
*/ |
|
806 |
if (lwb->lwb_nused + reclen + dlen > ZIL_BLK_DATA_SZ(lwb)) { |
|
807 |
lwb = zil_lwb_write_start(zilog, lwb); |
|
2237 | 808 |
if (lwb == NULL) |
1669 | 809 |
return (NULL); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
810 |
zil_lwb_write_init(zilog, lwb); |
1669 | 811 |
ASSERT(lwb->lwb_nused == 0); |
812 |
if (reclen + dlen > ZIL_BLK_DATA_SZ(lwb)) { |
|
813 |
txg_wait_synced(zilog->zl_dmu_pool, txg); |
|
789 | 814 |
return (lwb); |
815 |
} |
|
816 |
} |
|
817 |
||
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
818 |
/* |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
819 |
* Update the lrc_seq, to be log record sequence number. See zil.h |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
820 |
* Then copy the record to the log buffer. |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
821 |
*/ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
822 |
lrc->lrc_seq = ++zilog->zl_lr_seq; /* we are single threaded */ |
789 | 823 |
bcopy(lrc, lwb->lwb_buf + lwb->lwb_nused, reclen); |
2237 | 824 |
|
825 |
/* |
|
826 |
* If it's a write, fetch the data or get its blkptr as appropriate. |
|
827 |
*/ |
|
828 |
if (lrc->lrc_txtype == TX_WRITE) { |
|
829 |
if (txg > spa_freeze_txg(zilog->zl_spa)) |
|
830 |
txg_wait_synced(zilog->zl_dmu_pool, txg); |
|
831 |
if (itx->itx_wr_state != WR_COPIED) { |
|
832 |
char *dbuf; |
|
833 |
int error; |
|
834 |
||
835 |
/* alignment is guaranteed */ |
|
836 |
lr = (lr_write_t *)(lwb->lwb_buf + lwb->lwb_nused); |
|
837 |
if (dlen) { |
|
838 |
ASSERT(itx->itx_wr_state == WR_NEED_COPY); |
|
839 |
dbuf = lwb->lwb_buf + lwb->lwb_nused + reclen; |
|
840 |
lr->lr_common.lrc_reclen += dlen; |
|
841 |
} else { |
|
842 |
ASSERT(itx->itx_wr_state == WR_INDIRECT); |
|
843 |
dbuf = NULL; |
|
844 |
} |
|
845 |
error = zilog->zl_get_data( |
|
846 |
itx->itx_private, lr, dbuf, lwb->lwb_zio); |
|
847 |
if (error) { |
|
848 |
ASSERT(error == ENOENT || error == EEXIST || |
|
849 |
error == EALREADY); |
|
850 |
return (lwb); |
|
851 |
} |
|
852 |
} |
|
1669 | 853 |
} |
2237 | 854 |
|
855 |
lwb->lwb_nused += reclen + dlen; |
|
789 | 856 |
lwb->lwb_max_txg = MAX(lwb->lwb_max_txg, txg); |
857 |
ASSERT3U(lwb->lwb_nused, <=, ZIL_BLK_DATA_SZ(lwb)); |
|
858 |
ASSERT3U(P2PHASE(lwb->lwb_nused, sizeof (uint64_t)), ==, 0); |
|
859 |
||
860 |
return (lwb); |
|
861 |
} |
|
862 |
||
863 |
itx_t * |
|
5331 | 864 |
zil_itx_create(uint64_t txtype, size_t lrsize) |
789 | 865 |
{ |
866 |
itx_t *itx; |
|
867 |
||
1842
1712a484fc9d
6413731 pathologically slower fsync on 32 bit systems
perrin
parents:
1807
diff
changeset
|
868 |
lrsize = P2ROUNDUP_TYPED(lrsize, sizeof (uint64_t), size_t); |
789 | 869 |
|
870 |
itx = kmem_alloc(offsetof(itx_t, itx_lr) + lrsize, KM_SLEEP); |
|
871 |
itx->itx_lr.lrc_txtype = txtype; |
|
872 |
itx->itx_lr.lrc_reclen = lrsize; |
|
6101
915df4cedbc9
6658511 zl_itx_list_sz incorrect for WR_NEED_COPY writes
perrin
parents:
5913
diff
changeset
|
873 |
itx->itx_sod = lrsize; /* if write & WR_NEED_COPY will be increased */ |
789 | 874 |
itx->itx_lr.lrc_seq = 0; /* defensive */ |
875 |
||
876 |
return (itx); |
|
877 |
} |
|
878 |
||
879 |
uint64_t |
|
880 |
zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx) |
|
881 |
{ |
|
882 |
uint64_t seq; |
|
883 |
||
884 |
ASSERT(itx->itx_lr.lrc_seq == 0); |
|
885 |
||
886 |
mutex_enter(&zilog->zl_lock); |
|
887 |
list_insert_tail(&zilog->zl_itx_list, itx); |
|
6101
915df4cedbc9
6658511 zl_itx_list_sz incorrect for WR_NEED_COPY writes
perrin
parents:
5913
diff
changeset
|
888 |
zilog->zl_itx_list_sz += itx->itx_sod; |
789 | 889 |
itx->itx_lr.lrc_txg = dmu_tx_get_txg(tx); |
890 |
itx->itx_lr.lrc_seq = seq = ++zilog->zl_itx_seq; |
|
891 |
mutex_exit(&zilog->zl_lock); |
|
892 |
||
893 |
return (seq); |
|
894 |
} |
|
895 |
||
896 |
/* |
|
897 |
* Free up all in-memory intent log transactions that have now been synced. |
|
898 |
*/ |
|
899 |
static void |
|
900 |
zil_itx_clean(zilog_t *zilog) |
|
901 |
{ |
|
902 |
uint64_t synced_txg = spa_last_synced_txg(zilog->zl_spa); |
|
903 |
uint64_t freeze_txg = spa_freeze_txg(zilog->zl_spa); |
|
3778 | 904 |
list_t clean_list; |
789 | 905 |
itx_t *itx; |
906 |
||
3778 | 907 |
list_create(&clean_list, sizeof (itx_t), offsetof(itx_t, itx_node)); |
908 |
||
789 | 909 |
mutex_enter(&zilog->zl_lock); |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
910 |
/* wait for a log writer to finish walking list */ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
911 |
while (zilog->zl_writer) { |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
912 |
cv_wait(&zilog->zl_cv_writer, &zilog->zl_lock); |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
913 |
} |
3778 | 914 |
|
915 |
/* |
|
916 |
* Move the sync'd log transactions to a separate list so we can call |
|
917 |
* kmem_free without holding the zl_lock. |
|
918 |
* |
|
919 |
* There is no need to set zl_writer as we don't drop zl_lock here |
|
920 |
*/ |
|
789 | 921 |
while ((itx = list_head(&zilog->zl_itx_list)) != NULL && |
922 |
itx->itx_lr.lrc_txg <= MIN(synced_txg, freeze_txg)) { |
|
923 |
list_remove(&zilog->zl_itx_list, itx); |
|
6101
915df4cedbc9
6658511 zl_itx_list_sz incorrect for WR_NEED_COPY writes
perrin
parents:
5913
diff
changeset
|
924 |
zilog->zl_itx_list_sz -= itx->itx_sod; |
3778 | 925 |
list_insert_tail(&clean_list, itx); |
926 |
} |
|
927 |
cv_broadcast(&zilog->zl_cv_writer); |
|
928 |
mutex_exit(&zilog->zl_lock); |
|
929 |
||
930 |
/* destroy sync'd log transactions */ |
|
931 |
while ((itx = list_head(&clean_list)) != NULL) { |
|
932 |
list_remove(&clean_list, itx); |
|
789 | 933 |
kmem_free(itx, offsetof(itx_t, itx_lr) |
934 |
+ itx->itx_lr.lrc_reclen); |
|
935 |
} |
|
3778 | 936 |
list_destroy(&clean_list); |
789 | 937 |
} |
938 |
||
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
939 |
/* |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
940 |
* If there are any in-memory intent log transactions which have now been |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
941 |
* synced then start up a taskq to free them. |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
942 |
*/ |
789 | 943 |
void |
944 |
zil_clean(zilog_t *zilog) |
|
945 |
{ |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
946 |
itx_t *itx; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
947 |
|
789 | 948 |
mutex_enter(&zilog->zl_lock); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
949 |
itx = list_head(&zilog->zl_itx_list); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
950 |
if ((itx != NULL) && |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
951 |
(itx->itx_lr.lrc_txg <= spa_last_synced_txg(zilog->zl_spa))) { |
789 | 952 |
(void) taskq_dispatch(zilog->zl_clean_taskq, |
953 |
(void (*)(void *))zil_itx_clean, zilog, TQ_NOSLEEP); |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
954 |
} |
789 | 955 |
mutex_exit(&zilog->zl_lock); |
956 |
} |
|
957 |
||
958 |
void |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
959 |
zil_commit_writer(zilog_t *zilog, uint64_t seq, uint64_t foid) |
789 | 960 |
{ |
961 |
uint64_t txg; |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
962 |
uint64_t commit_seq = 0; |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
963 |
itx_t *itx, *itx_next = (itx_t *)-1; |
789 | 964 |
lwb_t *lwb; |
965 |
spa_t *spa; |
|
966 |
||
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
967 |
zilog->zl_writer = B_TRUE; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
968 |
zilog->zl_root_zio = NULL; |
789 | 969 |
spa = zilog->zl_spa; |
970 |
||
971 |
if (zilog->zl_suspend) { |
|
972 |
lwb = NULL; |
|
973 |
} else { |
|
974 |
lwb = list_tail(&zilog->zl_lwb_list); |
|
975 |
if (lwb == NULL) { |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
976 |
/* |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
977 |
* Return if there's nothing to flush before we |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
978 |
* dirty the fs by calling zil_create() |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
979 |
*/ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
980 |
if (list_is_empty(&zilog->zl_itx_list)) { |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
981 |
zilog->zl_writer = B_FALSE; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
982 |
return; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
983 |
} |
789 | 984 |
mutex_exit(&zilog->zl_lock); |
985 |
zil_create(zilog); |
|
986 |
mutex_enter(&zilog->zl_lock); |
|
987 |
lwb = list_tail(&zilog->zl_lwb_list); |
|
988 |
} |
|
989 |
} |
|
990 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
991 |
/* Loop through in-memory log transactions filling log blocks. */ |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
992 |
DTRACE_PROBE1(zil__cw1, zilog_t *, zilog); |
789 | 993 |
for (;;) { |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
994 |
/* |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
995 |
* Find the next itx to push: |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
996 |
* Push all transactions related to specified foid and all |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
997 |
* other transactions except TX_WRITE, TX_TRUNCATE, |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
998 |
* TX_SETATTR and TX_ACL for all other files. |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
999 |
*/ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1000 |
if (itx_next != (itx_t *)-1) |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1001 |
itx = itx_next; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1002 |
else |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1003 |
itx = list_head(&zilog->zl_itx_list); |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1004 |
for (; itx != NULL; itx = list_next(&zilog->zl_itx_list, itx)) { |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1005 |
if (foid == 0) /* push all foids? */ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1006 |
break; |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1007 |
if (itx->itx_sync) /* push all O_[D]SYNC */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1008 |
break; |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1009 |
switch (itx->itx_lr.lrc_txtype) { |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1010 |
case TX_SETATTR: |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1011 |
case TX_WRITE: |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1012 |
case TX_TRUNCATE: |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1013 |
case TX_ACL: |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1014 |
/* lr_foid is same offset for these records */ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1015 |
if (((lr_write_t *)&itx->itx_lr)->lr_foid |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1016 |
!= foid) { |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1017 |
continue; /* skip this record */ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1018 |
} |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1019 |
} |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1020 |
break; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1021 |
} |
789 | 1022 |
if (itx == NULL) |
1023 |
break; |
|
1024 |
||
1025 |
if ((itx->itx_lr.lrc_seq > seq) && |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1026 |
((lwb == NULL) || (lwb->lwb_nused == 0) || |
6101
915df4cedbc9
6658511 zl_itx_list_sz incorrect for WR_NEED_COPY writes
perrin
parents:
5913
diff
changeset
|
1027 |
(lwb->lwb_nused + itx->itx_sod > ZIL_BLK_DATA_SZ(lwb)))) { |
789 | 1028 |
break; |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1029 |
} |
789 | 1030 |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1031 |
/* |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1032 |
* Save the next pointer. Even though we soon drop |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1033 |
* zl_lock all threads that may change the list |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1034 |
* (another writer or zil_itx_clean) can't do so until |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1035 |
* they have zl_writer. |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1036 |
*/ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1037 |
itx_next = list_next(&zilog->zl_itx_list, itx); |
789 | 1038 |
list_remove(&zilog->zl_itx_list, itx); |
6101
915df4cedbc9
6658511 zl_itx_list_sz incorrect for WR_NEED_COPY writes
perrin
parents:
5913
diff
changeset
|
1039 |
zilog->zl_itx_list_sz -= itx->itx_sod; |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1040 |
mutex_exit(&zilog->zl_lock); |
789 | 1041 |
txg = itx->itx_lr.lrc_txg; |
1042 |
ASSERT(txg); |
|
1043 |
||
1044 |
if (txg > spa_last_synced_txg(spa) || |
|
1045 |
txg > spa_freeze_txg(spa)) |
|
1046 |
lwb = zil_lwb_commit(zilog, itx, lwb); |
|
1047 |
kmem_free(itx, offsetof(itx_t, itx_lr) |
|
1048 |
+ itx->itx_lr.lrc_reclen); |
|
1049 |
mutex_enter(&zilog->zl_lock); |
|
1050 |
} |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1051 |
DTRACE_PROBE1(zil__cw2, zilog_t *, zilog); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1052 |
/* determine commit sequence number */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1053 |
itx = list_head(&zilog->zl_itx_list); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1054 |
if (itx) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1055 |
commit_seq = itx->itx_lr.lrc_seq; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1056 |
else |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1057 |
commit_seq = zilog->zl_itx_seq; |
789 | 1058 |
mutex_exit(&zilog->zl_lock); |
1059 |
||
1060 |
/* write the last block out */ |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1061 |
if (lwb != NULL && lwb->lwb_zio != NULL) |
789 | 1062 |
lwb = zil_lwb_write_start(zilog, lwb); |
1063 |
||
1141 | 1064 |
zilog->zl_prev_used = zilog->zl_cur_used; |
1065 |
zilog->zl_cur_used = 0; |
|
1066 |
||
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1067 |
/* |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1068 |
* Wait if necessary for the log blocks to be on stable storage. |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1069 |
*/ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1070 |
if (zilog->zl_root_zio) { |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1071 |
DTRACE_PROBE1(zil__cw3, zilog_t *, zilog); |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1072 |
(void) zio_wait(zilog->zl_root_zio); |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1073 |
DTRACE_PROBE1(zil__cw4, zilog_t *, zilog); |
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
1074 |
zil_flush_vdevs(zilog); |
789 | 1075 |
} |
1141 | 1076 |
|
789 | 1077 |
if (zilog->zl_log_error || lwb == NULL) { |
1078 |
zilog->zl_log_error = 0; |
|
1079 |
txg_wait_synced(zilog->zl_dmu_pool, 0); |
|
1080 |
} |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1081 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1082 |
mutex_enter(&zilog->zl_lock); |
1141 | 1083 |
zilog->zl_writer = B_FALSE; |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1084 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1085 |
ASSERT3U(commit_seq, >=, zilog->zl_commit_seq); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1086 |
zilog->zl_commit_seq = commit_seq; |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1087 |
} |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1088 |
|
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1089 |
/* |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1090 |
* Push zfs transactions to stable storage up to the supplied sequence number. |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1091 |
* If foid is 0 push out all transactions, otherwise push only those |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1092 |
* for that file or might have been used to create that file. |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1093 |
*/ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1094 |
void |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1095 |
zil_commit(zilog_t *zilog, uint64_t seq, uint64_t foid) |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1096 |
{ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1097 |
if (zilog == NULL || seq == 0) |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1098 |
return; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1099 |
|
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1100 |
mutex_enter(&zilog->zl_lock); |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1101 |
|
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1102 |
seq = MIN(seq, zilog->zl_itx_seq); /* cap seq at largest itx seq */ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1103 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1104 |
while (zilog->zl_writer) { |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1105 |
cv_wait(&zilog->zl_cv_writer, &zilog->zl_lock); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1106 |
if (seq < zilog->zl_commit_seq) { |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1107 |
mutex_exit(&zilog->zl_lock); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1108 |
return; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1109 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1110 |
} |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1111 |
zil_commit_writer(zilog, seq, foid); /* drops zl_lock */ |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1112 |
/* wake up others waiting on the commit */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1113 |
cv_broadcast(&zilog->zl_cv_writer); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1114 |
mutex_exit(&zilog->zl_lock); |
789 | 1115 |
} |
1116 |
||
1117 |
/* |
|
1118 |
* Called in syncing context to free committed log blocks and update log header. |
|
1119 |
*/ |
|
1120 |
void |
|
1121 |
zil_sync(zilog_t *zilog, dmu_tx_t *tx) |
|
1122 |
{ |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1123 |
zil_header_t *zh = zil_header_in_syncing_context(zilog); |
789 | 1124 |
uint64_t txg = dmu_tx_get_txg(tx); |
1125 |
spa_t *spa = zilog->zl_spa; |
|
1126 |
lwb_t *lwb; |
|
1127 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1128 |
mutex_enter(&zilog->zl_lock); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1129 |
|
789 | 1130 |
ASSERT(zilog->zl_stop_sync == 0); |
1131 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1132 |
zh->zh_replay_seq = zilog->zl_replay_seq[txg & TXG_MASK]; |
789 | 1133 |
|
1134 |
if (zilog->zl_destroy_txg == txg) { |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1135 |
blkptr_t blk = zh->zh_log; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1136 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1137 |
ASSERT(list_head(&zilog->zl_lwb_list) == NULL); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1138 |
ASSERT(spa_sync_pass(spa) == 1); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1139 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1140 |
bzero(zh, sizeof (zil_header_t)); |
789 | 1141 |
bzero(zilog->zl_replay_seq, sizeof (zilog->zl_replay_seq)); |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1142 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1143 |
if (zilog->zl_keep_first) { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1144 |
/* |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1145 |
* If this block was part of log chain that couldn't |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1146 |
* be claimed because a device was missing during |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1147 |
* zil_claim(), but that device later returns, |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1148 |
* then this block could erroneously appear valid. |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1149 |
* To guard against this, assign a new GUID to the new |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1150 |
* log chain so it doesn't matter what blk points to. |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1151 |
*/ |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1152 |
zil_init_log_chain(zilog, &blk); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1153 |
zh->zh_log = blk; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1154 |
} |
789 | 1155 |
} |
1156 |
||
1157 |
for (;;) { |
|
1158 |
lwb = list_head(&zilog->zl_lwb_list); |
|
1159 |
if (lwb == NULL) { |
|
1160 |
mutex_exit(&zilog->zl_lock); |
|
1161 |
return; |
|
1162 |
} |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1163 |
zh->zh_log = lwb->lwb_blk; |
789 | 1164 |
if (lwb->lwb_buf != NULL || lwb->lwb_max_txg > txg) |
1165 |
break; |
|
1166 |
list_remove(&zilog->zl_lwb_list, lwb); |
|
1167 |
zio_free_blk(spa, &lwb->lwb_blk, txg); |
|
1168 |
kmem_cache_free(zil_lwb_cache, lwb); |
|
3668 | 1169 |
|
1170 |
/* |
|
1171 |
* If we don't have anything left in the lwb list then |
|
1172 |
* we've had an allocation failure and we need to zero |
|
1173 |
* out the zil_header blkptr so that we don't end |
|
1174 |
* up freeing the same block twice. |
|
1175 |
*/ |
|
1176 |
if (list_head(&zilog->zl_lwb_list) == NULL) |
|
1177 |
BP_ZERO(&zh->zh_log); |
|
789 | 1178 |
} |
1179 |
mutex_exit(&zilog->zl_lock); |
|
1180 |
} |
|
1181 |
||
1182 |
void |
|
1183 |
zil_init(void) |
|
1184 |
{ |
|
1185 |
zil_lwb_cache = kmem_cache_create("zil_lwb_cache", |
|
2856 | 1186 |
sizeof (struct lwb), 0, NULL, NULL, NULL, NULL, NULL, 0); |
789 | 1187 |
} |
1188 |
||
1189 |
void |
|
1190 |
zil_fini(void) |
|
1191 |
{ |
|
1192 |
kmem_cache_destroy(zil_lwb_cache); |
|
1193 |
} |
|
1194 |
||
1195 |
zilog_t * |
|
1196 |
zil_alloc(objset_t *os, zil_header_t *zh_phys) |
|
1197 |
{ |
|
1198 |
zilog_t *zilog; |
|
1199 |
||
1200 |
zilog = kmem_zalloc(sizeof (zilog_t), KM_SLEEP); |
|
1201 |
||
1202 |
zilog->zl_header = zh_phys; |
|
1203 |
zilog->zl_os = os; |
|
1204 |
zilog->zl_spa = dmu_objset_spa(os); |
|
1205 |
zilog->zl_dmu_pool = dmu_objset_pool(os); |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1206 |
zilog->zl_destroy_txg = TXG_INITIAL - 1; |
789 | 1207 |
|
2856 | 1208 |
mutex_init(&zilog->zl_lock, NULL, MUTEX_DEFAULT, NULL); |
1209 |
||
789 | 1210 |
list_create(&zilog->zl_itx_list, sizeof (itx_t), |
1211 |
offsetof(itx_t, itx_node)); |
|
1212 |
||
1213 |
list_create(&zilog->zl_lwb_list, sizeof (lwb_t), |
|
1214 |
offsetof(lwb_t, lwb_node)); |
|
1215 |
||
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
1216 |
mutex_init(&zilog->zl_vdev_lock, NULL, MUTEX_DEFAULT, NULL); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
1217 |
|
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
1218 |
avl_create(&zilog->zl_vdev_tree, zil_vdev_compare, |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
1219 |
sizeof (zil_vdev_node_t), offsetof(zil_vdev_node_t, zv_node)); |
789 | 1220 |
|
5913
a77f8ad2ce63
6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents:
5886
diff
changeset
|
1221 |
cv_init(&zilog->zl_cv_writer, NULL, CV_DEFAULT, NULL); |
a77f8ad2ce63
6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents:
5886
diff
changeset
|
1222 |
cv_init(&zilog->zl_cv_suspend, NULL, CV_DEFAULT, NULL); |
a77f8ad2ce63
6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents:
5886
diff
changeset
|
1223 |
|
789 | 1224 |
return (zilog); |
1225 |
} |
|
1226 |
||
1227 |
void |
|
1228 |
zil_free(zilog_t *zilog) |
|
1229 |
{ |
|
1230 |
lwb_t *lwb; |
|
1231 |
||
1232 |
zilog->zl_stop_sync = 1; |
|
1233 |
||
1234 |
while ((lwb = list_head(&zilog->zl_lwb_list)) != NULL) { |
|
1235 |
list_remove(&zilog->zl_lwb_list, lwb); |
|
1236 |
if (lwb->lwb_buf != NULL) |
|
1237 |
zio_buf_free(lwb->lwb_buf, lwb->lwb_sz); |
|
1238 |
kmem_cache_free(zil_lwb_cache, lwb); |
|
1239 |
} |
|
1240 |
list_destroy(&zilog->zl_lwb_list); |
|
1241 |
||
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
1242 |
avl_destroy(&zilog->zl_vdev_tree); |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5676
diff
changeset
|
1243 |
mutex_destroy(&zilog->zl_vdev_lock); |
789 | 1244 |
|
1245 |
ASSERT(list_head(&zilog->zl_itx_list) == NULL); |
|
1246 |
list_destroy(&zilog->zl_itx_list); |
|
2856 | 1247 |
mutex_destroy(&zilog->zl_lock); |
789 | 1248 |
|
5913
a77f8ad2ce63
6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents:
5886
diff
changeset
|
1249 |
cv_destroy(&zilog->zl_cv_writer); |
a77f8ad2ce63
6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents:
5886
diff
changeset
|
1250 |
cv_destroy(&zilog->zl_cv_suspend); |
a77f8ad2ce63
6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents:
5886
diff
changeset
|
1251 |
|
789 | 1252 |
kmem_free(zilog, sizeof (zilog_t)); |
1253 |
} |
|
1254 |
||
1255 |
/* |
|
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1256 |
* return true if the initial log block is not valid |
1362
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1257 |
*/ |
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1258 |
static int |
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1259 |
zil_empty(zilog_t *zilog) |
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1260 |
{ |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1261 |
const zil_header_t *zh = zilog->zl_header; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1262 |
arc_buf_t *abuf = NULL; |
1362
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1263 |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1264 |
if (BP_IS_HOLE(&zh->zh_log)) |
1362
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1265 |
return (1); |
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1266 |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1267 |
if (zil_read_log_block(zilog, &zh->zh_log, &abuf) != 0) |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1268 |
return (1); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1269 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1270 |
VERIFY(arc_buf_remove_ref(abuf, &abuf) == 1); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1271 |
return (0); |
1362
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1272 |
} |
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1273 |
|
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1274 |
/* |
789 | 1275 |
* Open an intent log. |
1276 |
*/ |
|
1277 |
zilog_t * |
|
1278 |
zil_open(objset_t *os, zil_get_data_t *get_data) |
|
1279 |
{ |
|
1280 |
zilog_t *zilog = dmu_objset_zil(os); |
|
1281 |
||
1282 |
zilog->zl_get_data = get_data; |
|
1283 |
zilog->zl_clean_taskq = taskq_create("zil_clean", 1, minclsyspri, |
|
1284 |
2, 2, TASKQ_PREPOPULATE); |
|
1285 |
||
1286 |
return (zilog); |
|
1287 |
} |
|
1288 |
||
1289 |
/* |
|
1290 |
* Close an intent log. |
|
1291 |
*/ |
|
1292 |
void |
|
1293 |
zil_close(zilog_t *zilog) |
|
1294 |
{ |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1295 |
/* |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1296 |
* If the log isn't already committed, mark the objset dirty |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1297 |
* (so zil_sync() will be called) and wait for that txg to sync. |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1298 |
*/ |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1299 |
if (!zil_is_committed(zilog)) { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1300 |
uint64_t txg; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1301 |
dmu_tx_t *tx = dmu_tx_create(zilog->zl_os); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1302 |
(void) dmu_tx_assign(tx, TXG_WAIT); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1303 |
dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1304 |
txg = dmu_tx_get_txg(tx); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1305 |
dmu_tx_commit(tx); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1306 |
txg_wait_synced(zilog->zl_dmu_pool, txg); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1307 |
} |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1308 |
|
789 | 1309 |
taskq_destroy(zilog->zl_clean_taskq); |
1310 |
zilog->zl_clean_taskq = NULL; |
|
1311 |
zilog->zl_get_data = NULL; |
|
1312 |
||
1313 |
zil_itx_clean(zilog); |
|
1314 |
ASSERT(list_head(&zilog->zl_itx_list) == NULL); |
|
1315 |
} |
|
1316 |
||
1317 |
/* |
|
1318 |
* Suspend an intent log. While in suspended mode, we still honor |
|
1319 |
* synchronous semantics, but we rely on txg_wait_synced() to do it. |
|
1320 |
* We suspend the log briefly when taking a snapshot so that the snapshot |
|
1321 |
* contains all the data it's supposed to, and has an empty intent log. |
|
1322 |
*/ |
|
1323 |
int |
|
1324 |
zil_suspend(zilog_t *zilog) |
|
1325 |
{ |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1326 |
const zil_header_t *zh = zilog->zl_header; |
789 | 1327 |
|
1328 |
mutex_enter(&zilog->zl_lock); |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1329 |
if (zh->zh_claim_txg != 0) { /* unplayed log */ |
789 | 1330 |
mutex_exit(&zilog->zl_lock); |
1331 |
return (EBUSY); |
|
1332 |
} |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1333 |
if (zilog->zl_suspend++ != 0) { |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1334 |
/* |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1335 |
* Someone else already began a suspend. |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1336 |
* Just wait for them to finish. |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1337 |
*/ |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1338 |
while (zilog->zl_suspending) |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1339 |
cv_wait(&zilog->zl_cv_suspend, &zilog->zl_lock); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1340 |
mutex_exit(&zilog->zl_lock); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1341 |
return (0); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1342 |
} |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1343 |
zilog->zl_suspending = B_TRUE; |
789 | 1344 |
mutex_exit(&zilog->zl_lock); |
1345 |
||
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1346 |
zil_commit(zilog, UINT64_MAX, 0); |
789 | 1347 |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1348 |
/* |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1349 |
* Wait for any in-flight log writes to complete. |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1350 |
*/ |
789 | 1351 |
mutex_enter(&zilog->zl_lock); |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1352 |
while (zilog->zl_writer) |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1353 |
cv_wait(&zilog->zl_cv_writer, &zilog->zl_lock); |
789 | 1354 |
mutex_exit(&zilog->zl_lock); |
1355 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1356 |
zil_destroy(zilog, B_FALSE); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1357 |
|
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1358 |
mutex_enter(&zilog->zl_lock); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1359 |
zilog->zl_suspending = B_FALSE; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1360 |
cv_broadcast(&zilog->zl_cv_suspend); |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1361 |
mutex_exit(&zilog->zl_lock); |
789 | 1362 |
|
1363 |
return (0); |
|
1364 |
} |
|
1365 |
||
1366 |
void |
|
1367 |
zil_resume(zilog_t *zilog) |
|
1368 |
{ |
|
1369 |
mutex_enter(&zilog->zl_lock); |
|
1370 |
ASSERT(zilog->zl_suspend != 0); |
|
1371 |
zilog->zl_suspend--; |
|
1372 |
mutex_exit(&zilog->zl_lock); |
|
1373 |
} |
|
1374 |
||
1375 |
typedef struct zil_replay_arg { |
|
1376 |
objset_t *zr_os; |
|
1377 |
zil_replay_func_t **zr_replay; |
|
1378 |
void *zr_arg; |
|
1379 |
uint64_t *zr_txgp; |
|
1380 |
boolean_t zr_byteswap; |
|
1381 |
char *zr_lrbuf; |
|
1382 |
} zil_replay_arg_t; |
|
1383 |
||
1384 |
static void |
|
1385 |
zil_replay_log_record(zilog_t *zilog, lr_t *lr, void *zra, uint64_t claim_txg) |
|
1386 |
{ |
|
1387 |
zil_replay_arg_t *zr = zra; |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1388 |
const zil_header_t *zh = zilog->zl_header; |
789 | 1389 |
uint64_t reclen = lr->lrc_reclen; |
1390 |
uint64_t txtype = lr->lrc_txtype; |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1391 |
char *name; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1392 |
int pass, error, sunk; |
789 | 1393 |
|
1394 |
if (zilog->zl_stop_replay) |
|
1395 |
return; |
|
1396 |
||
1397 |
if (lr->lrc_txg < claim_txg) /* already committed */ |
|
1398 |
return; |
|
1399 |
||
1400 |
if (lr->lrc_seq <= zh->zh_replay_seq) /* already replayed */ |
|
1401 |
return; |
|
1402 |
||
5331 | 1403 |
/* Strip case-insensitive bit, still present in log record */ |
1404 |
txtype &= ~TX_CI; |
|
1405 |
||
789 | 1406 |
/* |
1407 |
* Make a copy of the data so we can revise and extend it. |
|
1408 |
*/ |
|
1409 |
bcopy(lr, zr->zr_lrbuf, reclen); |
|
1410 |
||
1411 |
/* |
|
1412 |
* The log block containing this lr may have been byteswapped |
|
1413 |
* so that we can easily examine common fields like lrc_txtype. |
|
1414 |
* However, the log is a mix of different data types, and only the |
|
1415 |
* replay vectors know how to byteswap their records. Therefore, if |
|
1416 |
* the lr was byteswapped, undo it before invoking the replay vector. |
|
1417 |
*/ |
|
1418 |
if (zr->zr_byteswap) |
|
1419 |
byteswap_uint64_array(zr->zr_lrbuf, reclen); |
|
1420 |
||
1421 |
/* |
|
1422 |
* If this is a TX_WRITE with a blkptr, suck in the data. |
|
1423 |
*/ |
|
1424 |
if (txtype == TX_WRITE && reclen == sizeof (lr_write_t)) { |
|
1425 |
lr_write_t *lrw = (lr_write_t *)lr; |
|
1426 |
blkptr_t *wbp = &lrw->lr_blkptr; |
|
1427 |
uint64_t wlen = lrw->lr_length; |
|
1428 |
char *wbuf = zr->zr_lrbuf + reclen; |
|
1429 |
||
1430 |
if (BP_IS_HOLE(wbp)) { /* compressed to a hole */ |
|
1431 |
bzero(wbuf, wlen); |
|
1432 |
} else { |
|
1433 |
/* |
|
1434 |
* A subsequent write may have overwritten this block, |
|
1435 |
* in which case wbp may have been been freed and |
|
1436 |
* reallocated, and our read of wbp may fail with a |
|
1437 |
* checksum error. We can safely ignore this because |
|
1438 |
* the later write will provide the correct data. |
|
1439 |
*/ |
|
1544 | 1440 |
zbookmark_t zb; |
1441 |
||
1442 |
zb.zb_objset = dmu_objset_id(zilog->zl_os); |
|
1443 |
zb.zb_object = lrw->lr_foid; |
|
1444 |
zb.zb_level = -1; |
|
1445 |
zb.zb_blkid = lrw->lr_offset / BP_GET_LSIZE(wbp); |
|
1446 |
||
789 | 1447 |
(void) zio_wait(zio_read(NULL, zilog->zl_spa, |
1448 |
wbp, wbuf, BP_GET_LSIZE(wbp), NULL, NULL, |
|
1449 |
ZIO_PRIORITY_SYNC_READ, |
|
1544 | 1450 |
ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE, &zb)); |
789 | 1451 |
(void) memmove(wbuf, wbuf + lrw->lr_blkoff, wlen); |
1452 |
} |
|
1453 |
} |
|
1454 |
||
1455 |
/* |
|
1456 |
* We must now do two things atomically: replay this log record, |
|
1457 |
* and update the log header to reflect the fact that we did so. |
|
1458 |
* We use the DMU's ability to assign into a specific txg to do this. |
|
1459 |
*/ |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1460 |
for (pass = 1, sunk = B_FALSE; /* CONSTANTCONDITION */; pass++) { |
789 | 1461 |
uint64_t replay_txg; |
1462 |
dmu_tx_t *replay_tx; |
|
1463 |
||
1464 |
replay_tx = dmu_tx_create(zr->zr_os); |
|
1465 |
error = dmu_tx_assign(replay_tx, TXG_WAIT); |
|
1466 |
if (error) { |
|
1467 |
dmu_tx_abort(replay_tx); |
|
1468 |
break; |
|
1469 |
} |
|
1470 |
||
1471 |
replay_txg = dmu_tx_get_txg(replay_tx); |
|
1472 |
||
1473 |
if (txtype == 0 || txtype >= TX_MAX_TYPE) { |
|
1474 |
error = EINVAL; |
|
1475 |
} else { |
|
1476 |
/* |
|
1477 |
* On the first pass, arrange for the replay vector |
|
1478 |
* to fail its dmu_tx_assign(). That's the only way |
|
1479 |
* to ensure that those code paths remain well tested. |
|
5676 | 1480 |
* |
1481 |
* Only byteswap (if needed) on the 1st pass. |
|
789 | 1482 |
*/ |
1483 |
*zr->zr_txgp = replay_txg - (pass == 1); |
|
1484 |
error = zr->zr_replay[txtype](zr->zr_arg, zr->zr_lrbuf, |
|
5676 | 1485 |
zr->zr_byteswap && pass == 1); |
789 | 1486 |
*zr->zr_txgp = TXG_NOWAIT; |
1487 |
} |
|
1488 |
||
1489 |
if (error == 0) { |
|
1490 |
dsl_dataset_dirty(dmu_objset_ds(zr->zr_os), replay_tx); |
|
1491 |
zilog->zl_replay_seq[replay_txg & TXG_MASK] = |
|
1492 |
lr->lrc_seq; |
|
1493 |
} |
|
1494 |
||
1495 |
dmu_tx_commit(replay_tx); |
|
1496 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1497 |
if (!error) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1498 |
return; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1499 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1500 |
/* |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1501 |
* The DMU's dnode layer doesn't see removes until the txg |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1502 |
* commits, so a subsequent claim can spuriously fail with |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1503 |
* EEXIST. So if we receive any error other than ERESTART |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1504 |
* we try syncing out any removes then retrying the |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1505 |
* transaction. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1506 |
*/ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1507 |
if (error != ERESTART && !sunk) { |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1508 |
txg_wait_synced(spa_get_dsl(zilog->zl_spa), 0); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1509 |
sunk = B_TRUE; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1510 |
continue; /* retry */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1511 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1512 |
|
789 | 1513 |
if (error != ERESTART) |
1514 |
break; |
|
1515 |
||
1516 |
if (pass != 1) |
|
1517 |
txg_wait_open(spa_get_dsl(zilog->zl_spa), |
|
1518 |
replay_txg + 1); |
|
1519 |
||
1520 |
dprintf("pass %d, retrying\n", pass); |
|
1521 |
} |
|
1522 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1523 |
ASSERT(error && error != ERESTART); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1524 |
name = kmem_alloc(MAXNAMELEN, KM_SLEEP); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1525 |
dmu_objset_name(zr->zr_os, name); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1526 |
cmn_err(CE_WARN, "ZFS replay transaction error %d, " |
5331 | 1527 |
"dataset %s, seq 0x%llx, txtype %llu %s\n", |
1528 |
error, name, (u_longlong_t)lr->lrc_seq, (u_longlong_t)txtype, |
|
1529 |
(lr->lrc_txtype & TX_CI) ? "CI" : ""); |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1530 |
zilog->zl_stop_replay = 1; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1531 |
kmem_free(name, MAXNAMELEN); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1532 |
} |
789 | 1533 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1534 |
/* ARGSUSED */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1535 |
static void |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1536 |
zil_incr_blks(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1537 |
{ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1538 |
zilog->zl_replay_blks++; |
789 | 1539 |
} |
1540 |
||
1541 |
/* |
|
1362
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1542 |
* If this dataset has a non-empty intent log, replay it and destroy it. |
789 | 1543 |
*/ |
1544 |
void |
|
1545 |
zil_replay(objset_t *os, void *arg, uint64_t *txgp, |
|
3461 | 1546 |
zil_replay_func_t *replay_func[TX_MAX_TYPE]) |
789 | 1547 |
{ |
1548 |
zilog_t *zilog = dmu_objset_zil(os); |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1549 |
const zil_header_t *zh = zilog->zl_header; |
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1550 |
zil_replay_arg_t zr; |
1362
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1551 |
|
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1552 |
if (zil_empty(zilog)) { |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1553 |
zil_destroy(zilog, B_TRUE); |
1362
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1554 |
return; |
2b3ee2467364
6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents:
1141
diff
changeset
|
1555 |
} |
789 | 1556 |
|
1557 |
zr.zr_os = os; |
|
1558 |
zr.zr_replay = replay_func; |
|
1559 |
zr.zr_arg = arg; |
|
1560 |
zr.zr_txgp = txgp; |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1561 |
zr.zr_byteswap = BP_SHOULD_BYTESWAP(&zh->zh_log); |
789 | 1562 |
zr.zr_lrbuf = kmem_alloc(2 * SPA_MAXBLOCKSIZE, KM_SLEEP); |
1563 |
||
1564 |
/* |
|
1565 |
* Wait for in-progress removes to sync before starting replay. |
|
1566 |
*/ |
|
1567 |
txg_wait_synced(zilog->zl_dmu_pool, 0); |
|
1568 |
||
1569 |
zilog->zl_stop_replay = 0; |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1570 |
zilog->zl_replay_time = lbolt; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1571 |
ASSERT(zilog->zl_replay_blks == 0); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2986
diff
changeset
|
1572 |
(void) zil_parse(zilog, zil_incr_blks, zil_replay_log_record, &zr, |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1573 |
zh->zh_claim_txg); |
789 | 1574 |
kmem_free(zr.zr_lrbuf, 2 * SPA_MAXBLOCKSIZE); |
1575 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1669
diff
changeset
|
1576 |
zil_destroy(zilog, B_FALSE); |
5712
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5688
diff
changeset
|
1577 |
txg_wait_synced(zilog->zl_dmu_pool, zilog->zl_destroy_txg); |
789 | 1578 |
} |
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1579 |
|
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1580 |
/* |
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1581 |
* Report whether all transactions are committed |
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1582 |
*/ |
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1583 |
int |
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1584 |
zil_is_committed(zilog_t *zilog) |
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1585 |
{ |
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1586 |
lwb_t *lwb; |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1587 |
int ret; |
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1588 |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1589 |
mutex_enter(&zilog->zl_lock); |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1590 |
while (zilog->zl_writer) |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1591 |
cv_wait(&zilog->zl_cv_writer, &zilog->zl_lock); |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1592 |
|
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1593 |
/* recent unpushed intent log transactions? */ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1594 |
if (!list_is_empty(&zilog->zl_itx_list)) { |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1595 |
ret = B_FALSE; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1596 |
goto out; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1597 |
} |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1598 |
|
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1599 |
/* intent log never used? */ |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1600 |
lwb = list_head(&zilog->zl_lwb_list); |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1601 |
if (lwb == NULL) { |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1602 |
ret = B_TRUE; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1603 |
goto out; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1604 |
} |
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1605 |
|
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1606 |
/* |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1607 |
* more than 1 log buffer means zil_sync() hasn't yet freed |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1608 |
* entries after a txg has committed |
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1609 |
*/ |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1610 |
if (list_next(&zilog->zl_lwb_list, lwb)) { |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1611 |
ret = B_FALSE; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1612 |
goto out; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1613 |
} |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1614 |
|
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1615 |
ASSERT(zil_empty(zilog)); |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1616 |
ret = B_TRUE; |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1617 |
out: |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1618 |
cv_broadcast(&zilog->zl_cv_writer); |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1619 |
mutex_exit(&zilog->zl_lock); |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2391
diff
changeset
|
1620 |
return (ret); |
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1544
diff
changeset
|
1621 |
} |