Print this page
5269 zfs: zpool import slow
While importing a pool all objsets are enumerated twice, once to check
the zil log chains and once to claim them. On pools with many datasets
this process might take a substantial amount of time.
Speed up the process by parallelizing it utilizing a taskq. The number
of parallel tasks is limited to 4 times the number of leaf vdevs.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/sys/zil.h
+++ new/usr/src/uts/common/fs/zfs/sys/zil.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 24 */
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
25 25
26 26 /* Portions Copyright 2010 Robert Milkowski */
27 27
28 28 #ifndef _SYS_ZIL_H
29 29 #define _SYS_ZIL_H
30 30
31 31 #include <sys/types.h>
32 32 #include <sys/spa.h>
33 33 #include <sys/zio.h>
34 34 #include <sys/dmu.h>
35 +#include <sys/dsl_pool.h>
36 +#include <sys/dsl_dataset.h>
35 37
36 38 #ifdef __cplusplus
37 39 extern "C" {
38 40 #endif
39 41
40 42 /*
41 43 * Intent log format:
42 44 *
43 45 * Each objset has its own intent log. The log header (zil_header_t)
44 46 * for objset N's intent log is kept in the Nth object of the SPA's
45 47 * intent_log objset. The log header points to a chain of log blocks,
46 48 * each of which contains log records (i.e., transactions) followed by
47 49 * a log block trailer (zil_trailer_t). The format of a log record
48 50 * depends on the record (or transaction) type, but all records begin
49 51 * with a common structure that defines the type, length, and txg.
50 52 */
51 53
52 54 /*
53 55 * Intent log header - this on disk structure holds fields to manage
54 56 * the log. All fields are 64 bit to easily handle cross architectures.
55 57 */
56 58 typedef struct zil_header {
57 59 uint64_t zh_claim_txg; /* txg in which log blocks were claimed */
58 60 uint64_t zh_replay_seq; /* highest replayed sequence number */
59 61 blkptr_t zh_log; /* log chain */
60 62 uint64_t zh_claim_blk_seq; /* highest claimed block sequence number */
61 63 uint64_t zh_flags; /* header flags */
62 64 uint64_t zh_claim_lr_seq; /* highest claimed lr sequence number */
63 65 uint64_t zh_pad[3];
64 66 } zil_header_t;
65 67
66 68 /*
67 69 * zh_flags bit settings
68 70 */
69 71 #define ZIL_REPLAY_NEEDED 0x1 /* replay needed - internal only */
70 72 #define ZIL_CLAIM_LR_SEQ_VALID 0x2 /* zh_claim_lr_seq field is valid */
71 73
72 74 /*
73 75 * Log block chaining.
74 76 *
75 77 * Log blocks are chained together. Originally they were chained at the
76 78 * end of the block. For performance reasons the chain was moved to the
77 79 * beginning of the block which allows writes for only the data being used.
78 80 * The older position is supported for backwards compatability.
79 81 *
80 82 * The zio_eck_t contains a zec_cksum which for the intent log is
81 83 * the sequence number of this log block. A seq of 0 is invalid.
82 84 * The zec_cksum is checked by the SPA against the sequence
83 85 * number passed in the blk_cksum field of the blkptr_t
84 86 */
85 87 typedef struct zil_chain {
86 88 uint64_t zc_pad;
87 89 blkptr_t zc_next_blk; /* next block in chain */
88 90 uint64_t zc_nused; /* bytes in log block used */
89 91 zio_eck_t zc_eck; /* block trailer */
90 92 } zil_chain_t;
91 93
92 94 #define ZIL_MIN_BLKSZ 4096ULL
93 95 #define ZIL_MAX_BLKSZ SPA_MAXBLOCKSIZE
94 96
95 97 /*
96 98 * The words of a log block checksum.
97 99 */
98 100 #define ZIL_ZC_GUID_0 0
99 101 #define ZIL_ZC_GUID_1 1
100 102 #define ZIL_ZC_OBJSET 2
101 103 #define ZIL_ZC_SEQ 3
102 104
103 105 typedef enum zil_create {
104 106 Z_FILE,
105 107 Z_DIR,
106 108 Z_XATTRDIR,
107 109 } zil_create_t;
108 110
109 111 /*
110 112 * size of xvattr log section.
111 113 * its composed of lr_attr_t + xvattr bitmap + 2 64 bit timestamps
112 114 * for create time and a single 64 bit integer for all of the attributes,
113 115 * and 4 64 bit integers (32 bytes) for the scanstamp.
114 116 *
115 117 */
116 118
117 119 #define ZIL_XVAT_SIZE(mapsize) \
118 120 sizeof (lr_attr_t) + (sizeof (uint32_t) * (mapsize - 1)) + \
119 121 (sizeof (uint64_t) * 7)
120 122
121 123 /*
122 124 * Size of ACL in log. The ACE data is padded out to properly align
123 125 * on 8 byte boundary.
124 126 */
125 127
126 128 #define ZIL_ACE_LENGTH(x) (roundup(x, sizeof (uint64_t)))
127 129
128 130 /*
129 131 * Intent log transaction types and record structures
130 132 */
131 133 #define TX_CREATE 1 /* Create file */
132 134 #define TX_MKDIR 2 /* Make directory */
133 135 #define TX_MKXATTR 3 /* Make XATTR directory */
134 136 #define TX_SYMLINK 4 /* Create symbolic link to a file */
135 137 #define TX_REMOVE 5 /* Remove file */
136 138 #define TX_RMDIR 6 /* Remove directory */
137 139 #define TX_LINK 7 /* Create hard link to a file */
138 140 #define TX_RENAME 8 /* Rename a file */
139 141 #define TX_WRITE 9 /* File write */
140 142 #define TX_TRUNCATE 10 /* Truncate a file */
141 143 #define TX_SETATTR 11 /* Set file attributes */
142 144 #define TX_ACL_V0 12 /* Set old formatted ACL */
143 145 #define TX_ACL 13 /* Set ACL */
144 146 #define TX_CREATE_ACL 14 /* create with ACL */
145 147 #define TX_CREATE_ATTR 15 /* create + attrs */
146 148 #define TX_CREATE_ACL_ATTR 16 /* create with ACL + attrs */
147 149 #define TX_MKDIR_ACL 17 /* mkdir with ACL */
148 150 #define TX_MKDIR_ATTR 18 /* mkdir with attr */
149 151 #define TX_MKDIR_ACL_ATTR 19 /* mkdir with ACL + attrs */
150 152 #define TX_WRITE2 20 /* dmu_sync EALREADY write */
151 153 #define TX_MAX_TYPE 21 /* Max transaction type */
152 154
153 155 /*
154 156 * The transactions for mkdir, symlink, remove, rmdir, link, and rename
155 157 * may have the following bit set, indicating the original request
156 158 * specified case-insensitive handling of names.
157 159 */
158 160 #define TX_CI ((uint64_t)0x1 << 63) /* case-insensitive behavior requested */
159 161
160 162 /*
161 163 * Transactions for write, truncate, setattr, acl_v0, and acl can be logged
162 164 * out of order. For convenience in the code, all such records must have
163 165 * lr_foid at the same offset.
164 166 */
165 167 #define TX_OOO(txtype) \
166 168 ((txtype) == TX_WRITE || \
167 169 (txtype) == TX_TRUNCATE || \
168 170 (txtype) == TX_SETATTR || \
169 171 (txtype) == TX_ACL_V0 || \
170 172 (txtype) == TX_ACL || \
171 173 (txtype) == TX_WRITE2)
172 174
173 175 /*
174 176 * Format of log records.
175 177 * The fields are carefully defined to allow them to be aligned
176 178 * and sized the same on sparc & intel architectures.
177 179 * Each log record has a common structure at the beginning.
178 180 *
179 181 * The log record on disk (lrc_seq) holds the sequence number of all log
180 182 * records which is used to ensure we don't replay the same record.
181 183 */
182 184 typedef struct { /* common log record header */
183 185 uint64_t lrc_txtype; /* intent log transaction type */
184 186 uint64_t lrc_reclen; /* transaction record length */
185 187 uint64_t lrc_txg; /* dmu transaction group number */
186 188 uint64_t lrc_seq; /* see comment above */
187 189 } lr_t;
188 190
189 191 /*
190 192 * Common start of all out-of-order record types (TX_OOO() above).
191 193 */
192 194 typedef struct {
193 195 lr_t lr_common; /* common portion of log record */
194 196 uint64_t lr_foid; /* object id */
195 197 } lr_ooo_t;
196 198
197 199 /*
198 200 * Handle option extended vattr attributes.
199 201 *
200 202 * Whenever new attributes are added the version number
201 203 * will need to be updated as will code in
202 204 * zfs_log.c and zfs_replay.c
203 205 */
204 206 typedef struct {
205 207 uint32_t lr_attr_masksize; /* number of elements in array */
206 208 uint32_t lr_attr_bitmap; /* First entry of array */
207 209 /* remainder of array and any additional fields */
208 210 } lr_attr_t;
209 211
210 212 /*
211 213 * log record for creates without optional ACL.
212 214 * This log record does support optional xvattr_t attributes.
213 215 */
214 216 typedef struct {
215 217 lr_t lr_common; /* common portion of log record */
216 218 uint64_t lr_doid; /* object id of directory */
217 219 uint64_t lr_foid; /* object id of created file object */
218 220 uint64_t lr_mode; /* mode of object */
219 221 uint64_t lr_uid; /* uid of object */
220 222 uint64_t lr_gid; /* gid of object */
221 223 uint64_t lr_gen; /* generation (txg of creation) */
222 224 uint64_t lr_crtime[2]; /* creation time */
223 225 uint64_t lr_rdev; /* rdev of object to create */
224 226 /* name of object to create follows this */
225 227 /* for symlinks, link content follows name */
226 228 /* for creates with xvattr data, the name follows the xvattr info */
227 229 } lr_create_t;
228 230
229 231 /*
230 232 * FUID ACL record will be an array of ACEs from the original ACL.
231 233 * If this array includes ephemeral IDs, the record will also include
232 234 * an array of log-specific FUIDs to replace the ephemeral IDs.
233 235 * Only one copy of each unique domain will be present, so the log-specific
234 236 * FUIDs will use an index into a compressed domain table. On replay this
235 237 * information will be used to construct real FUIDs (and bypass idmap,
236 238 * since it may not be available).
237 239 */
238 240
239 241 /*
240 242 * Log record for creates with optional ACL
241 243 * This log record is also used for recording any FUID
242 244 * information needed for replaying the create. If the
243 245 * file doesn't have any actual ACEs then the lr_aclcnt
244 246 * would be zero.
245 247 *
246 248 * After lr_acl_flags, there are a lr_acl_bytes number of variable sized ace's.
247 249 * If create is also setting xvattr's, then acl data follows xvattr.
248 250 * If ACE FUIDs are needed then they will follow the xvattr_t. Following
249 251 * the FUIDs will be the domain table information. The FUIDs for the owner
250 252 * and group will be in lr_create. Name follows ACL data.
251 253 */
252 254 typedef struct {
253 255 lr_create_t lr_create; /* common create portion */
254 256 uint64_t lr_aclcnt; /* number of ACEs in ACL */
255 257 uint64_t lr_domcnt; /* number of unique domains */
256 258 uint64_t lr_fuidcnt; /* number of real fuids */
257 259 uint64_t lr_acl_bytes; /* number of bytes in ACL */
258 260 uint64_t lr_acl_flags; /* ACL flags */
259 261 } lr_acl_create_t;
260 262
261 263 typedef struct {
262 264 lr_t lr_common; /* common portion of log record */
263 265 uint64_t lr_doid; /* obj id of directory */
264 266 /* name of object to remove follows this */
265 267 } lr_remove_t;
266 268
267 269 typedef struct {
268 270 lr_t lr_common; /* common portion of log record */
269 271 uint64_t lr_doid; /* obj id of directory */
270 272 uint64_t lr_link_obj; /* obj id of link */
271 273 /* name of object to link follows this */
272 274 } lr_link_t;
273 275
274 276 typedef struct {
275 277 lr_t lr_common; /* common portion of log record */
276 278 uint64_t lr_sdoid; /* obj id of source directory */
277 279 uint64_t lr_tdoid; /* obj id of target directory */
278 280 /* 2 strings: names of source and destination follow this */
279 281 } lr_rename_t;
280 282
281 283 typedef struct {
282 284 lr_t lr_common; /* common portion of log record */
283 285 uint64_t lr_foid; /* file object to write */
284 286 uint64_t lr_offset; /* offset to write to */
285 287 uint64_t lr_length; /* user data length to write */
286 288 uint64_t lr_blkoff; /* no longer used */
287 289 blkptr_t lr_blkptr; /* spa block pointer for replay */
288 290 /* write data will follow for small writes */
289 291 } lr_write_t;
290 292
291 293 typedef struct {
292 294 lr_t lr_common; /* common portion of log record */
293 295 uint64_t lr_foid; /* object id of file to truncate */
294 296 uint64_t lr_offset; /* offset to truncate from */
295 297 uint64_t lr_length; /* length to truncate */
296 298 } lr_truncate_t;
297 299
298 300 typedef struct {
299 301 lr_t lr_common; /* common portion of log record */
300 302 uint64_t lr_foid; /* file object to change attributes */
301 303 uint64_t lr_mask; /* mask of attributes to set */
302 304 uint64_t lr_mode; /* mode to set */
303 305 uint64_t lr_uid; /* uid to set */
304 306 uint64_t lr_gid; /* gid to set */
305 307 uint64_t lr_size; /* size to set */
306 308 uint64_t lr_atime[2]; /* access time */
307 309 uint64_t lr_mtime[2]; /* modification time */
308 310 /* optional attribute lr_attr_t may be here */
309 311 } lr_setattr_t;
310 312
311 313 typedef struct {
312 314 lr_t lr_common; /* common portion of log record */
313 315 uint64_t lr_foid; /* obj id of file */
314 316 uint64_t lr_aclcnt; /* number of acl entries */
315 317 /* lr_aclcnt number of ace_t entries follow this */
316 318 } lr_acl_v0_t;
317 319
318 320 typedef struct {
319 321 lr_t lr_common; /* common portion of log record */
320 322 uint64_t lr_foid; /* obj id of file */
321 323 uint64_t lr_aclcnt; /* number of ACEs in ACL */
322 324 uint64_t lr_domcnt; /* number of unique domains */
323 325 uint64_t lr_fuidcnt; /* number of real fuids */
324 326 uint64_t lr_acl_bytes; /* number of bytes in ACL */
325 327 uint64_t lr_acl_flags; /* ACL flags */
326 328 /* lr_acl_bytes number of variable sized ace's follows */
327 329 } lr_acl_t;
328 330
329 331 /*
330 332 * ZIL structure definitions, interface function prototype and globals.
331 333 */
332 334
333 335 /*
334 336 * Writes are handled in three different ways:
335 337 *
336 338 * WR_INDIRECT:
337 339 * In this mode, if we need to commit the write later, then the block
338 340 * is immediately written into the file system (using dmu_sync),
339 341 * and a pointer to the block is put into the log record.
340 342 * When the txg commits the block is linked in.
341 343 * This saves additionally writing the data into the log record.
342 344 * There are a few requirements for this to occur:
343 345 * - write is greater than zfs/zvol_immediate_write_sz
344 346 * - not using slogs (as slogs are assumed to always be faster
345 347 * than writing into the main pool)
346 348 * - the write occupies only one block
347 349 * WR_COPIED:
348 350 * If we know we'll immediately be committing the
349 351 * transaction (FSYNC or FDSYNC), the we allocate a larger
350 352 * log record here for the data and copy the data in.
351 353 * WR_NEED_COPY:
352 354 * Otherwise we don't allocate a buffer, and *if* we need to
353 355 * flush the write later then a buffer is allocated and
354 356 * we retrieve the data using the dmu.
355 357 */
356 358 typedef enum {
357 359 WR_INDIRECT, /* indirect - a large write (dmu_sync() data */
358 360 /* and put blkptr in log, rather than actual data) */
359 361 WR_COPIED, /* immediate - data is copied into lr_write_t */
360 362 WR_NEED_COPY, /* immediate - data needs to be copied if pushed */
361 363 WR_NUM_STATES /* number of states */
362 364 } itx_wr_state_t;
363 365
364 366 typedef struct itx {
365 367 list_node_t itx_node; /* linkage on zl_itx_list */
366 368 void *itx_private; /* type-specific opaque data */
367 369 itx_wr_state_t itx_wr_state; /* write state */
368 370 uint8_t itx_sync; /* synchronous transaction */
369 371 uint64_t itx_sod; /* record size on disk */
370 372 uint64_t itx_oid; /* object id */
371 373 lr_t itx_lr; /* common part of log record */
372 374 /* followed by type-specific part of lr_xx_t and its immediate data */
373 375 } itx_t;
374 376
375 377 typedef int zil_parse_blk_func_t(zilog_t *zilog, blkptr_t *bp, void *arg,
376 378 uint64_t txg);
377 379 typedef int zil_parse_lr_func_t(zilog_t *zilog, lr_t *lr, void *arg,
378 380 uint64_t txg);
379 381 typedef int zil_replay_func_t();
380 382 typedef int zil_get_data_t(void *arg, lr_write_t *lr, char *dbuf, zio_t *zio);
381 383
382 384 extern int zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func,
383 385 zil_parse_lr_func_t *parse_lr_func, void *arg, uint64_t txg);
384 386
385 387 extern void zil_init(void);
386 388 extern void zil_fini(void);
387 389
388 390 extern zilog_t *zil_alloc(objset_t *os, zil_header_t *zh_phys);
389 391 extern void zil_free(zilog_t *zilog);
390 392
391 393 extern zilog_t *zil_open(objset_t *os, zil_get_data_t *get_data);
392 394 extern void zil_close(zilog_t *zilog);
393 395
394 396 extern void zil_replay(objset_t *os, void *arg,
395 397 zil_replay_func_t *replay_func[TX_MAX_TYPE]);
396 398 extern boolean_t zil_replaying(zilog_t *zilog, dmu_tx_t *tx);
397 399 extern void zil_destroy(zilog_t *zilog, boolean_t keep_first);
↓ open down ↓ |
353 lines elided |
↑ open up ↑ |
398 400 extern void zil_destroy_sync(zilog_t *zilog, dmu_tx_t *tx);
399 401 extern void zil_rollback_destroy(zilog_t *zilog, dmu_tx_t *tx);
400 402
401 403 extern itx_t *zil_itx_create(uint64_t txtype, size_t lrsize);
402 404 extern void zil_itx_destroy(itx_t *itx);
403 405 extern void zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx);
404 406
405 407 extern void zil_commit(zilog_t *zilog, uint64_t oid);
406 408
407 409 extern int zil_vdev_offline(const char *osname, void *txarg);
408 -extern int zil_claim(const char *osname, void *txarg);
409 -extern int zil_check_log_chain(const char *osname, void *txarg);
410 +extern int zil_claim(dsl_pool_t *dp, dsl_dataset_t *ds, void *txarg);
411 +extern int zil_check_log_chain(dsl_pool_t *dp, dsl_dataset_t *ds,
412 + void *tx);
410 413 extern void zil_sync(zilog_t *zilog, dmu_tx_t *tx);
411 414 extern void zil_clean(zilog_t *zilog, uint64_t synced_txg);
412 415
413 416 extern int zil_suspend(const char *osname, void **cookiep);
414 417 extern void zil_resume(void *cookie);
415 418
416 419 extern void zil_add_block(zilog_t *zilog, const blkptr_t *bp);
417 420 extern int zil_bp_tree_add(zilog_t *zilog, const blkptr_t *bp);
418 421
419 422 extern void zil_set_sync(zilog_t *zilog, uint64_t syncval);
420 423
421 424 extern void zil_set_logbias(zilog_t *zilog, uint64_t slogval);
422 425
423 426 extern int zil_replay_disable;
424 427
425 428 #ifdef __cplusplus
426 429 }
427 430 #endif
428 431
429 432 #endif /* _SYS_ZIL_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX