4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2011 by Delphix. All rights reserved.
26 #include <sys/dsl_pool.h>
27 #include <sys/dsl_dataset.h>
28 #include <sys/dsl_prop.h>
29 #include <sys/dsl_dir.h>
30 #include <sys/dsl_synctask.h>
31 #include <sys/dsl_scan.h>
32 #include <sys/dnode.h>
33 #include <sys/dmu_tx.h>
34 #include <sys/dmu_objset.h>
38 #include <sys/zfs_context.h>
39 #include <sys/fs/zfs.h>
40 #include <sys/zfs_znode.h>
41 #include <sys/spa_impl.h>
42 #include <sys/dsl_deadlist.h>
44 int zfs_no_write_throttle = 0;
45 int zfs_write_limit_shift = 3; /* 1/8th of physical memory */
46 int zfs_txg_synctime_ms = 1000; /* target millisecs to sync a txg */
48 unsigned long zfs_write_limit_min = 32 << 20; /* min write limit is 32MB */
49 unsigned long zfs_write_limit_max = 0; /* max data payload per txg */
50 unsigned long zfs_write_limit_inflated = 0;
51 unsigned long zfs_write_limit_override = 0;
53 kmutex_t zfs_write_limit_lock;
55 static pgcnt_t old_physmem = 0;
58 dsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **ddp)
63 err = zap_lookup(dp->dp_meta_objset,
64 dp->dp_root_dir->dd_phys->dd_child_dir_zapobj,
65 name, sizeof (obj), 1, &obj);
69 return (dsl_dir_open_obj(dp, obj, name, dp, ddp));
73 dsl_pool_open_impl(spa_t *spa, uint64_t txg)
76 blkptr_t *bp = spa_get_rootblkptr(spa);
78 dp = kmem_zalloc(sizeof (dsl_pool_t), KM_SLEEP);
80 dp->dp_meta_rootbp = *bp;
81 rw_init(&dp->dp_config_rwlock, NULL, RW_DEFAULT, NULL);
82 dp->dp_write_limit = zfs_write_limit_min;
85 txg_list_create(&dp->dp_dirty_datasets,
86 offsetof(dsl_dataset_t, ds_dirty_link));
87 txg_list_create(&dp->dp_dirty_dirs,
88 offsetof(dsl_dir_t, dd_dirty_link));
89 txg_list_create(&dp->dp_sync_tasks,
90 offsetof(dsl_sync_task_group_t, dstg_node));
91 list_create(&dp->dp_synced_datasets, sizeof (dsl_dataset_t),
92 offsetof(dsl_dataset_t, ds_synced_link));
94 mutex_init(&dp->dp_lock, NULL, MUTEX_DEFAULT, NULL);
96 dp->dp_iput_taskq = taskq_create("zfs_iput_taskq", 1, minclsyspri,
103 dsl_pool_open(spa_t *spa, uint64_t txg, dsl_pool_t **dpp)
106 dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
111 rw_enter(&dp->dp_config_rwlock, RW_WRITER);
112 err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp,
113 &dp->dp_meta_objset);
117 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
118 DMU_POOL_ROOT_DATASET, sizeof (uint64_t), 1,
119 &dp->dp_root_dir_obj);
123 err = dsl_dir_open_obj(dp, dp->dp_root_dir_obj,
124 NULL, dp, &dp->dp_root_dir);
128 err = dsl_pool_open_special_dir(dp, MOS_DIR_NAME, &dp->dp_mos_dir);
132 if (spa_version(spa) >= SPA_VERSION_ORIGIN) {
133 err = dsl_pool_open_special_dir(dp, ORIGIN_DIR_NAME, &dd);
136 err = dsl_dataset_hold_obj(dp, dd->dd_phys->dd_head_dataset_obj,
139 err = dsl_dataset_hold_obj(dp,
140 ds->ds_phys->ds_prev_snap_obj, dp,
141 &dp->dp_origin_snap);
142 dsl_dataset_rele(ds, FTAG);
144 dsl_dir_close(dd, dp);
149 if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
150 err = dsl_pool_open_special_dir(dp, FREE_DIR_NAME,
155 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
156 DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj);
159 VERIFY3U(0, ==, bpobj_open(&dp->dp_free_bpobj,
160 dp->dp_meta_objset, obj));
163 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
164 DMU_POOL_TMP_USERREFS, sizeof (uint64_t), 1,
165 &dp->dp_tmp_userrefs_obj);
171 err = dsl_scan_init(dp, txg);
174 rw_exit(&dp->dp_config_rwlock);
184 dsl_pool_close(dsl_pool_t *dp)
186 /* drop our references from dsl_pool_open() */
189 * Since we held the origin_snap from "syncing" context (which
190 * includes pool-opening context), it actually only got a "ref"
191 * and not a hold, so just drop that here.
193 if (dp->dp_origin_snap)
194 dsl_dataset_drop_ref(dp->dp_origin_snap, dp);
196 dsl_dir_close(dp->dp_mos_dir, dp);
198 dsl_dir_close(dp->dp_free_dir, dp);
200 dsl_dir_close(dp->dp_root_dir, dp);
202 bpobj_close(&dp->dp_free_bpobj);
204 /* undo the dmu_objset_open_impl(mos) from dsl_pool_open() */
205 if (dp->dp_meta_objset)
206 dmu_objset_evict(dp->dp_meta_objset);
208 txg_list_destroy(&dp->dp_dirty_datasets);
209 txg_list_destroy(&dp->dp_sync_tasks);
210 txg_list_destroy(&dp->dp_dirty_dirs);
211 list_destroy(&dp->dp_synced_datasets);
213 arc_flush(dp->dp_spa);
216 rw_destroy(&dp->dp_config_rwlock);
217 mutex_destroy(&dp->dp_lock);
218 taskq_destroy(dp->dp_iput_taskq);
220 kmem_free(dp->dp_blkstats, sizeof (zfs_all_blkstats_t));
221 kmem_free(dp, sizeof (dsl_pool_t));
225 dsl_pool_create(spa_t *spa, nvlist_t *zplprops, uint64_t txg)
228 dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
229 dmu_tx_t *tx = dmu_tx_create_assigned(dp, txg);
234 /* create and open the MOS (meta-objset) */
235 dp->dp_meta_objset = dmu_objset_create_impl(spa,
236 NULL, &dp->dp_meta_rootbp, DMU_OST_META, tx);
238 /* create the pool directory */
239 err = zap_create_claim(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
240 DMU_OT_OBJECT_DIRECTORY, DMU_OT_NONE, 0, tx);
241 ASSERT3U(err, ==, 0);
243 /* Initialize scan structures */
244 VERIFY3U(0, ==, dsl_scan_init(dp, txg));
246 /* create and open the root dir */
247 dp->dp_root_dir_obj = dsl_dir_create_sync(dp, NULL, NULL, tx);
248 VERIFY(0 == dsl_dir_open_obj(dp, dp->dp_root_dir_obj,
249 NULL, dp, &dp->dp_root_dir));
251 /* create and open the meta-objset dir */
252 (void) dsl_dir_create_sync(dp, dp->dp_root_dir, MOS_DIR_NAME, tx);
253 VERIFY(0 == dsl_pool_open_special_dir(dp,
254 MOS_DIR_NAME, &dp->dp_mos_dir));
256 if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
257 /* create and open the free dir */
258 (void) dsl_dir_create_sync(dp, dp->dp_root_dir,
260 VERIFY(0 == dsl_pool_open_special_dir(dp,
261 FREE_DIR_NAME, &dp->dp_free_dir));
263 /* create and open the free_bplist */
264 obj = bpobj_alloc(dp->dp_meta_objset, SPA_MAXBLOCKSIZE, tx);
265 VERIFY(zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
266 DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx) == 0);
267 VERIFY3U(0, ==, bpobj_open(&dp->dp_free_bpobj,
268 dp->dp_meta_objset, obj));
271 if (spa_version(spa) >= SPA_VERSION_DSL_SCRUB)
272 dsl_pool_create_origin(dp, tx);
274 /* create the root dataset */
275 obj = dsl_dataset_create_sync_dd(dp->dp_root_dir, NULL, 0, tx);
277 /* create the root objset */
278 VERIFY(0 == dsl_dataset_hold_obj(dp, obj, FTAG, &ds));
279 VERIFY(NULL != (os = dmu_objset_create_impl(dp->dp_spa, ds,
280 dsl_dataset_get_blkptr(ds), DMU_OST_ZFS, tx)));
282 zfs_create_fs(os, kcred, zplprops, tx);
284 dsl_dataset_rele(ds, FTAG);
292 deadlist_enqueue_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
294 dsl_deadlist_t *dl = arg;
295 dsl_pool_t *dp = dmu_objset_pool(dl->dl_os);
296 rw_enter(&dp->dp_config_rwlock, RW_READER);
297 dsl_deadlist_insert(dl, bp, tx);
298 rw_exit(&dp->dp_config_rwlock);
303 dsl_pool_sync(dsl_pool_t *dp, uint64_t txg)
309 dsl_sync_task_group_t *dstg;
310 objset_t *mos = dp->dp_meta_objset;
311 hrtime_t start, write_time;
312 uint64_t data_written;
316 * We need to copy dp_space_towrite() before doing
317 * dsl_sync_task_group_sync(), because
318 * dsl_dataset_snapshot_reserve_space() will increase
319 * dp_space_towrite but not actually write anything.
321 data_written = dp->dp_space_towrite[txg & TXG_MASK];
323 tx = dmu_tx_create_assigned(dp, txg);
325 dp->dp_read_overhead = 0;
328 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
329 while ((ds = txg_list_remove(&dp->dp_dirty_datasets, txg))) {
331 * We must not sync any non-MOS datasets twice, because
332 * we may have taken a snapshot of them. However, we
333 * may sync newly-created datasets on pass 2.
335 ASSERT(!list_link_active(&ds->ds_synced_link));
336 list_insert_tail(&dp->dp_synced_datasets, ds);
337 dsl_dataset_sync(ds, zio, tx);
339 DTRACE_PROBE(pool_sync__1setup);
342 write_time = gethrtime() - start;
344 DTRACE_PROBE(pool_sync__2rootzio);
346 for (ds = list_head(&dp->dp_synced_datasets); ds;
347 ds = list_next(&dp->dp_synced_datasets, ds))
348 dmu_objset_do_userquota_updates(ds->ds_objset, tx);
351 * Sync the datasets again to push out the changes due to
352 * userspace updates. This must be done before we process the
353 * sync tasks, because that could cause a snapshot of a dataset
354 * whose ds_bp will be rewritten when we do this 2nd sync.
356 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
357 while ((ds = txg_list_remove(&dp->dp_dirty_datasets, txg))) {
358 ASSERT(list_link_active(&ds->ds_synced_link));
359 dmu_buf_rele(ds->ds_dbuf, ds);
360 dsl_dataset_sync(ds, zio, tx);
365 * Move dead blocks from the pending deadlist to the on-disk
368 for (ds = list_head(&dp->dp_synced_datasets); ds;
369 ds = list_next(&dp->dp_synced_datasets, ds)) {
370 bplist_iterate(&ds->ds_pending_deadlist,
371 deadlist_enqueue_cb, &ds->ds_deadlist, tx);
374 while ((dstg = txg_list_remove(&dp->dp_sync_tasks, txg))) {
376 * No more sync tasks should have been added while we
379 ASSERT(spa_sync_pass(dp->dp_spa) == 1);
380 dsl_sync_task_group_sync(dstg, tx);
382 DTRACE_PROBE(pool_sync__3task);
385 while ((dd = txg_list_remove(&dp->dp_dirty_dirs, txg)))
386 dsl_dir_sync(dd, tx);
387 write_time += gethrtime() - start;
390 if (list_head(&mos->os_dirty_dnodes[txg & TXG_MASK]) != NULL ||
391 list_head(&mos->os_free_dnodes[txg & TXG_MASK]) != NULL) {
392 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
393 dmu_objset_sync(mos, zio, tx);
396 dprintf_bp(&dp->dp_meta_rootbp, "meta objset rootbp is %s", "");
397 spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp);
399 write_time += gethrtime() - start;
400 DTRACE_PROBE2(pool_sync__4io, hrtime_t, write_time,
401 hrtime_t, dp->dp_read_overhead);
402 write_time -= dp->dp_read_overhead;
406 dp->dp_space_towrite[txg & TXG_MASK] = 0;
407 ASSERT(dp->dp_tempreserved[txg & TXG_MASK] == 0);
410 * If the write limit max has not been explicitly set, set it
411 * to a fraction of available physical memory (default 1/8th).
412 * Note that we must inflate the limit because the spa
413 * inflates write sizes to account for data replication.
414 * Check this each sync phase to catch changing memory size.
416 if (physmem != old_physmem && zfs_write_limit_shift) {
417 mutex_enter(&zfs_write_limit_lock);
418 old_physmem = physmem;
419 zfs_write_limit_max = ptob(physmem) >> zfs_write_limit_shift;
420 zfs_write_limit_inflated = MAX(zfs_write_limit_min,
421 spa_get_asize(dp->dp_spa, zfs_write_limit_max));
422 mutex_exit(&zfs_write_limit_lock);
426 * Attempt to keep the sync time consistent by adjusting the
427 * amount of write traffic allowed into each transaction group.
428 * Weight the throughput calculation towards the current value:
429 * thru = 3/4 old_thru + 1/4 new_thru
431 * Note: write_time is in nanosecs, so write_time/MICROSEC
434 ASSERT(zfs_write_limit_min > 0);
435 if (data_written > zfs_write_limit_min / 8 && write_time > MICROSEC) {
436 uint64_t throughput = data_written / (write_time / MICROSEC);
438 if (dp->dp_throughput)
439 dp->dp_throughput = throughput / 4 +
440 3 * dp->dp_throughput / 4;
442 dp->dp_throughput = throughput;
443 dp->dp_write_limit = MIN(zfs_write_limit_inflated,
444 MAX(zfs_write_limit_min,
445 dp->dp_throughput * zfs_txg_synctime_ms));
450 dsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg)
455 while ((ds = list_head(&dp->dp_synced_datasets))) {
456 list_remove(&dp->dp_synced_datasets, ds);
458 zil_clean(os->os_zil, txg);
459 ASSERT(!dmu_objset_is_dirty(os, txg));
460 dmu_buf_rele(ds->ds_dbuf, ds);
462 ASSERT(!dmu_objset_is_dirty(dp->dp_meta_objset, txg));
466 * TRUE if the current thread is the tx_sync_thread or if we
467 * are being called from SPA context during pool initialization.
470 dsl_pool_sync_context(dsl_pool_t *dp)
472 return (curthread == dp->dp_tx.tx_sync_thread ||
473 spa_get_dsl(dp->dp_spa) == NULL);
477 dsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree)
479 uint64_t space, resv;
482 * Reserve about 1.6% (1/64), or at least 32MB, for allocation
484 * XXX The intent log is not accounted for, so it must fit
487 * If we're trying to assess whether it's OK to do a free,
488 * cut the reservation in half to allow forward progress
489 * (e.g. make it possible to rm(1) files from a full pool).
491 space = spa_get_dspace(dp->dp_spa);
492 resv = MAX(space >> 6, SPA_MINDEVSIZE >> 1);
496 return (space - resv);
500 dsl_pool_tempreserve_space(dsl_pool_t *dp, uint64_t space, dmu_tx_t *tx)
502 uint64_t reserved = 0;
503 uint64_t write_limit = (zfs_write_limit_override ?
504 zfs_write_limit_override : dp->dp_write_limit);
506 if (zfs_no_write_throttle) {
507 atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK],
513 * Check to see if we have exceeded the maximum allowed IO for
514 * this transaction group. We can do this without locks since
515 * a little slop here is ok. Note that we do the reserved check
516 * with only half the requested reserve: this is because the
517 * reserve requests are worst-case, and we really don't want to
518 * throttle based off of worst-case estimates.
520 if (write_limit > 0) {
521 reserved = dp->dp_space_towrite[tx->tx_txg & TXG_MASK]
522 + dp->dp_tempreserved[tx->tx_txg & TXG_MASK] / 2;
524 if (reserved && reserved > write_limit) {
525 DMU_TX_STAT_BUMP(dmu_tx_write_limit);
530 atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], space);
533 * If this transaction group is over 7/8ths capacity, delay
534 * the caller 1 clock tick. This will slow down the "fill"
535 * rate until the sync process can catch up with us.
537 if (reserved && reserved > (write_limit - (write_limit >> 3)))
538 txg_delay(dp, tx->tx_txg, 1);
544 dsl_pool_tempreserve_clear(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx)
546 ASSERT(dp->dp_tempreserved[tx->tx_txg & TXG_MASK] >= space);
547 atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], -space);
551 dsl_pool_memory_pressure(dsl_pool_t *dp)
553 uint64_t space_inuse = 0;
556 if (dp->dp_write_limit == zfs_write_limit_min)
559 for (i = 0; i < TXG_SIZE; i++) {
560 space_inuse += dp->dp_space_towrite[i];
561 space_inuse += dp->dp_tempreserved[i];
563 dp->dp_write_limit = MAX(zfs_write_limit_min,
564 MIN(dp->dp_write_limit, space_inuse / 4));
568 dsl_pool_willuse_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx)
571 mutex_enter(&dp->dp_lock);
572 dp->dp_space_towrite[tx->tx_txg & TXG_MASK] += space;
573 mutex_exit(&dp->dp_lock);
579 upgrade_clones_cb(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
582 dsl_dataset_t *ds, *prev = NULL;
584 dsl_pool_t *dp = spa_get_dsl(spa);
586 err = dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds);
590 while (ds->ds_phys->ds_prev_snap_obj != 0) {
591 err = dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj,
594 dsl_dataset_rele(ds, FTAG);
598 if (prev->ds_phys->ds_next_snap_obj != ds->ds_object)
600 dsl_dataset_rele(ds, FTAG);
606 prev = dp->dp_origin_snap;
609 * The $ORIGIN can't have any data, or the accounting
612 ASSERT(prev->ds_phys->ds_bp.blk_birth == 0);
614 /* The origin doesn't get attached to itself */
615 if (ds->ds_object == prev->ds_object) {
616 dsl_dataset_rele(ds, FTAG);
620 dmu_buf_will_dirty(ds->ds_dbuf, tx);
621 ds->ds_phys->ds_prev_snap_obj = prev->ds_object;
622 ds->ds_phys->ds_prev_snap_txg = prev->ds_phys->ds_creation_txg;
624 dmu_buf_will_dirty(ds->ds_dir->dd_dbuf, tx);
625 ds->ds_dir->dd_phys->dd_origin_obj = prev->ds_object;
627 dmu_buf_will_dirty(prev->ds_dbuf, tx);
628 prev->ds_phys->ds_num_children++;
630 if (ds->ds_phys->ds_next_snap_obj == 0) {
631 ASSERT(ds->ds_prev == NULL);
632 VERIFY(0 == dsl_dataset_hold_obj(dp,
633 ds->ds_phys->ds_prev_snap_obj, ds, &ds->ds_prev));
637 ASSERT(ds->ds_dir->dd_phys->dd_origin_obj == prev->ds_object);
638 ASSERT(ds->ds_phys->ds_prev_snap_obj == prev->ds_object);
640 if (prev->ds_phys->ds_next_clones_obj == 0) {
641 dmu_buf_will_dirty(prev->ds_dbuf, tx);
642 prev->ds_phys->ds_next_clones_obj =
643 zap_create(dp->dp_meta_objset,
644 DMU_OT_NEXT_CLONES, DMU_OT_NONE, 0, tx);
646 VERIFY(0 == zap_add_int(dp->dp_meta_objset,
647 prev->ds_phys->ds_next_clones_obj, ds->ds_object, tx));
649 dsl_dataset_rele(ds, FTAG);
650 if (prev != dp->dp_origin_snap)
651 dsl_dataset_rele(prev, FTAG);
656 dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx)
658 ASSERT(dmu_tx_is_syncing(tx));
659 ASSERT(dp->dp_origin_snap != NULL);
661 VERIFY3U(0, ==, dmu_objset_find_spa(dp->dp_spa, NULL, upgrade_clones_cb,
662 tx, DS_FIND_CHILDREN));
667 upgrade_dir_clones_cb(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
671 dsl_pool_t *dp = spa_get_dsl(spa);
672 objset_t *mos = dp->dp_meta_objset;
674 VERIFY3U(0, ==, dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
676 if (ds->ds_dir->dd_phys->dd_origin_obj) {
677 dsl_dataset_t *origin;
679 VERIFY3U(0, ==, dsl_dataset_hold_obj(dp,
680 ds->ds_dir->dd_phys->dd_origin_obj, FTAG, &origin));
682 if (origin->ds_dir->dd_phys->dd_clones == 0) {
683 dmu_buf_will_dirty(origin->ds_dir->dd_dbuf, tx);
684 origin->ds_dir->dd_phys->dd_clones = zap_create(mos,
685 DMU_OT_DSL_CLONES, DMU_OT_NONE, 0, tx);
688 VERIFY3U(0, ==, zap_add_int(dp->dp_meta_objset,
689 origin->ds_dir->dd_phys->dd_clones, dsobj, tx));
691 dsl_dataset_rele(origin, FTAG);
694 dsl_dataset_rele(ds, FTAG);
699 dsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx)
703 ASSERT(dmu_tx_is_syncing(tx));
705 (void) dsl_dir_create_sync(dp, dp->dp_root_dir, FREE_DIR_NAME, tx);
706 VERIFY(0 == dsl_pool_open_special_dir(dp,
707 FREE_DIR_NAME, &dp->dp_free_dir));
710 * We can't use bpobj_alloc(), because spa_version() still
711 * returns the old version, and we need a new-version bpobj with
712 * subobj support. So call dmu_object_alloc() directly.
714 obj = dmu_object_alloc(dp->dp_meta_objset, DMU_OT_BPOBJ,
715 SPA_MAXBLOCKSIZE, DMU_OT_BPOBJ_HDR, sizeof (bpobj_phys_t), tx);
716 VERIFY3U(0, ==, zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
717 DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx));
718 VERIFY3U(0, ==, bpobj_open(&dp->dp_free_bpobj,
719 dp->dp_meta_objset, obj));
721 VERIFY3U(0, ==, dmu_objset_find_spa(dp->dp_spa, NULL,
722 upgrade_dir_clones_cb, tx, DS_FIND_CHILDREN));
726 dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx)
731 ASSERT(dmu_tx_is_syncing(tx));
732 ASSERT(dp->dp_origin_snap == NULL);
734 /* create the origin dir, ds, & snap-ds */
735 rw_enter(&dp->dp_config_rwlock, RW_WRITER);
736 dsobj = dsl_dataset_create_sync(dp->dp_root_dir, ORIGIN_DIR_NAME,
738 VERIFY(0 == dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
739 dsl_dataset_snapshot_sync(ds, ORIGIN_DIR_NAME, tx);
740 VERIFY(0 == dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj,
741 dp, &dp->dp_origin_snap));
742 dsl_dataset_rele(ds, FTAG);
743 rw_exit(&dp->dp_config_rwlock);
747 dsl_pool_iput_taskq(dsl_pool_t *dp)
749 return (dp->dp_iput_taskq);
753 * Walk through the pool-wide zap object of temporary snapshot user holds
757 dsl_pool_clean_tmp_userrefs(dsl_pool_t *dp)
761 objset_t *mos = dp->dp_meta_objset;
762 uint64_t zapobj = dp->dp_tmp_userrefs_obj;
766 ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
768 for (zap_cursor_init(&zc, mos, zapobj);
769 zap_cursor_retrieve(&zc, &za) == 0;
770 zap_cursor_advance(&zc)) {
774 htag = strchr(za.za_name, '-');
777 dsobj = strtonum(za.za_name, NULL);
778 (void) dsl_dataset_user_release_tmp(dp, dsobj, htag, B_FALSE);
780 zap_cursor_fini(&zc);
784 * Create the pool-wide zap object for storing temporary snapshot holds.
787 dsl_pool_user_hold_create_obj(dsl_pool_t *dp, dmu_tx_t *tx)
789 objset_t *mos = dp->dp_meta_objset;
791 ASSERT(dp->dp_tmp_userrefs_obj == 0);
792 ASSERT(dmu_tx_is_syncing(tx));
794 dp->dp_tmp_userrefs_obj = zap_create(mos, DMU_OT_USERREFS,
797 VERIFY(zap_add(mos, DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_TMP_USERREFS,
798 sizeof (uint64_t), 1, &dp->dp_tmp_userrefs_obj, tx) == 0);
802 dsl_pool_user_hold_rele_impl(dsl_pool_t *dp, uint64_t dsobj,
803 const char *tag, uint64_t *now, dmu_tx_t *tx, boolean_t holding)
805 objset_t *mos = dp->dp_meta_objset;
806 uint64_t zapobj = dp->dp_tmp_userrefs_obj;
810 ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
811 ASSERT(dmu_tx_is_syncing(tx));
814 * If the pool was created prior to SPA_VERSION_USERREFS, the
815 * zap object for temporary holds might not exist yet.
819 dsl_pool_user_hold_create_obj(dp, tx);
820 zapobj = dp->dp_tmp_userrefs_obj;
826 name = kmem_asprintf("%llx-%s", (u_longlong_t)dsobj, tag);
828 error = zap_add(mos, zapobj, name, 8, 1, now, tx);
830 error = zap_remove(mos, zapobj, name, tx);
837 * Add a temporary hold for the given dataset object and tag.
840 dsl_pool_user_hold(dsl_pool_t *dp, uint64_t dsobj, const char *tag,
841 uint64_t *now, dmu_tx_t *tx)
843 return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, now, tx, B_TRUE));
847 * Release a temporary hold for the given dataset object and tag.
850 dsl_pool_user_release(dsl_pool_t *dp, uint64_t dsobj, const char *tag,
853 return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, NULL,
857 #if defined(_KERNEL) && defined(HAVE_SPL)
858 module_param(zfs_no_write_throttle, int, 0644);
859 MODULE_PARM_DESC(zfs_no_write_throttle, "Disable write throttling");
861 module_param(zfs_write_limit_shift, int, 0444);
862 MODULE_PARM_DESC(zfs_write_limit_shift, "log2(fraction of memory) per txg");
864 module_param(zfs_txg_synctime_ms, int, 0644);
865 MODULE_PARM_DESC(zfs_txg_synctime_ms, "Target milliseconds between txg sync");
867 module_param(zfs_write_limit_min, ulong, 0444);
868 MODULE_PARM_DESC(zfs_write_limit_min, "Min txg write limit");
870 module_param(zfs_write_limit_max, ulong, 0444);
871 MODULE_PARM_DESC(zfs_write_limit_max, "Max txg write limit");
873 module_param(zfs_write_limit_inflated, ulong, 0444);
874 MODULE_PARM_DESC(zfs_write_limit_inflated, "Inflated txg write limit");
876 module_param(zfs_write_limit_override, ulong, 0444);
877 MODULE_PARM_DESC(zfs_write_limit_override, "Override txg write limit");